11import { join } from 'node:path' ;
22import { buildAndGetResults } from '@e2e/helper' ;
3- import { expect , test } from 'vitest' ;
3+ import { describe , expect , test } from 'vitest' ;
44
55test ( 'shims for __dirname and __filename in ESM' , async ( ) => {
66 const fixturePath = join ( __dirname , 'esm' ) ;
@@ -16,15 +16,29 @@ test('shims for __dirname and __filename in ESM', async () => {
1616 }
1717} ) ;
1818
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() {
2425 return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
2526}();` ,
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+ } ) ;
3044} ) ;
0 commit comments