Angular: How to debug Karma unit tests when Babel transpiling is used? - angularjs

I use JetBrains Webstorm for a while now and it really shines when debugging Karma unit tests for e.g. Angular webapps.
But I am stuck at trying to debug unit tests when the sources are transpiled via Babel. I decided to run the tests on the transpiled sources instead of the original ES6 compatible ones just to be sure that everything works which works in Babel, which is more than e.g. Chrome can handle.
But how can I set breakpoints in the ES6 files which actually fire when Karma hits them on the transpiled version? Does Karma honor source maps? I could not get it to work. Has someone tried on this task and give me some hints how to configure the whole thing?
Summary:
working: run Karma unit tests on transpiled source files
not workin: breakpoints/debugging unit tests

Related

Running Angular JS UnitTests with Karma and Chutzpah

Can I run my AngularJS Unit Tests with Karma and Chutzpah? Is that possible?
I am coding my Unit TestCases in Visual Studio and have already installed Chutzpah so whether I can install Karma also?
I need Karma as I need to include some template urls
Yes, you can use both but you would need to setup both a Karma config and a chutzpah.json config.

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 it necessary to have a runner.html to run an e2e test?

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).

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