-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: throw an error, if tests are collected with a different vitest v…
…ersion (#3301)
- Loading branch information
1 parent
93fbd02
commit 708b10f
Showing
4 changed files
with
30 additions
and
0 deletions.
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
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,22 @@ | ||
import { version as VERSION } from '../package.json' | ||
|
||
export function getVersion(): string { | ||
// @ts-expect-error internal variable | ||
return globalThis.__vitest_runner_version__ || VERSION | ||
} | ||
|
||
export function markVersion(): void { | ||
// @ts-expect-error internal variable | ||
globalThis.__vitest_runner_version__ = VERSION | ||
} | ||
|
||
export function checkVersion() { | ||
const collectVersion = getVersion() | ||
|
||
if (collectVersion !== VERSION) { | ||
const error = `Version mismatch: Vitest started as ${collectVersion}, but tests are collected with ${VERSION} version.` | ||
+ '\n\n- If you are using global Vitest, make sure your package has the same version.' | ||
+ '\n- If you have a monorepo setup, make sure your main package has the same version as your test packages.' | ||
throw new Error(error) | ||
} | ||
} |