jonkemp / gulp-qunit

Run QUnit unit tests in a headless PhantomJS instance.
MIT License
24 stars 19 forks source link

Tests fail but gulp returns 0 #41

Open drinckes opened 5 years ago

drinckes commented 5 years ago

I'm not sure if this is a gulp-qunit problem, a gulp problem, or I'm holding it wrong. :-)

My gulpfile is pretty standard:

var gulp = require('gulp');
var qunit = require('gulp-qunit');

gulp.task('test', () => {
  return gulp.src('./test.html').pipe(qunit());
});

I'm using gulp 4.0.1, gulp-qunit 2.0.2. If I run my tests, and the tests pass, then gulp returns 0. But if I edit my tests to force them to fail:

$ gulp test
...
[13:46:51] Took 75ms to run 203 tests. 202 passed, 1 failed.
[13:46:51] gulp-qunit: ✖ QUnit assertions failed in test.html

$ echo $?
0

gulp test still returns zero? How do I get gulp to return something else if the tests fail?

jonkemp commented 5 years ago

Try updating to the latest, 2.0.3 which was just published.

You can also listen to the gulp-qunit.finished event and check if it passed or failed there.

jonkemp commented 5 years ago

You can also try node-qunit-phantomjs with gulp.

https://github.com/jonkemp/node-qunit-phantomjs

drinckes commented 5 years ago

Thanks @jonkemp - I tried to listen to the gulp-qunit.finished event (using .on()?) but couldn't get it to work. I'm pretty sure I tried 2.0.3 but I ended up switching to phantomjs, and forcing it to throw an error on test failure:

var gulp = require('gulp');
var phantom = require('node-qunit-phantomjs');

function test(callback) {
  phantom('./test.html', {'verbose': true}, (result) => {
    // Called with 0 for successful test completion, 1 for failure(s).
    if (result === 0) {
      callback();
    } else {
      callback(new Error('tests failed'));
    }
  });
}

exports.test = test;
drinckes commented 5 years ago

Duh just noticed your comment about 2.0.3 just being released. As I don't possess a time machine I must have been using 2.0.2.