-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use useDefineForClassFields
with coverage-v8
and vitest workspace cause error
#5329
Comments
This looks like a bug in 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 |
I'm going to need to strip out the ancient TypeScript from v8-coverage before I can build and release, the toolchain from 6 years ago is very broken. |
@colinaaa @AriPerkkio, I believe this should now be addressed in |
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
The text was updated successfully, but these errors were encountered: