From 9d9618d4feced113b32c91f9e7000494119482f3 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 10 Feb 2024 12:48:00 +0000 Subject: [PATCH] Test: add fixture for rejected "begin", "moduleStart", "done" callbacks 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 https://github.com/qunitjs/qunit/pull/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 https://github.com/qunitjs/qunit/pull/1391. --- test/cli/cli-main.js | 1 + test/cli/fixtures/callbacks-rejected.js | 37 +++++++++++++++++++++++ test/cli/fixtures/expected/tap-outputs.js | 19 ++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 test/cli/fixtures/callbacks-rejected.js diff --git a/test/cli/cli-main.js b/test/cli/cli-main.js index 030d3020f..be4079322 100644 --- a/test/cli/cli-main.js +++ b/test/cli/cli-main.js @@ -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'], diff --git a/test/cli/fixtures/callbacks-rejected.js b/test/cli/fixtures/callbacks-rejected.js new file mode 100644 index 000000000..821ebe5d8 --- /dev/null +++ b/test/cli/fixtures/callbacks-rejected.js @@ -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); + }); +}); diff --git a/test/cli/fixtures/expected/tap-outputs.js b/test/cli/fixtures/expected/tap-outputs.js index aca86598b..95fccd98f 100644 --- a/test/cli/fixtures/expected/tap-outputs.js +++ b/test/cli/fixtures/expected/tap-outputs.js @@ -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':