-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(coverage): vite-node
to pass correct execution wrapper offset
#7417
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
954d2a1
to
0f3f4f5
Compare
@vitest/web-worker
with v8 coveragevite-node
to pass correct execution wrapper offset
e7a39cc
to
4e458b0
Compare
// TODO: vite-node should export this | ||
const WRAPPER_LENGTH = 185 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally getting rid of this 🥳
4e458b0
to
008b10d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me 👍
I'm wondering what happens if the same file is imported from test and from @vitest/web-worker
. Does startOffset
conflict (last loaded win?) and so coverage is likely broken?
Yep, coverage could break then. Also V8 gets confused as the same file ID had different contents when executed. The script coverage is a mess then. |
Do we need to update vitest's |
@@ -313,6 +320,8 @@ export class VitestExecutor extends ViteNodeRunner { | |||
columnOffset: -codeDefinition.length, | |||
} | |||
|
|||
this.options.moduleExecutionInfo?.set(options.filename, { startOffset: codeDefinition.length }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if filename
is a good choice here. Wouldn't url
be better? It should include queries if there are any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now as it's using moduleCache
, the key must match that one. I think the options.filename
here contains query params too 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moduleCache
doesn't use filename
tho, it uses normalized module id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll add test case that loads Worker with query params later.
This change should break Vue tests if query params are missing. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The used id/filename must match the one that is being passed as filename
in vm.runInThisContext
. That's what V8 sets in the runtime results.
moduleCache doesn't use filename tho, it uses normalized module id
When are these two different? Can't see any differences between these two in the tests.
Which package here? vitest/packages/vitest/package.json Lines 124 to 132 in 12eaf3e
Or you mean about using mixed versions? A year ago (#5208) we made the decision that Vitest monorepo's packages do not work with mixed versions. All packages must have the same version. And we've been introducing breaking changes between the packages ever since. There are also runtime warnings in |
de7dc2a
to
e5fa58a
Compare
e5fa58a
to
89102c3
Compare
@@ -203,6 +203,7 @@ it('self injected into worker and its deps should be equal', async () => { | |||
await sleep(0) | |||
expect(await testSelfWorker(new MySelfWorker())).toBeTruthy() | |||
|
|||
vi.resetModules() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test should work without clearing modules, that's the whole point of it, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this test actually contained "two tests", as in first the MySelfWorker
part and then Worker
part.
If this test should pass without module reset, we cannot move the module invalidation in InlineWorker
to happen before executeFile
. So cannot use ModuleCache
for holding the startOffset
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a single test, the worker is the same, just initiated differently.
So cannot use
ModuleCache
for holding thestartOffset
.
Seems like we need to go to the drawing board then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup I'll need to revert b736b63 and not rely on ModuleCache
.
Description
Makes
vite-node
to hold info about the execution wrapper it uses when executing modules. Coverage providers are passed this info on the test runner thread so that they can attach it into the coverage results. There's no longer need to hard-code the wrapper length on main thread codebase. The exampleweb-worker.test.ts
has a case where in a single test runner thread some code is executed with 185 long wrapper and some with ~430 long wrapper.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.