1
1
import { join } from 'node:path' ;
2
2
import { buildAndGetResults } from '@e2e/helper' ;
3
- import { expect , test } from 'vitest' ;
3
+ import { describe , expect , test } from 'vitest' ;
4
4
5
5
test ( 'shims for __dirname and __filename in ESM' , async ( ) => {
6
6
const fixturePath = join ( __dirname , 'esm' ) ;
@@ -16,15 +16,29 @@ test('shims for __dirname and __filename in ESM', async () => {
16
16
}
17
17
} ) ;
18
18
19
- test ( 'shims for import.meta.url in CJS' , async ( ) => {
20
- const fixturePath = join ( __dirname , 'cjs' ) ;
21
- const { entries } = await buildAndGetResults ( fixturePath ) ;
22
- for ( const shim of [
23
- `var __rslib_import_meta_url__ = /*#__PURE__*/ function() {
19
+ describe ( 'shims for `import.meta.url` in CJS' , ( ) => {
20
+ test ( 'CJS should apply shims' , async ( ) => {
21
+ const fixturePath = join ( __dirname , 'cjs' ) ;
22
+ const { entries } = await buildAndGetResults ( fixturePath ) ;
23
+ for ( const shim of [
24
+ `var __rslib_import_meta_url__ = /*#__PURE__*/ function() {
24
25
return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
25
26
}();` ,
26
- 'console.log(__rslib_import_meta_url__);' ,
27
- ] ) {
28
- expect ( entries . cjs ) . toContain ( shim ) ;
29
- }
27
+ 'console.log(__rslib_import_meta_url__);' ,
28
+ ] ) {
29
+ expect ( entries . cjs ) . toContain ( shim ) ;
30
+ }
31
+ } ) ;
32
+
33
+ test ( 'ESM should not be affected by CJS shims configuration' , async ( ) => {
34
+ const fixturePath = join ( __dirname , 'cjs' ) ;
35
+ const { entries } = await buildAndGetResults ( fixturePath ) ;
36
+ expect ( entries . esm ) . toMatchInlineSnapshot ( `
37
+ "const foo = ()=>{
38
+ console.log(import.meta.url);
39
+ };
40
+ export { foo };
41
+ "
42
+ ` ) ;
43
+ } ) ;
30
44
} ) ;
0 commit comments