-
-
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
fix: call resolveId('vitest')
after buildStart
#5646
Merged
sheremet-va
merged 8 commits into
vitest-dev:main
from
hi-ogawa:fix-avoid-early-resolveId
May 2, 2024
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
606fe8c
fix: use `resolve.resolve('vitest')` instead of `resolveId` during in…
hi-ogawa 0db4486
test: add test
hi-ogawa 1037511
wip: just delay til `Vitest.start`?
hi-ogawa 04df286
fix: delay initializeDistPath + test createVitest
hi-ogawa 997566a
test: simplify
hi-ogawa 32ded40
refactor: minor
hi-ogawa 4296dea
fix: reset distPath
hi-ogawa 74a9636
Merge branch 'main' into fix-avoid-early-resolveId
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
test("basic", () => { | ||
expect(1).toBe(1); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
{ | ||
name: "test-default", | ||
configureServer() { | ||
console.log("##test## configureServer(default)") | ||
hi-ogawa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
buildStart() { | ||
console.log("##test## buildStart(default)") | ||
}, | ||
resolveId(source) { | ||
console.log("##test## resolveId(default)") | ||
console.log({ source }) | ||
}, | ||
transform(_code, id) { | ||
console.log("##test## transform(default)") | ||
console.log({ id }) | ||
}, | ||
}, | ||
{ | ||
name: "test-pre", | ||
enforce: "pre", | ||
configureServer() { | ||
console.log("##test## configureServer(pre)") | ||
}, | ||
buildStart() { | ||
console.log("##test## buildStart(pre)") | ||
}, | ||
resolveId(source) { | ||
console.log("##test## resolveId(pre)") | ||
console.log({ source }) | ||
}, | ||
transform(_code, id) { | ||
console.log("##test## transform(pre)") | ||
console.log({ id }) | ||
}, | ||
} | ||
] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Console } from 'node:console' | ||
import { Writable } from 'node:stream' | ||
import { expect, it, vi } from 'vitest' | ||
import { runVitest } from '../../test-utils' | ||
|
||
it('plugin hooks', async () => { | ||
// capture console on main process | ||
let stdout = '' | ||
vi.stubGlobal('console', new Console({ | ||
stdout: new Writable({ | ||
write: (data, _, callback) => { | ||
stdout += String(data) | ||
callback() | ||
}, | ||
}), | ||
})) | ||
await runVitest({ root: './fixtures/plugin' }) | ||
vi.unstubAllGlobals() | ||
|
||
const lines = stdout.split('\n').filter(line => line.startsWith('##test##')) | ||
expect(lines.slice(0, 5)).toEqual([ | ||
'##test## configureServer(pre)', | ||
'##test## configureServer(default)', | ||
'##test## buildStart(pre)', | ||
'##test## buildStart(default)', | ||
'##test## resolveId(pre)', | ||
]) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
vs code extension doesn't call
start
at allThere 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.
Oh, really...
I had
createRequire
approach before 1037511. Would this work better?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.
Or we could delay it further to
ctx.runFiles
. Let me think...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
createRequire
approach is wrong because we need Vite to process it. Having it in runFiles is fine. We can have a guard to not check this path if it is resolved, and reset it inconfigureServer
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.
Do we need Vite's resolution? If the purpose is only to find local Vitest, would
createRequire
withrequire.resolve('vitest', { paths: [config.root] })
do the same?This was the approach used for package installer:
vitest/packages/vitest/src/node/packageInstaller.ts
Lines 15 to 18 in 04df286
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.
We need Vite's resolution because files importing vitest are processed by Vite. It's possible that Vitest is called globally and resolved id is not correct, or there is an alias or resolveId interception