Open colinaaa opened 4 months ago
This looks like a bug in @bcoe/v8-coverage
(👋 @bcoe). Here's minimal reproduction without Vitest in pure Javascript https://github.com/AriPerkkio/reproductions/tree/v8-merge.
import { mergeProcessCovs } from "@bcoe/v8-coverage";
import { writeFileSync } from "node:fs";
import inspector from "node:inspector";
writeFileSync(
"./source-file.js",
`
export class Foo {
static Baz = process.env["NODE_ENV"] === "test" ? "some" : "thing";
// Remove this will not cause error
static Bar = {};
}
`.trim(),
"utf8"
);
const session = new inspector.Session();
session.connect();
session.post("Profiler.enable");
session.post("Profiler.startPreciseCoverage", {
callCount: true,
detailed: true,
});
await import("./source-file.js");
const coverage = await collectCoverage("source-file.js");
console.log(JSON.stringify(coverage, null, 2));
mergeProcessCovs([coverage]);
async function collectCoverage(filename) {
return new Promise((resolve, reject) => {
session.post("Profiler.takePreciseCoverage", async (error, coverage) => {
if (error) return reject(error);
const result = coverage.result.filter((entry) =>
entry.url.includes(filename)
);
resolve({ result });
});
});
}
$ node index.mjs
{
"result": [
{
"scriptId": "499",
"url": "file:///<root>/reproductions/source-file.js",
"functions": [
{
"functionName": "",
"ranges": [
{
"startOffset": 0,
"endOffset": 148,
"count": 1
}
],
"isBlockCoverage": true
},
{
"functionName": "<static_initializer>",
"ranges": [
{
"startOffset": 130,
"endOffset": 145,
"count": 1
},
{
"startOffset": 69,
"endOffset": 77,
"count": 0
}
],
"isBlockCoverage": true
}
]
}
]
}
/<root>/reproductions/node_modules/.pnpm/@bcoe+v8-coverage@0.2.3/node_modules/@bcoe/v8-coverage/dist/lib/range-tree.js:27
[parent, parentCount] = stack[stack.length - 1];
^
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
at RangeTree.fromSortedRanges (/<root>/reproductions/node_modules/.pnpm/@bcoe+v8-coverage@0.2.3/node_modules/@bcoe/v8-coverage/dist/lib/range-tree.js:27:39)
at normalizeFunctionCov (/<root>/reproductions/node_modules/.pnpm/@bcoe+v8-coverage@0.2.3/node_modules/@bcoe/v8-coverage/dist/lib/normalize.js:74:41)
at Object.deepNormalizeScriptCov (/<root>/reproductions/node_modules/.pnpm/@bcoe+v8-coverage@0.2.3/node_modules/@bcoe/v8-coverage/dist/lib/normalize.js:59:9)
at mergeScriptCovs (/<root>/reproductions/node_modules/.pnpm/@bcoe+v8-coverage@0.2.3/node_modules/@bcoe/v8-coverage/dist/lib/merge.js:59:21)
at mergeProcessCovs (/<root>/reproductions/node_modules/.pnpm/@bcoe+v8-coverage@0.2.3/node_modules/@bcoe/v8-coverage/dist/lib/merge.js:34:21)
at file:///<root>/reproductions/index.mjs:32:1
Node.js v18.17.1
Describe the bug
I'm using vitest and a coverage error showed up after I added a
static
class field:I tried to minimize the reproduction demo and it seems like it is related to
useDefineForClassFields
. See the Reproduction section for details.Reproduction
A minimal reproduction repo is created at: https://github.com/colinaaa/vitest-v8-repro
Just run
pnpm install
pnpm vitest --coverage
to reproduce the issue.
Note that any of these will eliminate the error:
useDefineForClassFields
intsconfig.json
coverage-v8
withcoverage-istanbul
static Bar
static Baz
withrequire.resole('./loader.js')
System Info
Used Package Manager
pnpm
Validations