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

Produce clearer, contextual failures when assert.async callbacks are called incorrectly #1595

Closed
wants to merge 18 commits 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
2 changes: 0 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ module.exports = function( grunt ) {
"test/reporter-urlparams-hidepassed.html",
"test/moduleId.html",
"test/onerror/inside-test.html",
"test/onerror/outside-test.html",
"test/seed.html",
"test/overload.html",
"test/preconfigured.html",
Expand Down Expand Up @@ -130,7 +129,6 @@ module.exports = function( grunt ) {
"test/events.js",
"test/events-in-test.js",
"test/onerror/inside-test.js",
"test/onerror/outside-test.js",
"test/setTimeout.js",
"test/main/dump.js",
"test/node/storage-1.js",
Expand Down
11 changes: 1 addition & 10 deletions src/core/onerror.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { pushFailure, test } from "../test";
import { pushFailure } from "../test";

import config from "./config";
import { extend } from "./utilities";

// Handle an unhandled exception. By convention, returns true if further
// error handling should be suppressed and false otherwise.
Expand All @@ -17,14 +16,6 @@ export default function onError( error, ...args ) {
error.stacktrace || error.fileName + ":" + error.lineNumber,
...args
);
} else {
test( "global failure", extend( function() {
pushFailure(
error.message,
error.stacktrace || error.fileName + ":" + error.lineNumber,
...args
);
}, { validTest: true } ) );
Comment on lines -20 to -27
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to self-flag this, after some more thorough bashing. Here's my counter-example:

QUnit.module( "foo", function() {
    QUnit.test('hello', assert => {
        assert.ok(1);
    });
    throw new Error("oops");
} );

In the current release, that shows a console error with Uncaught Error: oops, but it also shows a "global failure" as script error. In this PR, you see the console error, but otherwise a passing test in the report. That is a no-go, and I will re-work this.

}

return false;
Expand Down
6 changes: 6 additions & 0 deletions test/cli/fixtures/delayed-done.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
QUnit.test( "times out before scheduled done is called", assert => {
assert.timeout( 10 );
const done = assert.async();
assert.true( true );
setTimeout( done, 20 );
} );
49 changes: 49 additions & 0 deletions test/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,55 @@ QUnit.module( "CLI Main", () => {

} );

QUnit.module( "assert.async", () => {

QUnit.test( "assert.async callback after tests timeout", async assert => {
const command = "qunit delayed-done.js";
try {
await execute( command );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "" );
assert.equal( e.stdout, expectedOutput[ command ] );
}
} );

QUnit.test( "drooling calls across tests to assert.async callback", async assert => {
const command = "qunit drooling-done.js";
try {
await execute( command );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "" );

// code coverage and various Node versions can alter the stacks,
// so we can't compare exact strings, but we can spot-check
assert.true( e.stdout.includes(
"not ok 2 Test B\n" +
" ---\n" +
" message: \"`assert.async` callback from test 'Test A' was called during this test.\"" ), e.stdout );
}
} );

QUnit.test( "too many calls to assert.async callback", async assert => {
const command = "qunit too-many-done-calls.js";
try {
await execute( command );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "" );

// code coverage and various Node versions can alter the stacks,
// so we can't compare exact strings, but we can spot-check
assert.true( e.stdout.includes(
"not ok 1 Test A\n" +
" ---\n" +
" message: Too many calls to the `assert.async` callback" ), e.stdout );
}
} );

} );

QUnit.module( "only", () => {
QUnit.test( "test", async assert => {

Expand Down
1 change: 0 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<script src="reporter-html/diff.js"></script>
<script src="reporter-html/unhandled-rejection.js"></script>
<script src="onerror/inside-test.js"></script>
<script src="onerror/outside-test.js"></script>
</head>
<body>
<div id="qunit"></div>
Expand Down
13 changes: 0 additions & 13 deletions test/onerror/outside-test.html

This file was deleted.

39 changes: 0 additions & 39 deletions test/onerror/outside-test.js

This file was deleted.