1+ import path from 'node:path' ;
12import { buildAndGetResults , queryContent } from 'test-helper' ;
23import { beforeAll , expect , test } from 'vitest' ;
34
45let contents : Awaited < ReturnType < typeof buildAndGetResults > > [ 'contents' ] ;
56
67beforeAll ( async ( ) => {
7- const fixturePath = __dirname ;
8+ const fixturePath = path . resolve ( __dirname , './js' ) ;
89 contents = ( await buildAndGetResults ( { fixturePath } ) ) . contents ;
910} ) ;
1011
1112test ( 'redirect.js default' , async ( ) => {
12- const { content : indexContent , path : indexPath } = queryContent (
13+ const { content : indexContent , path : indexEsmPath } = queryContent (
1314 contents . esm0 ! ,
1415 / e s m \/ i n d e x \. j s / ,
1516 ) ;
17+ const { path : indexCjsPath } = await queryContent (
18+ contents . cjs0 ! ,
19+ / c j s \/ i n d e x \. c j s / ,
20+ ) ;
21+
1622 expect ( indexContent ) . toMatchInlineSnapshot ( `
1723 "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
1824 import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js";
@@ -22,16 +28,19 @@ test('redirect.js default', async () => {
2228 "
2329 ` ) ;
2430
25- expect ( ( await import ( indexPath ) ) . default ) . toMatchInlineSnapshot (
26- `"FOOBAR1FOOBAR1"` ,
27- ) ;
31+ const esmResult = await import ( indexEsmPath ) ;
32+ const cjsResult = await import ( indexCjsPath ) ;
33+
34+ expect ( esmResult . default ) . toEqual ( cjsResult . default ) ;
35+ expect ( esmResult . default ) . toMatchInlineSnapshot ( `"FOOBAR1FOOBAR1"` ) ;
2836} ) ;
2937
3038test ( 'redirect.js.path false' , async ( ) => {
3139 const { content : indexContent } = queryContent (
3240 contents . esm1 ! ,
3341 / e s m \/ i n d e x \. j s / ,
3442 ) ;
43+
3544 expect ( indexContent ) . toMatchInlineSnapshot ( `
3645 "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
3746 import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "@/bar.js";
@@ -45,10 +54,15 @@ test('redirect.js.path false', async () => {
4554} ) ;
4655
4756test ( 'redirect.js.path with user override externals' , async ( ) => {
48- const { content : indexContent , path : indexPath } = queryContent (
57+ const { content : indexContent , path : indexEsmPath } = queryContent (
4958 contents . esm2 ! ,
5059 / e s m \/ i n d e x \. j s / ,
5160 ) ;
61+ const { path : indexCjsPath } = await queryContent (
62+ contents . cjs2 ! ,
63+ / c j s \/ i n d e x \. c j s / ,
64+ ) ;
65+
5266 expect ( indexContent ) . toMatchInlineSnapshot ( `
5367 "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
5468 import * as __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__ from "./others/bar/index.js";
@@ -60,9 +74,11 @@ test('redirect.js.path with user override externals', async () => {
6074 "
6175 ` ) ;
6276
63- expect ( ( await import ( indexPath ) ) . default ) . toMatchInlineSnapshot (
64- `"FOOBAR1OTHERFOOOTHERBAR2"` , // cspell:disable-line
65- ) ;
77+ const esmResult = await import ( indexEsmPath ) ;
78+ const cjsResult = await import ( indexCjsPath ) ;
79+
80+ expect ( esmResult . default ) . toEqual ( cjsResult . default ) ;
81+ expect ( esmResult . default ) . toMatchInlineSnapshot ( `"FOOBAR1OTHERFOOOTHERBAR2"` ) ; // cspell:disable-line
6682} ) ;
6783
6884test ( 'redirect.js.extension: false' , async ( ) => {
0 commit comments