Skip to content

Commit

Permalink
Test: add fixture for rejected "begin", "moduleStart", "done" callbacks
Browse files Browse the repository at this point in the history
I'm adding this as a CLI fixture instead of an HTML fixture because
we don't currently have a good way of expecting a failure in an HTML
test run. I've confirmed that the "hanging" appearance described in
#1391 is equivalent to the
"Process exited before tests finished running" message reported.

Once we switch to capturing TAP by default, this will make the HTML
tests much easier to verify no matter whether the pass/fail outcome.

Ref #1391.
  • Loading branch information
Krinkle committed Feb 10, 2024
1 parent e614a2f commit 9d9618d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/cli/cli-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const fixtureCases = {
'uncaught error in "moduleDone" callback"': ['qunit', 'bad-callbacks/moduleDone-throw.js'],
// FIXME: Details of testStart() error are swallowed
'uncaught error in "testStart" callback"': ['qunit', 'bad-callbacks/testStart-throw.js'],
'rejection from callbacks': ['qunit', 'callbacks-rejected.js'],

'QUnit.hooks context': ['qunit', 'hooks-global-context.js'],

Expand Down
37 changes: 37 additions & 0 deletions test/cli/fixtures/callbacks-rejected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var caught = [];

QUnit.on('error', function (e) {
caught.push(e.message);
});

QUnit.begin(function () {
return Promise.reject(new Error('begin'));
});

QUnit.moduleStart(function () {
return Promise.reject(new Error('moduleStart'));
});

QUnit.testStart(function () {
return Promise.reject(new Error('testStart'));
});

QUnit.done(function () {
setTimeout(function () {
console.log('Caught errors from ' + caught.join(', '));
}, 100);
});

QUnit.done(function () {
return Promise.reject(new Error('done'));
});

QUnit.test('one', function (assert) {
assert.ok(true);
});

QUnit.module('example', function () {
QUnit.test('two', function (assert) {
assert.ok(true);
});
});
19 changes: 19 additions & 0 deletions test/cli/fixtures/expected/tap-outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,25 @@ Error: Process exited before tests finished running
# stderr
Error: Process exited before tests finished running
# exit code: 1`,

'qunit callbacks-rejected.js':
`TAP version 13
not ok 1 global failure
---
message: Error: begin
severity: failed
stack: |
Error: begin
at /qunit/test/cli/fixtures/callbacks-rejected.js:8:25
at qunit.js
at internal
...
Bail out! Error: begin
# stderr
Error: Process exited before tests finished running
# exit code: 1`,

'qunit no-tests':
Expand Down

0 comments on commit 9d9618d

Please sign in to comment.