Skip to content

Commit

Permalink
Adding test for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham9411 committed Oct 28, 2023
1 parent 2b31649 commit 33c8731
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
15 changes: 15 additions & 0 deletions test/fixtures/test-runner/timeout.js
Original file line number Diff line number Diff line change
@@ -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);
});
26 changes: 23 additions & 3 deletions test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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(), '');
Expand Down

0 comments on commit 33c8731

Please sign in to comment.