Is it necessary to have a runner.html to run an e2e test? - angularjs

Is it necessary to have a runner.html to run an e2e test?
Related to Selector [ng\:model="query"] did not match any elements
I am trying to get my e2e test running, but it keeps on failing.
The errors make it look like the test "engine" can't find any elements to assert against (see linked question).
I'm assuming that by having my karma config set up correctly, it will scan the included files specified by the karma config and run the test.
I'm assuming this because the karma runner does in fact detect the test, but the test itself fails.
Please see the linked question for the relevant code examples.

The runner is just a convenient way to do testing.
Karma will run headless (without a browser).

Related

AngularJS -Karma testing Jasmine- describe is not defined

Just trying to start Angular Testing with Karma. I did install and create my karma.config. On CMD when I start my karma, it runs without any problems and opens both of my browsers (Chrome Canary and Firefox)
However it doesn't show Tests on browser. And I don't get any error from karma or anything written on my console.
My File structure and file part of karma.conf.js:
And in my .spec.js file when I write a basic test just to see if it is running properly, in WebStorm it gets underlined. Here is a screenshot for this:
None of the other similar topics on StackOverflow helped me. I am stuck with this error.
What can be the reason for that?
It looks and sounds like WebStorm is trying to run your tests in a Node.js environment as opposed to a Karma environment.
Try making a Karma run configuration for your karma.conf.js file.
More details about making a run configuration can be found here: https://www.jetbrains.com/help/webstorm/2016.3/running-unit-tests-on-karma.html#runConfigurationKarma

How to run a single test file with Karma/Jasmine?

I'm using Karma and Jasmine for testing my Angular JS code. I managed to run all the tests in my project using Karma, but if I try to run just a single file I'm getting the following error: ReferenceError: describe is not defined. Is it possible to run just a single test file and if yes then how?
P.S. I'm using Intellij IDEA.
Although it's not ideal, you can replace describe (and it) with fdescribe (and fit) so only those tests will be executed
On the other hand, xdescribe / xit excludes the tests from your suite
If you use Gulp, you can combine gulp-karma & yargs to pass in a pattern as argument.
source: https://stackoverflow.com/a/27696472/1782659
If you are like me and you've inherited a suite of tests that are controlled by a task runner (e.g. gulp) and you are getting failures but are unsure which file is actually failing you can sanity check an individual file by running jasmine directly against it:
1.) Make sure you have jasmine installed (it may not be if wrapped inside your task runner configuration)
npm install jasmine
2.) Run jasmine against file:
./node_modules/.bin/jasmine /path/to/my/spec/file.js
or
./node_modules/jasmine/bin/jasmine.js /path/to/my/spec/file.js

Grunt+karma+angular - debugging unit tests

I have set up an angular application using Yeoman generator. It works fine, builds fine and unit tests work. I have also added Protractor for e2e tests.
I've set up Webstorm to run the unit tests as a Node.js run configuration, which executes grunt-cli\bin\grunt with the test build task. It runs fine from the IDE.
However when I'm trying to debug, the execution never stops on breakpoints.
The console output is of little help. The tests simply succeed/fail as expected and that's it.
What could be wrong?
it doesn't seem to be possible to debug protractor tests in webstorm right now. Please vote for protractor support: WEB-9236

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