Skip to content

Commit

Permalink
test_runner: allow nesting test within describe
Browse files Browse the repository at this point in the history
PR-URL: nodejs#46544
Fixes: nodejs#46478
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
MoLow committed Feb 18, 2023
1 parent 6ac158d commit ed06bf6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 62 deletions.
3 changes: 2 additions & 1 deletion lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ function getGlobalRoot() {
}

function test(name, options, fn) {
const subtest = getGlobalRoot().createSubtest(Test, name, options, fn);
const parent = testResources.get(executionAsyncId()) || getGlobalRoot();
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);
});
});

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


Expand Down
Loading

0 comments on commit ed06bf6

Please sign in to comment.