-
-
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(vitest): invalidate setupFiles with extension-less path #6749
Draft
hi-ogawa
wants to merge
2
commits into
vitest-dev:main
Choose a base branch
from
hi-ogawa:fix-resolve-setupFile-before-invalidate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,9 @@ | ||
import { beforeEach } from 'vitest'; | ||
|
||
export type MyContext = { | ||
testOk: boolean | ||
} | ||
|
||
beforeEach<MyContext>((ctx) => { | ||
ctx.testOk = true; | ||
}); | ||
AriPerkkio marked this conversation as resolved.
Show resolved
Hide resolved
|
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,9 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
setupFiles: ['./setup'], | ||
isolate: false, | ||
fileParallelism: false, | ||
}, | ||
}); |
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,6 @@ | ||
import { expect, test } from "vitest" | ||
import type { MyContext } from "./setup" | ||
|
||
test<MyContext>("x", (ctx) => { | ||
expect(ctx.testOk).toBe(true) | ||
}) |
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,6 @@ | ||
import { expect, test } from "vitest" | ||
import type { MyContext } from "./setup" | ||
|
||
test<MyContext>("y", (ctx) => { | ||
expect(ctx.testOk).toBe(true) | ||
}) |
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,11 @@ | ||
import path from 'node:path' | ||
import { expect, test } from 'vitest' | ||
import { runVitest } from '../../test-utils' | ||
|
||
test('re-import setupFiles with no isolate', async () => { | ||
const root = path.resolve(import.meta.dirname, '../fixtures/setup-file-no-isolate') | ||
|
||
const { stderr, exitCode } = await runVitest({ root }) | ||
expect(stderr).toBe('') | ||
expect(exitCode).toBe(0) | ||
}) |
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.
Shouldn't it be resolved here even without the extension?
vitest/packages/vitest/src/node/config/resolveConfig.ts
Line 311 in 63f8b07
This worked before without problems
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 imagine it's working for most of the case, but the issue was when it's extension-less relative path. For example,
setupFiles: ['./setup.ts']
works butsetupFiles: ['./setup']
fails, which was OP's repro.Alternatively, we can use Vite server resolver during
resolveConfig
or sometime later if we restructure a bit, but I thought there might be a reason not to bring that.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 am saying that it shouldn't fail even without the extension
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.
Yeah, we should fix it for sure, but I don't think this was a regression and extension-less relative path has never been handled with proper invalidation. I'll think about the solution.
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.
In any way, I don't think the current fix in this PR is the correct one. In the very least it seems weird to me that it processes the same setup file in every test (which means it processes the same value multiple times). The setup file ID should be resolved already at the config stage. The
resolvePath
inresolveConfig
is supposed to be able to resolve any JS paths even without an extension as far as I understand - why doesn't it? 🤔