Skip to content

Commit

Permalink
fixup! Tests: Add CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Trent Willis committed Mar 19, 2017
1 parent d7eded5 commit 84b2451
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 16 deletions.
65 changes: 65 additions & 0 deletions test/cli/fixtures/expected/tap-outputs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Expected outputs from the TapReporter for the commands run in CLI tests
module.exports = {
"qunit":
`TAP version 13
ok 1 First > 1
ok 2 Second > 1
1..2
# pass 2
# skip 0
# todo 0
# fail 0`,

"qunit 'glob/**/*-test.js'":
`TAP version 13
ok 1 A-Test > derp
ok 2 Nested-Test > herp
1..2
# pass 2
# skip 0
# todo 0
# fail 0`,

"qunit single.js":
`TAP version 13
ok 1 Single > has a test
1..1
# pass 1
# skip 0
# todo 0
# fail 0`,

"qunit single.js double.js":
`TAP version 13
ok 1 Double > has a test
ok 2 Double > has another test
ok 3 Single > has a test
1..3
# pass 3
# skip 0
# todo 0
# fail 0`,

"qunit test":
`TAP version 13
ok 1 First > 1
ok 2 Second > 1
1..2
# pass 2
# skip 0
# todo 0
# fail 0`,

"qunit test single.js 'glob/**/*-test.js'":
`TAP version 13
ok 1 A-Test > derp
ok 2 Nested-Test > herp
ok 3 Single > has a test
ok 4 First > 1
ok 5 Second > 1
1..5
# pass 5
# skip 0
# todo 0
# fail 0`
};
4 changes: 4 additions & 0 deletions test/cli/fixtures/fail/failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ QUnit.module( "Failure", function() {
QUnit.test( "bad", function( assert ) {
assert.ok( false );
} );

QUnit.test( "bad again", function( assert ) {
assert.ok( false );
} );
} );
File renamed without changes.
39 changes: 23 additions & 16 deletions test/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const path = require( "path" );
const exec = require( "execa" ).shell;
const co = require( "co" );

const expectedOutput = require( "./fixtures/expected/tap-outputs" );

// Executes the provided command from within the fixtures directory
function execute( command ) {
const cwd = process.cwd();
process.chdir( path.join( __dirname, "fixtures" ) );
Expand All @@ -15,13 +18,14 @@ function execute( command ) {
return execution;
}

QUnit.module( "cli", function() {
QUnit.module( "CLI Main", function() {
QUnit.test( "defaults to running tests in 'test' directory", co.wrap( function* ( assert ) {
const execution = yield execute( "qunit" );
const command = "qunit";
const execution = yield execute( command );

assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, "TAP version 13\nok 1 1\nok 2 1\n1..2" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );

QUnit.test( "errors if no test files are found to run", co.wrap( function* ( assert ) {
Expand All @@ -33,52 +37,55 @@ QUnit.module( "cli", function() {
} ) );

QUnit.test( "accepts globs for test files to run", co.wrap( function* ( assert ) {
const execution = yield execute( "qunit 'glob/**/*-test.js'" );
const command = "qunit 'glob/**/*-test.js'";
const execution = yield execute( command );

assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, "TAP version 13\nok 1 derp\nok 2 herp\n1..2" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );

QUnit.test( "runs a single JS file", co.wrap( function* ( assert ) {
const execution = yield execute( "qunit single.js" );
const command = "qunit single.js";
const execution = yield execute( command );

assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, "TAP version 13\nok 1 has a test\n1..1" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );

QUnit.test( "runs multiple JS files", co.wrap( function* ( assert ) {
const execution = yield execute( "qunit single.js double.js" );
const command = "qunit single.js double.js";
const execution = yield execute( command );

assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, "TAP version 13\nok 1 has a test\n" +
"ok 2 has another test\nok 3 has a test\n1..3" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );

QUnit.test( "runs all JS files in a directory matching an arg", co.wrap( function* ( assert ) {
const execution = yield execute( "qunit test" );
const command = "qunit test";
const execution = yield execute( command );

assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, "TAP version 13\nok 1 1\nok 2 1\n1..2" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );

QUnit.test( "runs multiple types of file paths", co.wrap( function* ( assert ) {
const execution = yield execute( "qunit test single.js 'glob/**/*-test.js'" );
const command = "qunit test single.js 'glob/**/*-test.js'";
const execution = yield execute( command );

assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, "TAP version 13\nok 1 derp\nok 2 herp\n" +
"ok 3 has a test\nok 4 1\nok 5 1\n1..5" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );

QUnit.test( "exit code is equal to number of failed tests", co.wrap( function* ( assert ) {
try {
yield execute( "qunit fail/*.js" );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.code, 2 );
}
} ) );
} );

0 comments on commit 84b2451

Please sign in to comment.