From 33c87319cf6c8e86910ba56b0d6bbe4b46b8d562 Mon Sep 17 00:00:00 2001 From: Shubham Pandey Date: Sat, 28 Oct 2023 18:24:25 +0530 Subject: [PATCH] Adding test for timeout --- test/fixtures/test-runner/timeout.js | 15 +++++++++++++++ test/parallel/test-runner-cli.js | 26 +++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/test-runner/timeout.js diff --git a/test/fixtures/test-runner/timeout.js b/test/fixtures/test-runner/timeout.js new file mode 100644 index 00000000000000..7b758041f1cae9 --- /dev/null +++ b/test/fixtures/test-runner/timeout.js @@ -0,0 +1,15 @@ +'use strict'; +const test = require('node:test'); +const common = require('../../common'); +const fixtures = require('../../common/fixtures'); + +test('should support timeout', async () => { + const stream = test.run({files: [ + fixtures.path('test-runner', 'never_ending_sync.js'), + fixtures.path('test-runner', 'never_ending_async.js'), + ] }); + stream.on('test:fail', common.mustCall(2)); + stream.on('test:pass', common.mustNotCall()); + // eslint-disable-next-line no-unused-vars + for await (const _ of stream); +}); \ No newline at end of file diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 34ce67caa5e6a5..2163cc3d3e37ab 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -115,6 +115,26 @@ const testFixtures = fixtures.path('test-runner'); }); } +{ + const args = [ + '--test', + '--test-timeout', + 50, + 'test/fixtures/test-runner/timeout.js' + ]; + const child = spawnSync(process.execPath, args); + + assert.strictEqual(child.status, 1); + assert.strictEqual(child.signal, null); + assert.strictEqual(child.stderr.toString(), ''); + const stdout = child.stdout.toString(); + assert.match(stdout, /not ok 1 - test/); + assert.match(stdout, / {2}---/); + assert.match(stdout, / {2}duration_ms: .*/); + assert.match(stdout, /failureType: 'testTimeoutFailure/); + assert.match(stdout, /error: 'test timed out after 50ms'/); +} + { // Test combined stream outputs const args = [ @@ -195,9 +215,9 @@ const testFixtures = fixtures.path('test-runner'); // Use test with --loader and --require. // This case is common since vscode uses --require to load the debugger. const args = ['--no-warnings', - '--experimental-loader', 'data:text/javascript,', - '--require', fixtures.path('empty.js'), - '--test', join(testFixtures, 'default-behavior', 'index.test.js')]; + '--experimental-loader', 'data:text/javascript,', + '--require', fixtures.path('empty.js'), + '--test', join(testFixtures, 'default-behavior', 'index.test.js')]; const child = spawnSync(process.execPath, args); assert.strictEqual(child.stderr.toString(), '');