How to make karma.js crash on test fail? - javascript

I am looking for a way to make karma.js crash when my tests fail so that my build process gets interrupted since that is easier to monitor in a remote building server.
I am using mocha as a reporter and jasmine as the test processor engine.
Is there any option or particular variable in the karma.conf.js file maybe that would allow me to "crash on test fail"

There is no need for a "crash on failure".
Your build process should check the exit code of the Karma process that it launches. If all test pass, the code will be 0. If there is a test failure, the code will be non-zero. (I've just checked and it was 1 when I tried.)

You may be able to get a plugin for karma for your build server that will report the results of your tests.
For example, there's a plugin for karma/teamcity (karma-teamcity-reporter) which allows you to fail the build step, preventing the application from publishing if you have it set up that way.

you can use grunt as automation tool to run your karma test case so that whenever any grunt job(test case) failed it will by default stop execution.

Related

Mocha test runner - option to rerun only failed tests from previous run

Is there an option in Javascript's Mocha test runner to only run tests which failed on the previous run? Is there an easy way to implement that if not? There are a lot of words written about retrying flaky tests but thats not what I want. I want to run tests, see failures, make updates to the code, then automatically run only the previous failed tests to see if my changes fixed them
Found this https://github.com/segmentio/mocha-broken but integration into WebStorm wasn't streamlined enough so dropped it...
Might fit your needs though, worth a try

Triggering Karma tests in the test runner

I am having a small issue with WebStorm that I am hoping someone has experienced and solved before.
I am using WebStorm to build a angular.js app and I have it set up to use Karma to run my tests. This is fine for the most part: I have a Karma configuration setup and I can get to to run the tests or debug them with no issue.
My problem is that when I try to run a test individually by clicking on one of the test in the "Test Run" tree it goes off to a node configuration, tries to run it and fails (because its looking for js dependencies). After that I just go back to my 'karma config' and it runs through the whole of the test no problem.
Does anyone know how I can get the IDE hooked up so that I can trigger my tests from the UI?
Running tests from file right-click menu is only supported for those runners that allow executing individual tests (JSTestDriver, for example). There is currently no such possibility for Karma (WEB-13173). See the discussion at https://github.com/karma-runner/karma/issues/1235.
to run individual test files, you can have several karma configuration files with different sets of tests included. Plus you can rename individual tests/suits in the way mentioned in https://github.com/karma-runner/karma/issues/553

How to use protractor test to determine whether or not to publish my application?

I need to automate the publishing process of my AngularJS application.
But I want to publish the application only when the protractor tests passes.
Is there any way to get a boolean output from the test?
Or maybe using a task runner like gulp can do this trick for me?
What we were doing was letting the task runner fail with a non-zero exit code which would mean our tests failed or there was an error during the test run.
In our case this was grunt-protractor-runner with keepAlive set to false. And, if grunt sees a non-zero error code returned by one of the tasks, it stops the execution and fails the whole macro-task itself, by default (without --force).
There are definitely other options:
dump the test results into a junit XML (personally used JUnitXmlReporter from jasmine-reporters) and let your CI tool (say, Jenkins) parse the results and understand whether to continue or not
set the resultJsonOutputFile setting in your protractor config and parse it after a test run
To summarize - you should solve it on higher level, let your task runner, grunt or gulp, or a continuous integration tool, Jenkins, Bamboo or other, handle it.

Integration of Karma test cases in Jenkins which is configured to run ansible script

We are stuck with a scenario where we deploy code(written in nodejs) to remote instance through ansible scripts. We now have to integrate this code in jenkins server.
Till now we ran the pure ansible script in EXECUTE SHELL section of job configuration.
But now ,we need to run a series of karma test cases and upon success execute this ansible script. We have tried running karma test cases inside ansible script but that means giving control to ansible and missing reporting feature which jenkins does.
What we need is a test runner plugin of jenkins that would run test cases and upon success run this ansible script and upon failure do appropriate reporting.
Any working example would be highly helpful.
And why doesn't the good old Conditional step work for you?
Add build step -> Conditional (Single)

What is the correct way to test javascript with unit AND integrations tests, using Visual Studio and Team City?

I have got javascript tests running in visual studio using Resharper and Jasmine. It all works fine. Now however I want to run an integration test. After looking into this I just can't work out whether I should be using Karma or PhantomJs or both? And whether they link to resharper?
I then have to run all my tests on the continuous integration server using Team City. Doesn't seem like there is a clear logical way to architect front end testing from dev right through to the CI server.
For example do I really need to use Karma locally and on the CI server? I don't want to because it is not baked into visual studio and I will have to keep opening the command line and running my tests manually. This will annoy other developers and they won't bother running them I imagine. Help!
We are using Team City by the way....
Neither of these test runners are connected to Resharper in any form. I don't think there is a one and only "correct" way of running Jasmine tests in TeamCity currently - for all approaches I am aware of there is a bit of assembly required.
Personally I am using a combination of PhantomJS and the Jasmine TeamCity Reporter which works like this:
Get a list of unique test URLs from server - each of these test suites will use the Jasmine TeamCity Reporter to log results
for each test URL dynamically generate a test JS file to be used for phantom and write it to disk
use PhantomJS to run the JS file which now will load the test suite page and its test result will be written to console where they are picked up by TeamCity.

Categories

Resources