forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ssr external / resolveId test (vitejs#18327)
- Loading branch information
Showing
6 changed files
with
65 additions
and
4 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
2 changes: 2 additions & 0 deletions
2
packages/vite/src/node/__tests__/fixtures/test-dep-conditions-app/entry-with-module.js
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,2 @@ | ||
import dep from '@vitejs/test-dep-conditions/with-module' | ||
export default dep |
1 change: 1 addition & 0 deletions
1
packages/vite/src/node/__tests__/fixtures/test-dep-conditions/dir/index.default.js
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 @@ | ||
export default 'dir/index.default.js' |
1 change: 1 addition & 0 deletions
1
packages/vite/src/node/__tests__/fixtures/test-dep-conditions/dir/index.module.js
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 @@ | ||
export default 'dir/index.module.js' |
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,52 @@ | ||
import { describe, expect, onTestFinished, test } from 'vitest' | ||
import { createServer } from '../server' | ||
import { createServerModuleRunner } from '../ssr/runtime/serverModuleRunner' | ||
|
||
describe('import and resolveId', () => { | ||
async function createTestServer() { | ||
const server = await createServer({ | ||
configFile: false, | ||
root: import.meta.dirname, | ||
logLevel: 'error', | ||
server: { | ||
middlewareMode: true, | ||
}, | ||
}) | ||
onTestFinished(() => server.close()) | ||
const runner = createServerModuleRunner(server.environments.ssr, { | ||
hmr: { | ||
logger: false, | ||
}, | ||
sourcemapInterceptor: false, | ||
}) | ||
return { server, runner } | ||
} | ||
|
||
test('import first', async () => { | ||
const { server, runner } = await createTestServer() | ||
const mod = await runner.import( | ||
'/fixtures/test-dep-conditions-app/entry-with-module', | ||
) | ||
const resolved = await server.environments.ssr.pluginContainer.resolveId( | ||
'@vitejs/test-dep-conditions/with-module', | ||
) | ||
expect([mod.default, resolved?.id]).toEqual([ | ||
'dir/index.default.js', | ||
expect.stringContaining('dir/index.module.js'), | ||
]) | ||
}) | ||
|
||
test('resolveId first', async () => { | ||
const { server, runner } = await createTestServer() | ||
const resolved = await server.environments.ssr.pluginContainer.resolveId( | ||
'@vitejs/test-dep-conditions/with-module', | ||
) | ||
const mod = await runner.import( | ||
'/fixtures/test-dep-conditions-app/entry-with-module', | ||
) | ||
expect([mod.default, resolved?.id]).toEqual([ | ||
'dir/index.default.js', | ||
expect.stringContaining('dir/index.module.js'), | ||
]) | ||
}) | ||
}) |