Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

Commit b72ff6d

Browse files
authored
test: add test for #523 (#524)
1 parent d488ed4 commit b72ff6d

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

playground/resolve/__tests__/resolve.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ test('plugin resolved virtual file', async () => {
151151
expect(await page.textContent('.virtual')).toMatch('[success]')
152152
})
153153

154+
test('plugin resolved virtual file that has import', async () => {
155+
expect(await page.textContent('.virtual-has-import')).toMatch('[success]')
156+
})
157+
154158
test('plugin resolved custom virtual file', async () => {
155159
expect(await page.textContent('.custom-virtual')).toMatch('[success]')
156160
})

playground/resolve/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ <h2>Plugin resolved virtual file</h2>
152152
<h2>Plugin resolved virtual file (#9036)</h2>
153153
<p class="virtual-9036"></p>
154154

155+
<h2>Plugin resolved virtual file that has import</h2>
156+
<p class="virtual-has-import"></p>
157+
155158
<h2>Plugin resolved custom virtual file</h2>
156159
<p class="custom-virtual"></p>
157160

@@ -388,6 +391,9 @@ <h2>utf8-bom-package</h2>
388391
import { msg as virtualMsg9036 } from 'virtual:file-9036.js'
389392
text('.virtual-9036', virtualMsg9036)
390393

394+
import { msg as virtualMsgHasImport } from 'virtual:file-has-import.js'
395+
text('.virtual-has-import', virtualMsgHasImport)
396+
391397
import { msg as customVirtualMsg } from '@custom-virtual-file'
392398
text('.custom-virtual', customVirtualMsg)
393399

playground/resolve/vite.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const virtualId = '\0' + virtualFile
88
const virtualFile9036 = 'virtual:file-9036.js'
99
const virtualId9036 = '\0' + virtualFile9036
1010

11+
const virtualFileHasImport = 'virtual:file-has-import.js'
12+
const virtualIdHasImport = '/file-has-import.js'
13+
1114
const customVirtualFile = '@custom-virtual-file'
1215

1316
const virtualFileWithScheme = 'virtual-with-scheme'
@@ -67,6 +70,30 @@ export default defineConfig({
6770
}
6871
},
6972
},
73+
{
74+
name: 'virtual-module-has-import',
75+
enforce: 'pre',
76+
resolveId(id, _importer, opts) {
77+
if (id === virtualFileHasImport) {
78+
// make scanner happy
79+
// @ts-expect-error -- opts.scan is internal
80+
if (opts?.scan) {
81+
return normalizePath(
82+
path.resolve(import.meta.dirname, './exports-path/main.js'),
83+
)
84+
}
85+
return virtualIdHasImport
86+
}
87+
},
88+
load(id) {
89+
if (id === virtualIdHasImport) {
90+
return (
91+
'import { msg as importedMsg } from "@vitejs/test-resolve-exports-path"\n' +
92+
'export const msg = importedMsg.includes("[success]") ? "[success] from virtual file that has import" : "[failure]"'
93+
)
94+
}
95+
},
96+
},
7097
{
7198
name: 'custom-resolve',
7299
resolveId(id) {

0 commit comments

Comments
 (0)