How to run and test AngularJS project in IntellijIDEA? - angularjs

I created AngularJS project in IntellijIDEA. And I didn't find any information how to run and test it with Karma framework. Also I installed NodeJS and plugins for AngularJS to Karma and Jasmine. How to correctly run it and test?
Here is my project structure. I use first Angular.

Right-click the karma.conf.js file, choose 'Create "karma.conf.js"' - this action will create Karma run configuration; then run the created configuration.
See also https://blog.jetbrains.com/webstorm/2017/02/your-first-unit-test-using-angular-cli-karma-and-webstorm/ - you might find this article helpful

Related

is it possible to run angularJS unit tests with angular-cli `ng test`?

I work on an AngularJS 1.6.X ES6 application.
I use Mocha and Sinon to write and run unit tests on it.
I started to hybrid/upgrade this application with ngUpgrade in order to write the new components in angular. So now, I got some angularJS modules and some angular modules.
I use #angular-builders/custom-webpack with babel-loader and ng-annotate-loader to properly load the AngularJS modules.
I want to run the existing unit tests of the AngularJS modules at the same time as the unit tests of the new angular modules.
Ideally, I would also like to have a common code coverage report for AngularJS and angular modules.
Is it possible to do it with angular-cli ng test?
Which Karma configuration do you recommend?
Is it possible to do it with angular-cli ng test?
Yes, I think so. If you are running Angular 6 or higher, but I have not tried this myself.
Angular CLI introduced something called "builders" which allows you to replace the core CLI commands with your own functionality.
https://medium.com/dailyjs/angular-cli-6-under-the-hood-builders-demystified-f0690ebcf01
Basically, you can define your own ng run <target> targets that work similuar to npm run <script>. These targets are defined in your angular.json file and are coded in a JavaScript file. You can then map the built in target ng test to a custom target to replace the built it one.
The above article gives an example for replacing ng test with a custom tester.

Eclipse: Installing Karma and Jasmine in Angular project

Is it possible to take advantage of the Nodeclipse addon in order to add Karma and Jasmine to an AngularJS project in Eclipse? I want to download the Karma and Jasmine modules inside of Eclipse, or at least I want to take advantage of the installed node.exe to download the modules to my project directory.

What is the use of node.js in protractor?

I'm very new to AngularJS. I am trying to automate an angularJS app.
installed node.js
installed protractor (npm install -g protractor)
updated webdriver manager tool (webdriver-manager update)
started the driver (webdriver-manager start)
I create a simple conf.js and spec.js files. Everything works fine and set to go.
when we execute spec.js, protractor talk to selenium webdriver which then launches the browser and does the other stuff like interacting with angularJS app. Am I correct?
So, what is the role of node.js here in protractor?
I might be wrong, if so please do correct me and explain how protractor works.
Thanks in advance :)
Node.js is an open source runtime environment to develop applications in JavaScript.
WebDriverJS has been written in Node.js and Protractor has been written on top of WebDriverJS.
Node.js will be executing the javascript code you've written in your spec and po files with its JavaScript Engine (Google V8), or as you've so colourfully described: "does the other stuff like interacting with angularJS app".
Read more here and here
Protractor is a Node.js application... hence the Node requirement. Protractor is written in Javascript, so it requires a Javascript engine, which Node provides (Google V8), thus allowing it to run on a server.
Node.js is package file we are using in protractor automation tool to run the angular.js based application.It contains selenium and other browser drivers to run our applications in different environments.

Is there an example of AngularJS app generated by Yeoman with e2e tests and $httpBackend?

Is there somewhere an example of AngularJS app generated by yo angular generator that has e2e tests with $httpBackend from ngMockE2E module? Preferably with single and continuous versions for CI and development.
It looks like using $httpBackend requires one to create a new app that depends on the original app module and ngMockE2E module and requires new index.html file that loads this new app.
If tests use a different app, does it mean that I should modify configuration to store files generated for tests somewhere else than files generated by grunt server command (.tmp), or will these files be exactly the same? I'd like to be able to have grunt server running for development while running e2e tests in the background with PhantomJS.
Has anyone created a task that automatically generates modified index-e2e.html file based on index.html? This way it would be always up to date and it could also be used with watch to automatically regenerate it whenever original index.html file changes.
You should notice that angular is depreacting e2e in favor of the protractor framework.. Also notice that e2e (and protractor also) is quite slow. so running continuously in the background like we do with unittesting isn't recommended. That said, for your question - No you don't need a different app, index file etc. (unless you need coverage data from e2e, in that case you'll need to instrument the js files, and that would require a different index.html, that can be created in grunt task with sed). what you do need is a different karma.conf.js file, a different grunt karma task ro reference it, including ng-scenario in the files section of the karma.conf. and running some kind of grunt testServer task that would run a test server, which isn't the same as the dev grunt server. You can run both with foreman or something similiar (as explained in this SO [question]. (How can I automate both E2E and unit tests with Yeoman & AngularJS?) and answer). If this is what you are looking for - you can find a karma.conf.js example for both e2e an unit in this PR. and again, don't invest heavily into the current e2e framework. better working the the new and shiny protractor

How can I run Jasmine tests with Karma (was Testacular) from Bamboo?

While building a single page app with AngularJS, I'm trying to integrate Jasmine tests in my build.
I did something similar before with the Maven Jasmine plugin, but I don't like to wrap my project in maven just to run the Jasmine tests. It seems cleaner to use Karma (was Testacular) for this somehow.
I'm comfortable that I'll get things running from a shell command, and my guess is that I can then run the command from Bamboo.
My questions:
Am I on the right track?
How can I best fail the build from a script, or does Bamboo recognize the Karma output automatically?
Great question. Make sure testacular.conf.js is configured to output junit xml for consumption by bamboo
junitReporter = {
// will be resolved to basePath (in the same way as files/exclude patterns)
outputFile: 'test-results.xml'
};
You can configure Testacular to run against many browsers and is pre-configured to use Chrome, we've chosen to start going headless with PhantomJS to do unit testing. Testacular already has jasmine inside.
For CI we are following the recommendation in
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = true;
If you use Ant a lot (and we do) sometimes you just want to stick with what you know... so you may want to checkout ANT, Windows and NodeJS Modules. to run node modules (ie testacular).
One note, if you are running testacular on windows, the npm install of testacular fails on hiredis module, which seems to be just *nix friendly. So, far it works fine without it.
It took us a couple of hours to prove all of this works. Hope this helps
--dan

Resources