Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Add case for errors while console is mocked #1343

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.log = orgLog;
console.error = orgError;
} );

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