Showing with 53 additions and 0 deletions.
  1. +24 −0 bin/run.js
  2. +6 −0 test/cli/fixtures/expected/tap-outputs.js
  3. +3 −0 test/cli/fixtures/hanging-test/index.js
  4. +1 −0 test/cli/fixtures/no-tests/index.js
  5. +19 −0 test/cli/main.js
@@ -12,6 +12,25 @@ const IGNORED_GLOBS = [
let QUnit;

function run( args, options ) {
let running = true;

// Default to non-zero exit code to avoid false positives
process.exitCode = 1;

process.on( "exit", function() {
if ( running ) {
console.error( "Error: Process exited before tests finished running" );

const currentTest = QUnit.config.current;
if ( currentTest && currentTest.semaphore ) {
const name = currentTest.testName;
console.error( "Last test to run (" + name + ") has an async hold. " +
"Ensure all assert.async() callbacks are invoked and Promises resolve. " +
"You should also set a standard timeout via QUnit.config.testTimeout." );
}
}
} );

const files = utils.getFilesFromArgs( args );

QUnit = requireQUnit();
@@ -46,8 +65,13 @@ function run( args, options ) {
QUnit.start();

QUnit.on( "runEnd", function setExitCode( data ) {
running = false;

if ( data.testCounts.failed ) {
process.exitCode = 1;
} else if ( data.testCounts.total === 0 ) {
console.error( "Error: No tests were run" );
process.exitCode = 1;
} else {
process.exitCode = 0;
}
@@ -80,5 +80,11 @@ ok 5 A-Test > derp
"qunit --reporter does-not-exist": `No reporter found matching "does-not-exist".
Available reporters from JS Reporters are: console, tap
Available custom reporters from dependencies are: npm-reporter
`,

/* eslint-disable max-len */
"qunit hanging-test": `Error: Process exited before tests finished running
Last test to run (hanging) has an async hold. Ensure all assert.async() callbacks are invoked and Promises resolve. You should also set a standard timeout via QUnit.config.testTimeout.
`
/* eslint-enable max-len */
};
@@ -0,0 +1,3 @@
QUnit.test( "hanging", function( assert ) {
assert.async();
} );
@@ -0,0 +1 @@
// This test file has no tests!
@@ -76,6 +76,25 @@ QUnit.module( "CLI Main", function() {
}
} ) );

QUnit.test( "exit code is 1 when no tests are run", co.wrap( function* ( assert ) {
try {
yield execute( "qunit no-tests" );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "Error: No tests were run\n" );
}
} ) );

QUnit.test( "exit code is 1 when no tests exit before done", co.wrap( function* ( assert ) {
const command = "qunit hanging-test";
try {
yield execute( command );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, expectedOutput[ command ] );
}
} ) );

QUnit.module( "filter", function() {
QUnit.test( "can properly filter tests", co.wrap( function* ( assert ) {
const command = "qunit --filter 'single' test single.js 'glob/**/*-test.js'";