diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index 45dd90e..a4112c2 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -129,7 +129,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() } diff --git a/test/message/test_runner_desctibe_it.js b/test/message/test_runner_desctibe_it.js index d8c1bb3..304a672 100644 --- a/test/message/test_runner_desctibe_it.js +++ b/test/message/test_runner_desctibe_it.js @@ -3,7 +3,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') it.todo('sync pass todo', () => { @@ -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') }) @@ -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 () => { @@ -106,7 +109,7 @@ describe('level 0a', { concurrency: 4 }, () => { const p1a = new Promise((resolve) => { setTimeout(() => { resolve() - }, 1000) + }, 100) }) return p1a @@ -124,7 +127,7 @@ describe('level 0a', { concurrency: 4 }, () => { const p1c = new Promise((resolve) => { setTimeout(() => { resolve() - }, 2000) + }, 200) }) return p1c @@ -134,7 +137,7 @@ describe('level 0a', { concurrency: 4 }, () => { const p1c = new Promise((resolve) => { setTimeout(() => { resolve() - }, 1500) + }, 150) }) return p1c @@ -143,7 +146,7 @@ describe('level 0a', { concurrency: 4 }, () => { const p0a = new Promise((resolve) => { setTimeout(() => { resolve() - }, 3000) + }, 300) }) return p0a @@ -308,12 +311,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) }) it('large timeout async test is ok', { timeout: 30_000_000 }, async () => { diff --git a/test/message/test_runner_desctibe_it.out b/test/message/test_runner_desctibe_it.out index 208097d..9faeacd 100644 --- a/test/message/test_runner_desctibe_it.out +++ b/test/message/test_runner_desctibe_it.out @@ -82,8 +82,13 @@ ok 10 - async pass --- duration_ms: * ... +# Subtest: mixing describe/it and test should work +ok 11 - mixing describe/it and test should work + --- + duration_ms: * + ... # Subtest: async throw fail -not ok 11 - async throw fail +not ok 12 - async throw fail --- duration_ms: * failureType: 'testCodeFailure' @@ -99,7 +104,7 @@ not ok 11 - async throw fail * ... # Subtest: async skip fail -not ok 12 - async skip fail +not ok 13 - async skip fail --- duration_ms: * failureType: 'callbackAndPromisePresent' @@ -107,7 +112,7 @@ not ok 12 - async skip fail code: 'ERR_TEST_FAILURE' ... # Subtest: async assertion fail -not ok 13 - async assertion fail +not ok 14 - async assertion fail --- duration_ms: * failureType: 'testCodeFailure' @@ -130,12 +135,12 @@ not ok 13 - async assertion fail * ... # Subtest: resolve pass -ok 14 - resolve pass +ok 15 - resolve pass --- duration_ms: * ... # Subtest: reject fail -not ok 15 - reject fail +not ok 16 - reject fail --- duration_ms: * failureType: 'testCodeFailure' @@ -151,27 +156,27 @@ not ok 15 - reject fail * ... # Subtest: unhandled rejection - passes but warns -ok 16 - unhandled rejection - passes but warns +ok 17 - unhandled rejection - passes but warns --- duration_ms: * ... # Subtest: async unhandled rejection - passes but warns -ok 17 - async unhandled rejection - passes but warns +ok 18 - async unhandled rejection - passes but warns --- duration_ms: * ... # Subtest: immediate throw - passes but warns -ok 18 - immediate throw - passes but warns +ok 19 - immediate throw - passes but warns --- duration_ms: * ... # Subtest: immediate reject - passes but warns -ok 19 - immediate reject - passes but warns +ok 20 - immediate reject - passes but warns --- duration_ms: * ... # Subtest: immediate resolve pass -ok 20 - immediate resolve pass +ok 21 - immediate resolve pass --- duration_ms: * ... @@ -195,8 +200,13 @@ ok 20 - immediate resolve pass * * ... - 1..1 -not ok 21 - subtest sync throw fail + # Subtest: mixing describe/it and test should work + ok 2 - mixing describe/it and test should work + --- + duration_ms: * + ... + 1..2 +not ok 22 - subtest sync throw fail --- duration_ms: * failureType: 'subtestsFailed' @@ -205,7 +215,7 @@ not ok 21 - subtest sync throw fail stack: |- ... # Subtest: sync throw non-error fail -not ok 22 - sync throw non-error fail +not ok 23 - sync throw non-error fail --- duration_ms: * failureType: 'testCodeFailure' @@ -235,27 +245,27 @@ not ok 22 - sync throw non-error fail duration_ms: * ... 1..4 -ok 23 - level 0a +ok 24 - level 0a --- duration_ms: * ... # Subtest: invalid subtest - pass but subtest fails -ok 24 - invalid subtest - pass but subtest fails +ok 25 - invalid subtest - pass but subtest fails --- duration_ms: * ... # Subtest: sync skip option -ok 25 - sync skip option # SKIP +ok 26 - sync skip option # SKIP --- duration_ms: * ... # Subtest: sync skip option with message -ok 26 - sync skip option with message # SKIP this is skipped +ok 27 - sync skip option with message # SKIP this is skipped --- duration_ms: * ... # Subtest: sync skip option is false fail -not ok 27 - sync skip option is false fail +not ok 28 - sync skip option is false fail --- duration_ms: * failureType: 'testCodeFailure' @@ -271,67 +281,67 @@ not ok 27 - sync skip option is false fail * ... # Subtest: -ok 28 - +ok 29 - --- duration_ms: * ... # Subtest: functionOnly -ok 29 - functionOnly +ok 30 - functionOnly --- duration_ms: * ... # Subtest: -ok 30 - +ok 31 - --- duration_ms: * ... # Subtest: test with only a name provided -ok 31 - test with only a name provided +ok 32 - test with only a name provided --- duration_ms: * ... # Subtest: -ok 32 - +ok 33 - --- duration_ms: * ... # Subtest: -ok 33 - # SKIP +ok 34 - # SKIP --- duration_ms: * ... # Subtest: test with a name and options provided -ok 34 - test with a name and options provided # SKIP +ok 35 - test with a name and options provided # SKIP --- duration_ms: * ... # Subtest: functionAndOptions -ok 35 - functionAndOptions # SKIP +ok 36 - functionAndOptions # SKIP --- duration_ms: * ... # Subtest: escaped description \\ \# \\\#\\ -ok 36 - escaped description \\ \# \\\#\\ +ok 37 - escaped description \\ \# \\\#\\ --- duration_ms: * ... # Subtest: escaped skip message -ok 37 - escaped skip message # SKIP \#skip +ok 38 - escaped skip message # SKIP \#skip --- duration_ms: * ... # Subtest: escaped todo message -ok 38 - escaped todo message # TODO \#todo +ok 39 - escaped todo message # TODO \#todo --- duration_ms: * ... # Subtest: callback pass -ok 39 - callback pass +ok 40 - callback pass --- duration_ms: * ... # Subtest: callback fail -not ok 40 - callback fail +not ok 41 - callback fail --- duration_ms: * failureType: 'testCodeFailure' @@ -342,22 +352,22 @@ not ok 40 - callback fail * ... # Subtest: sync t is this in test -ok 41 - sync t is this in test +ok 42 - sync t is this in test --- duration_ms: * ... # Subtest: async t is this in test -ok 42 - async t is this in test +ok 43 - async t is this in test --- duration_ms: * ... # Subtest: callback t is this in test -ok 43 - callback t is this in test +ok 44 - callback t is this in test --- duration_ms: * ... # Subtest: callback also returns a Promise -not ok 44 - callback also returns a Promise +not ok 45 - callback also returns a Promise --- duration_ms: * failureType: 'callbackAndPromisePresent' @@ -366,7 +376,7 @@ not ok 44 - callback also returns a Promise stack: |- ... # Subtest: callback throw -not ok 45 - callback throw +not ok 46 - callback throw --- duration_ms: * failureType: 'testCodeFailure' @@ -382,7 +392,7 @@ not ok 45 - callback throw * ... # Subtest: callback called twice -not ok 46 - callback called twice +not ok 47 - callback called twice --- duration_ms: * failureType: 'multipleCallbackInvocations' @@ -393,12 +403,12 @@ not ok 46 - callback called twice * ... # Subtest: callback called twice in different ticks -ok 47 - callback called twice in different ticks +ok 48 - callback called twice in different ticks --- duration_ms: * ... # Subtest: callback called twice in future tick -not ok 48 - callback called twice in future tick +not ok 49 - callback called twice in future tick --- duration_ms: * failureType: 'uncaughtException' @@ -408,7 +418,7 @@ not ok 48 - callback called twice in future tick * ... # Subtest: callback async throw -not ok 49 - callback async throw +not ok 50 - callback async throw --- duration_ms: * failureType: 'uncaughtException' @@ -419,12 +429,12 @@ not ok 49 - callback async throw * ... # Subtest: callback async throw after done -ok 50 - callback async throw after done +ok 51 - callback async throw after done --- duration_ms: * ... # Subtest: custom inspect symbol fail -not ok 51 - custom inspect symbol fail +not ok 52 - custom inspect symbol fail --- duration_ms: * failureType: 'testCodeFailure' @@ -433,7 +443,7 @@ not ok 51 - custom inspect symbol fail stack: |- ... # Subtest: custom inspect symbol that throws fail -not ok 52 - custom inspect symbol that throws fail +not ok 53 - custom inspect symbol that throws fail --- duration_ms: * failureType: 'testCodeFailure' @@ -485,7 +495,7 @@ not ok 52 - custom inspect symbol that throws fail * ... 1..2 -not ok 53 - subtest sync throw fails +not ok 54 - subtest sync throw fails --- duration_ms: * failureType: 'subtestsFailed' @@ -503,7 +513,7 @@ not ok 53 - subtest sync throw fails code: 'ERR_TEST_FAILURE' ... 1..1 -not ok 54 - describe sync throw fails +not ok 55 - describe sync throw fails --- duration_ms: * failureType: 'testCodeFailure' @@ -531,7 +541,7 @@ not ok 54 - describe sync throw fails code: 'ERR_TEST_FAILURE' ... 1..1 -not ok 55 - describe async throw fails +not ok 56 - describe async throw fails --- duration_ms: * failureType: 'testCodeFailure' @@ -579,7 +589,7 @@ not ok 55 - describe async throw fails duration_ms: * ... 1..4 -not ok 56 - timeouts +not ok 57 - timeouts --- duration_ms: * failureType: 'subtestsFailed' @@ -604,7 +614,7 @@ not ok 56 - timeouts * ... 1..2 -not ok 57 - successful thenable +not ok 58 - successful thenable --- duration_ms: * failureType: 'subtestsFailed' @@ -612,7 +622,7 @@ not ok 57 - successful thenable code: 'ERR_TEST_FAILURE' ... # Subtest: rejected thenable -not ok 58 - rejected thenable +not ok 59 - rejected thenable --- duration_ms: * failureType: 'testCodeFailure' @@ -622,7 +632,7 @@ not ok 58 - rejected thenable * ... # Subtest: invalid subtest fail -not ok 59 - invalid subtest fail +not ok 60 - invalid subtest fail --- duration_ms: * failureType: 'parentAlreadyFinished' @@ -631,15 +641,15 @@ not ok 59 - invalid subtest fail stack: |- * ... -1..59 +1..60 # Warning: Test "unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. # Warning: Test "async unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from async unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. # Warning: Test "immediate throw - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from immediate throw fail" and would have caused the test to fail, but instead triggered an uncaughtException event. # Warning: Test "immediate reject - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from immediate reject fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. # Warning: Test "callback called twice in different ticks" generated asynchronous activity after the test ended. This activity created the error "Error [ERR_TEST_FAILURE]: callback invoked multiple times" and would have caused the test to fail, but instead triggered an uncaughtException event. # Warning: Test "callback async throw after done" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from callback async throw after done" and would have caused the test to fail, but instead triggered an uncaughtException event. -# tests 59 -# pass 22 +# tests 60 +# pass 23 # fail 23 # cancelled 0 # skipped 9 diff --git a/test/message/test_runner_output.js b/test/message/test_runner_output.js index 44d5141..629bff4 100644 --- a/test/message/test_runner_output.js +++ b/test/message/test_runner_output.js @@ -120,7 +120,7 @@ test('level 0a', { concurrency: 4 }, async (t) => { return p1a }) - t.test('level 1b', async (t) => { + test('level 1b', async (t) => { const p1b = new Promise((resolve) => { resolve() })