Open
Description
This module behaves notably differently when it comes to printing stack traces when test groups fail.
Here is a simple test:
const assert = require('assert')
const test = require('node:test')
test('parent test', async t => {
await t.test('sub test', async t => {
assert(false)
})
})
Node core (v18.8.0):
$ node example.js
TAP version 13
# Subtest: parent test
# Subtest: sub test
not ok 1 - sub test
---
duration_ms: 0.00944469
failureType: 'testCodeFailure'
error: |-
The expression evaluated to a falsy value:
assert(false)
code: 'ERR_ASSERTION'
stack: |-
TestContext.<anonymous> (/Users/julian/dev/nodejs/node-core-test/example.js:8:5)
Test.runInAsyncScope (node:async_hooks:203:9)
Test.run (node:internal/test_runner/test:483:25)
Test.start (node:internal/test_runner/test:410:17)
TestContext.test (node:internal/test_runner/test:114:20)
TestContext.<anonymous> (/Users/julian/dev/nodejs/node-core-test/example.js:7:11)
Test.runInAsyncScope (node:async_hooks:203:9)
Test.run (node:internal/test_runner/test:483:25)
Test.start (node:internal/test_runner/test:410:17)
Test.test (node:internal/test_runner/harness:155:18)
...
1..1
not ok 1 - parent test
---
duration_ms: 0.011879383
failureType: 'subtestsFailed'
error: '1 subtest failed'
code: 'ERR_TEST_FAILURE'
...
1..1
# tests 1
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 0.049244309
This module:
TAP version 13
# Subtest: parent test
# Subtest: sub test
not ok 1 - sub test
---
duration_ms: 0.011840078
failureType: 'testCodeFailure'
error: |-
The expression evaluated to a falsy value:
assert(false)
code: 'ERR_ASSERTION'
stack: |-
TestContext.<anonymous> (/Users/julian/dev/nodejs/node-core-test/example.js:8:5)
Test.runInAsyncScope (node:async_hooks:202:9)
exports.ReflectApply (/Users/julian/dev/nodejs/node-core-test/lib/internal/per_context/primordials.js:32:56)
Test.run (/Users/julian/dev/nodejs/node-core-test/lib/internal/test_runner/test.js:485:25)
Test.start (/Users/julian/dev/nodejs/node-core-test/lib/internal/test_runner/test.js:412:17)
TestContext.test (/Users/julian/dev/nodejs/node-core-test/lib/internal/test_runner/test.js:116:20)
TestContext.<anonymous> (/Users/julian/dev/nodejs/node-core-test/example.js:7:11)
Test.runInAsyncScope (node:async_hooks:202:9)
exports.ReflectApply (/Users/julian/dev/nodejs/node-core-test/lib/internal/per_context/primordials.js:32:56)
Test.run (/Users/julian/dev/nodejs/node-core-test/lib/internal/test_runner/test.js:485:25)
...
1..1
not ok 1 - parent test
---
duration_ms: 0.015167603
failureType: 'subtestsFailed'
error: '1 subtest failed'
code: 'ERR_TEST_FAILURE'
stack: |-
exports.ErrorCaptureStackTrace (/Users/julian/dev/nodejs/node-core-test/lib/internal/per_context/primordials.js:18:53)
__node_internal_captureLargerStackTrace (/Users/julian/dev/nodejs/node-core-test/lib/internal/errors.js:311:5)
new NodeError (/Users/julian/dev/nodejs/node-core-test/lib/internal/errors.js:238:5)
Test.postRun (/Users/julian/dev/nodejs/node-core-test/lib/internal/test_runner/test.js:546:17)
Test.run (/Users/julian/dev/nodejs/node-core-test/lib/internal/test_runner/test.js:513:10)
process.processTicksAndRejections (node:internal/process/task_queues:95:5)
...
1..1
# tests 1
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 0.122793632
The stack trace from parent test
shouldn't be shown. I haven't yet looked into why this is happening.