Karma will not work if tests have errors

When a test cannot be started by karma due to an error (for example, a syntax error), Karma complains of a warning:

INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/ INFO [launcher]: Starting browser PhantomJS INFO [PhantomJS 1.9.8 (Linux)]: Connected on socket WT-AsaXZq4odkQe2DgZJ with id 10861626 WARN [web-server]: 404: /undefinedhttp%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Funit%2Fjs%2Fspecs%2Fcore%2FDeviceSpec.js%3F1e346ab1ad6e6e9240be6a6d5effaaa8f0dd96d8/9/%22ReferenceError%3A%20Can't%20find%20variable%3A%20SYNTAXERROR%22 

The last line is unescaped: "/undefinedhttp://localhost:9876/base/tests/unit/js/specs/core/DeviceSpec.js?1e346ab1ad6e6e9240be6a6d5effaaa8f0dd96d8/9/" ReferenceError: cannot find variableERNORTA "ORNTA"

Which is correct, since I inserted SYNTAXERROR somewhere in my test for this question.

So, the test is ignored, but since other tests are in order, Karma returns those tests that passed:

  PhantomJS 1.9.8 (Linux): Executed 41 of 41 SUCCESS (0.354 secs / 0.016 secs) ➜ echo $? 0 

I want Karma to fail if it cannot complete all the tests (I don’t think for any reason not!).

I did not find any configuration variable to act this way.

I found a line where Karma prints the warning above, but I don’t understand why it is treated like 404 ...

Any idea to make karma fail when it cannot complete all the tests?

+6
source share
1 answer

Im using a script that fails if WARN displayed by karma:

 #!/bin/bash set -eo pipefail mkdir -p tests/unit/js/dist || true ./node_modules/.bin/karma start tests/unit/js/karma.conf.js --port 9875 | tee tests/unit/js/dist/results.txt if grep 'WARN' tests/unit/js/dist/results.txt; then exit 1 else exit 0 fi 
0
source

Source: https://habr.com/ru/post/986762/


All Articles