-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Open
Description
Version
24.12.0
Platform
Microsoft Windows NT 10.0.22631.0 x64
Subsystem
test_runner
What steps will reproduce the bug?
Run test node test with --experimental-test-coverage on source code with a directory named file.
Steps to Reproduce
- Create
src/file/index.js
export function a() {
console.log("!");
return 1;
}- Create
src/file/__tests__/index.spec.js
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { a } from "../index.js"
describe("a", async function () {
it("test", async function () {
const result = a();
assert.equal(result, 1);
})
});- npm run test with
node --experimental-test-coverage --test \"./src/**/__tests__/*.{spec,test}.js\".
Findings
node/lib/internal/test_runner/utils.js
Lines 552 to 555 in dcb9573
| function printCoverageBodyTree(tree, depth = 0) { | |
| for (const key in tree) { | |
| if (tree[key].file) { | |
| const file = tree[key].file; |
In printCoverageBodyTree, a directory named file seems to conflict with internal variable named file. Causing it to treat the directory as a file.
How often does it reproduce? Is there a required condition?
100%
What is the expected behavior? Why is that the expected behavior?
Generate test coverage normally.
What do you see instead?
TypeError: String.prototype.split called on null or undefined
at split (<anonymous>)
at printCoverageBodyTree (node:internal/test_runner/utils:536:44)
at printCoverageBodyTree (node:internal/test_runner/utils:565:9)
at getCoverageReport (node:internal/test_runner/utils:585:3)
at #handleEvent (node:internal/test_runner/reporter/spec:102:16)
at SpecReporter._transform (node:internal/test_runner/reporter/spec:112:37)
at Transform._write (node:internal/streams/transform:171:8)
at writeOrBuffer (node:internal/streams/writable:570:12)
at _write (node:internal/streams/writable:499:10)
at Writable.write (node:internal/streams/writable:508:10)
Emitted 'error' event on Readable instance at:
at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
Additional information
No response
Metadata
Metadata
Assignees
Labels
No labels