From ab087ef1cb6602da87ed0dc2a4ea396478d97b46 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 8 Feb 2024 22:43:21 +0000 Subject: [PATCH] Core: Fix hanging `assert.async()` after `assert.timeout()` Follows-up 163c9bcf60 (https://github.com/qunitjs/qunit/pull/1642), which changed an internalRecover() to internalStart(), whereas internalStart will (correctly) not resume if there are other pauses still remaining. Change this back to internalRecover(). Fixes https://github.com/qunitjs/qunit/issues/1705. --- src/test.js | 2 +- test/cli/cli-main.js | 1 + test/cli/fixtures/expected/tap-outputs.js | 19 +++++++++++++++++++ .../fixtures/pending-async-after-timeout.js | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/cli/fixtures/pending-async-after-timeout.js diff --git a/src/test.js b/src/test.js index cc494e359..5f8ebc105 100644 --- a/src/test.js +++ b/src/test.js @@ -752,7 +752,7 @@ Test.prototype = { `Test took longer than ${timeout}ms; test timed out.`, sourceFromStacktrace(2) ); - internalStart(test); + internalRecover(test); }; }; clearTimeout(config.timeout); diff --git a/test/cli/cli-main.js b/test/cli/cli-main.js index aeb2f37ae..030d3020f 100644 --- a/test/cli/cli-main.js +++ b/test/cli/cli-main.js @@ -25,6 +25,7 @@ const fixtureCases = { 'test with failing assertion': ['qunit', 'fail/failure.js'], 'test that hangs': ['qunit', 'hanging-test'], + 'test with pending async after timeout': ['qunit', 'pending-async-after-timeout.js'], 'two tests with one timeout': ['qunit', 'timeout'], 'test with zero assertions': ['qunit', 'zero-assertions.js'], diff --git a/test/cli/fixtures/expected/tap-outputs.js b/test/cli/fixtures/expected/tap-outputs.js index 1abcd4b72..aca86598b 100644 --- a/test/cli/fixtures/expected/tap-outputs.js +++ b/test/cli/fixtures/expected/tap-outputs.js @@ -191,6 +191,25 @@ Extra reporters found among package dependencies: npm-reporter Error: Process exited before tests finished running Last test to run (hanging) has an async hold. Ensure all assert.async() callbacks are invoked and Promises resolve. You should also set a standard timeout via QUnit.config.testTimeout. +# exit code: 1`, + + 'qunit pending-async-after-timeout.js': +`TAP version 13 +not ok 1 example + --- + message: Test took longer than 10ms; test timed out. + severity: failed + actual : null + expected: undefined + stack: | + at internal + ... +1..1 +# pass 0 +# skip 0 +# todo 0 +# fail 1 + # exit code: 1`, 'qunit unhandled-rejection.js': diff --git a/test/cli/fixtures/pending-async-after-timeout.js b/test/cli/fixtures/pending-async-after-timeout.js new file mode 100644 index 000000000..ed180dfcf --- /dev/null +++ b/test/cli/fixtures/pending-async-after-timeout.js @@ -0,0 +1,6 @@ +// Regression test for https://github.com/qunitjs/qunit/issues/1705 +QUnit.test( "example", async assert => { + assert.timeout( 10 ); + const done = assert.async(); + assert.true( true ); +} );