Skip to content

Commit

Permalink
Tests: Add case for errors while console is mocked
Browse files Browse the repository at this point in the history
The asserted output is not what we'd like it to be.
This is just to documnet what happens today.

Ref #1340.
  • Loading branch information
Krinkle committed Dec 24, 2018
1 parent b54e732 commit 95645f7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/cli/fixtures/expected/tap-outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ not ok 1 global failure
# skip 0
# todo 0
# fail 1
`,

"qunit 'fail/mocked-console.js'":
`TAP version 13
ok 2 Uncaught error > good
1..2
# pass 1
# skip 0
# todo 0
# fail 1
`,

"qunit test single.js 'glob/**/*-test.js'":
Expand Down
24 changes: 24 additions & 0 deletions test/cli/fixtures/fail/mocked-console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
QUnit.module( "Error with mocked console", function( hooks ) {
var orgLog, orgError;

// Stub
hooks.before( function() {
orgLog = console.log;
orgError = console.error;
console.log = console.error = function() {};
} );

// Restore
hooks.after( function() {
console.error = orgError;
console.log = orgLog;
} );

QUnit.test( "bad", function( assert ) {
assert.ok( this.aint() );
} );

QUnit.test( "good", function( assert ) {
assert.ok( 1 );
} );
} );
14 changes: 14 additions & 0 deletions test/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ QUnit.module( "CLI Main", function() {
}
} ) );

// Test case for https://github.com/qunitjs/qunit/issues/1333
QUnit.test( "report assert.throws() failures properly", co.wrap( function* ( assert ) {
const command = "qunit fail/throws-match.js";
try {
Expand All @@ -91,6 +92,19 @@ QUnit.module( "CLI Main", function() {
}
} ) );

// Test case for https://github.com/qunitjs/qunit/issues/1340
QUnit.test( "report errors with mocked console", co.wrap( function* ( assert ) {
const command = "qunit fail/mocked-console.js";
try {
yield execute( command );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "" );
const re = new RegExp( expectedOutput[ command ] );
assert.equal( re.test( e.stdout ), true );
}
} ) );

QUnit.test( "exit code is 1 when failing tests are present", co.wrap( function* ( assert ) {
try {
yield execute( "qunit fail/failure.js" );
Expand Down

0 comments on commit 95645f7

Please sign in to comment.