@@ -2,17 +2,17 @@ import '../common/index.mjs';
22import assert from 'assert' ;
33import vfs from 'node:vfs' ;
44
5- // NOTE: Each test uses a different mount path (/virtual, /virtual2, etc.)
6- // because ESM imports are cached by URL - using the same mount path would
7- // return cached modules from previous tests instead of fresh imports .
5+ // NOTE: Each test uses a unique mount path because ESM imports are cached
6+ // by URL — unmounting does not clear the V8 module cache, so reusing a
7+ // mount path would return stale cached modules from earlier tests.
88
99// Test importing a simple virtual ES module
1010{
1111 const myVfs = vfs . create ( ) ;
1212 myVfs . writeFileSync ( '/hello.mjs' , 'export const message = "hello from vfs";' ) ;
13- myVfs . mount ( '/virtual ' ) ;
13+ myVfs . mount ( '/esm-named ' ) ;
1414
15- const { message } = await import ( '/virtual /hello.mjs' ) ;
15+ const { message } = await import ( '/esm-named /hello.mjs' ) ;
1616 assert . strictEqual ( message , 'hello from vfs' ) ;
1717
1818 myVfs . unmount ( ) ;
@@ -22,9 +22,9 @@ import vfs from 'node:vfs';
2222{
2323 const myVfs = vfs . create ( ) ;
2424 myVfs . writeFileSync ( '/default.mjs' , 'export default { name: "test", value: 42 };' ) ;
25- myVfs . mount ( '/virtual2 ' ) ;
25+ myVfs . mount ( '/esm-default ' ) ;
2626
27- const mod = await import ( '/virtual2 /default.mjs' ) ;
27+ const mod = await import ( '/esm-default /default.mjs' ) ;
2828 assert . strictEqual ( mod . default . name , 'test' ) ;
2929 assert . strictEqual ( mod . default . value , 42 ) ;
3030
@@ -36,12 +36,12 @@ import vfs from 'node:vfs';
3636 const myVfs = vfs . create ( ) ;
3737 myVfs . writeFileSync ( '/utils.mjs' , 'export function add(a, b) { return a + b; }' ) ;
3838 myVfs . writeFileSync ( '/main.mjs' , `
39- import { add } from '/virtual3 /utils.mjs';
39+ import { add } from '/esm-chain /utils.mjs';
4040 export const result = add(10, 20);
4141 ` ) ;
42- myVfs . mount ( '/virtual3 ' ) ;
42+ myVfs . mount ( '/esm-chain ' ) ;
4343
44- const { result } = await import ( '/virtual3 /main.mjs' ) ;
44+ const { result } = await import ( '/esm-chain /main.mjs' ) ;
4545 assert . strictEqual ( result , 30 ) ;
4646
4747 myVfs . unmount ( ) ;
@@ -56,9 +56,9 @@ import vfs from 'node:vfs';
5656 import { helper } from './helper.mjs';
5757 export const output = helper();
5858 ` ) ;
59- myVfs . mount ( '/virtual4 ' ) ;
59+ myVfs . mount ( '/esm-relative ' ) ;
6060
61- const { output } = await import ( '/virtual4 /lib/index.mjs' ) ;
61+ const { output } = await import ( '/esm-relative /lib/index.mjs' ) ;
6262 assert . strictEqual ( output , 'helped' ) ;
6363
6464 myVfs . unmount ( ) ;
@@ -68,9 +68,9 @@ import vfs from 'node:vfs';
6868{
6969 const myVfs = vfs . create ( ) ;
7070 myVfs . writeFileSync ( '/data.json' , JSON . stringify ( { items : [ 1 , 2 , 3 ] , enabled : true } ) ) ;
71- myVfs . mount ( '/virtual5 ' ) ;
71+ myVfs . mount ( '/esm-json ' ) ;
7272
73- const data = await import ( '/virtual5 /data.json' , { with : { type : 'json' } } ) ;
73+ const data = await import ( '/esm-json /data.json' , { with : { type : 'json' } } ) ;
7474 assert . deepStrictEqual ( data . default . items , [ 1 , 2 , 3 ] ) ;
7575 assert . strictEqual ( data . default . enabled , true ) ;
7676
@@ -81,7 +81,7 @@ import vfs from 'node:vfs';
8181{
8282 const myVfs = vfs . create ( ) ;
8383 myVfs . writeFileSync ( '/test.mjs' , 'export const x = 1;' ) ;
84- myVfs . mount ( '/virtual6 ' ) ;
84+ myVfs . mount ( '/esm-builtin ' ) ;
8585
8686 // Import from node: should still work
8787 const assertMod = await import ( 'node:assert' ) ;
@@ -95,15 +95,15 @@ import vfs from 'node:vfs';
9595 const myVfs = vfs . create ( ) ;
9696 myVfs . writeFileSync ( '/esm-module.mjs' , 'export const esmValue = "esm";' ) ;
9797 myVfs . writeFileSync ( '/cjs-module.js' , 'module.exports = { cjsValue: "cjs" };' ) ;
98- myVfs . mount ( '/virtual8 ' ) ;
98+ myVfs . mount ( '/esm-mixed ' ) ;
9999
100- const { esmValue } = await import ( '/virtual8 /esm-module.mjs' ) ;
100+ const { esmValue } = await import ( '/esm-mixed /esm-module.mjs' ) ;
101101 assert . strictEqual ( esmValue , 'esm' ) ;
102102
103103 // CJS require should also work (via createRequire)
104104 const { createRequire } = await import ( 'module' ) ;
105105 const require = createRequire ( import . meta. url ) ;
106- const { cjsValue } = require ( '/virtual8 /cjs-module.js' ) ;
106+ const { cjsValue } = require ( '/esm-mixed /cjs-module.js' ) ;
107107 assert . strictEqual ( cjsValue , 'cjs' ) ;
108108
109109 myVfs . unmount ( ) ;
@@ -132,9 +132,9 @@ import vfs from 'node:vfs';
132132 '/app/entry.mjs' ,
133133 "export { fromVfs } from 'my-vfs-pkg';" ,
134134 ) ;
135- myVfs . mount ( '/virtual9 ' ) ;
135+ myVfs . mount ( '/esm-bare ' ) ;
136136
137- const { fromVfs } = await import ( '/virtual9 /app/entry.mjs' ) ;
137+ const { fromVfs } = await import ( '/esm-bare /app/entry.mjs' ) ;
138138 assert . strictEqual ( fromVfs , true ) ;
139139
140140 myVfs . unmount ( ) ;
0 commit comments