Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: allow nesting test within describe #46544

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ function getGlobalRoot() {
}

function test(name, options, fn) {
const subtest = getGlobalRoot().createSubtest(Test, name, options, fn);
const parent = testResources.get(executionAsyncId()) || getGlobalRoot();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can't we use ?? here?

const subtest = parent.createSubtest(Test, name, options, fn);
return subtest.start();
}

Expand Down
17 changes: 10 additions & 7 deletions test/message/test_runner_describe_it.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';
require('../common');
const assert = require('node:assert');
const { describe, it } = require('node:test');
const { describe, it, test } = require('node:test');
const util = require('util');


Expand Down Expand Up @@ -41,6 +41,8 @@ it('async pass', async () => {

});

test('mixing describe/it and test should work', () => {});

it('async throw fail', async () => {
throw new Error('thrown from async throw fail');
});
Expand Down Expand Up @@ -95,6 +97,7 @@ describe('subtest sync throw fail', () => {
it('+sync throw fail', () => {
throw new Error('thrown from subtest sync throw fail');
});
test('mixing describe/it and test should work', () => {});
});

it('sync throw non-error fail', async () => {
Expand All @@ -106,7 +109,7 @@ describe('level 0a', { concurrency: 4 }, () => {
const p1a = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 1000);
}, 100);
});

return p1a;
Expand All @@ -124,7 +127,7 @@ describe('level 0a', { concurrency: 4 }, () => {
const p1c = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 2000);
}, 200);
});

return p1c;
Expand All @@ -134,7 +137,7 @@ describe('level 0a', { concurrency: 4 }, () => {
const p1c = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 1500);
}, 150);
});

return p1c;
Expand All @@ -143,7 +146,7 @@ describe('level 0a', { concurrency: 4 }, () => {
const p0a = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 3000);
}, 300);
});

return p0a;
Expand Down Expand Up @@ -309,12 +312,12 @@ describe('describe async throw fails', async () => {
describe('timeouts', () => {
it('timed out async test', { timeout: 5 }, async () => {
return new Promise((resolve) => {
setTimeout(resolve, 1000);
setTimeout(resolve, 100);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these setTimeouts use common platform timeout machinery or are you convinced there is no/little flakiness potential here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have already changed these values in the equivalent test recipe test

});
});

it('timed out callback test', { timeout: 5 }, (done) => {
setTimeout(done, 1000);
setTimeout(done, 100);
});


Expand Down
Loading