Repository navigation
feat(module,vitest-environment): support vite-plus test
#1861
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bfe13a2
fix(vitest-environment): resolve vitest from package location
danielroe 5d11282
fix(module): accept `vi` import from `vite-plus/test`
danielroe a580338
fix(module): add `vi` import when existing `vi` import is aliased
danielroe a850f73
test: load nuxt environment through vitest in regression test
danielroe 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 hidden or 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 hidden or 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 hidden or 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, it } from 'vitest' | ||
|
|
||
| it('runs in the nuxt environment', () => { | ||
| expect(window.__NUXT_VITEST_ENVIRONMENT__).toBe(true) | ||
| }) |
This file contains hidden or 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,15 @@ | ||
| import { defineConfig } from 'vitest/config' | ||
|
|
||
| export default defineConfig({ | ||
| resolve: { | ||
| alias: { | ||
| '#nuxt-test-utils/h3': 'h3', | ||
| }, | ||
| }, | ||
| test: { | ||
| environment: 'nuxt', | ||
| environmentOptions: { | ||
| nuxt: {}, | ||
| }, | ||
| }, | ||
| }) |
This file contains hidden or 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 hidden or 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,30 @@ | ||
| import { mkdtemp, rm } from 'node:fs/promises' | ||
| import { tmpdir } from 'node:os' | ||
| import { join } from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
| import { x } from 'tinyexec' | ||
| import { afterAll, describe, expect, it } from 'vitest' | ||
|
|
||
| const TEST_TIMEOUT = process.env.CI ? 60_000 : 30_000 | ||
|
|
||
| const fixtureDir = fileURLToPath(new URL('../fixtures/vitest-environment', import.meta.url)) | ||
|
|
||
| describe('nuxt vitest environment', () => { | ||
| const dirs: string[] = [] | ||
|
|
||
| afterAll(async () => { | ||
| await Promise.all(dirs.map(dir => rm(dir, { recursive: true, force: true }))) | ||
| }) | ||
|
|
||
| it('should run when vitest cannot be resolved from cwd', async () => { | ||
| const cwd = await mkdtemp(join(tmpdir(), 'nuxt-test-utils-env-')) | ||
| dirs.push(cwd) | ||
|
|
||
| const result = await x('vitest', ['run', '--root', fixtureDir, '--no-color'], { | ||
| nodeOptions: { cwd }, | ||
| }) | ||
|
|
||
| expect.assert(result.exitCode === 0, result.stderr) | ||
| expect(result.stdout).toContain('1 passed') | ||
| }, TEST_TIMEOUT) | ||
| }) |
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: nuxt/test-utils
Length of output: 5178
🏁 Script executed:
Repository: nuxt/test-utils
Length of output: 9718
🏁 Script executed:
Repository: nuxt/test-utils
Length of output: 3802
🌐 Web query:
vite-plus 1.3 package.json bundled vitest runtime vite-plus/test💡 Result:
🌐 Web query:
exsolve resolveModulePath from option import.meta.url package resolution documentation💡 Result:
🌐 Web query:
vite-plus@1.3.0 package.json dependencies vitest package exports vite-plus/test💡 Result:
🏁 Script executed:
Repository: nuxt/test-utils
Length of output: 19717
🏁 Script executed:
Repository: nuxt/test-utils
Length of output: 1966
🌐 Web query:
site:github.com/voidzero-dev/vite-plus/issues/1506 vite-plus vitest runtime Nuxt test-utils getPackageInfo💡 Result:
🌐 Web query:
vite-plus 1.3 test/runtime populateGlobal dist/test/runtime.js vitest runtime export💡 Result:
Resolve Vite+ through
vite-plus/test/runtime.vite-plus@1.3.0keeps Vitest 5.0.5 as a nested dependency. It exposes the supported runtime asvite-plus/test/runtime, not asvitest/runtime.The changed lookups start from
@nuxt/test-utilsand request the barevitestpackage. In an isolated install, that path cannot reachvite-plus/node_modules/vitest.vitestMajorbecomesNaN, and the fallback importsvitest/environments. Nuxt environment startup can then fail undervp test.Use the Vite+ runtime when it is available, and use its declared Vitest version for the Vitest 5 cleanup behavior.
Suggested fix
🤖 Prompt for AI Agents