Skip to content

Commit 3584551

Browse files
committed
test: add test for #523
1 parent 69c482b commit 3584551

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

playground/resolve/__tests__/resolve.spec.ts

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

164+
test('plugin resolved virtual file that has import', async () => {
165+
expect(await page.textContent('.virtual-has-import')).toMatch('[success]')
166+
})
167+
164168
test('plugin resolved custom virtual file', async () => {
165169
expect(await page.textContent('.custom-virtual')).toMatch('[success]')
166170
})

playground/resolve/index.html

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

161+
<h2>Plugin resolved virtual file that has import</h2>
162+
<p class="virtual-has-import"></p>
163+
161164
<h2>Plugin resolved custom virtual file</h2>
162165
<p class="custom-virtual"></p>
163166

@@ -402,6 +405,9 @@ <h2>utf8-bom-package</h2>
402405
import { msg as virtualMsg9036 } from 'virtual:file-9036.js'
403406
text('.virtual-9036', virtualMsg9036)
404407

408+
import { msg as virtualMsgHasImport } from 'virtual:file-has-import.js'
409+
text('.virtual-has-import', virtualMsgHasImport)
410+
405411
import { msg as customVirtualMsg } from '@custom-virtual-file'
406412
text('.custom-virtual', customVirtualMsg)
407413

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)