Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: respect transformMode when resolving id (#1506)
* fix: consider transform mode when resolving ids * test: testing resolveId * chore: cleanup * chore: use importer to get transform mode when resolving id * chore: update lockfile
- Loading branch information
1 parent
9f9216f
commit 406f995
Showing
5 changed files
with
64 additions
and
9 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 @@ | ||
{ | ||
"name": "@vitest/test-vite-node", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest", | ||
"coverage": "vitest run --coverage" | ||
}, | ||
"devDependencies": { | ||
"vite": "^2.9.10", | ||
"vite-node": "workspace:*", | ||
"vitest": "workspace:*" | ||
} | ||
} |
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,31 @@ | ||
import type { ViteDevServer } from 'vite' | ||
import { ViteNodeServer } from 'vite-node/server' | ||
import { describe, expect, test, vi } from 'vitest' | ||
|
||
const mockDevServer = (options: any = {}) => { | ||
return options as ViteDevServer | ||
} | ||
|
||
describe('server works correctly', async () => { | ||
test('resolve id considers transform mode', async () => { | ||
const resolveId = vi.fn() | ||
|
||
const vnServer = new ViteNodeServer(mockDevServer({ | ||
pluginContainer: { resolveId }, | ||
config: { | ||
root: '/', | ||
}, | ||
}), { | ||
transformMode: { | ||
web: [/web/], | ||
ssr: [/ssr/], | ||
}, | ||
}) | ||
|
||
await vnServer.resolveId('/path', '/web path') | ||
expect(resolveId).toHaveBeenCalledWith('/path', '/web path', { ssr: false }) | ||
|
||
await vnServer.resolveId('/ssr', '/ssr path') | ||
expect(resolveId).toHaveBeenCalledWith('/ssr', '/ssr path', { ssr: 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,7 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
clearMocks: true, | ||
}, | ||
}) |