Skip to content

Commit 124441d

Browse files
committed
fix vitest
1 parent 16d257e commit 124441d

File tree

7 files changed

+28
-27
lines changed

7 files changed

+28
-27
lines changed

tests/integration/redirect/__fixtures__/src/bar/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/integration/redirect/__fixtures__/src/constant.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/integration/redirect/__fixtures__/src/foo.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/integration/redirect/__fixtures__/src/index.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/integration/redirect/js/index.test.ts renamed to tests/integration/redirect/js.test.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1+
import path from 'node:path';
12
import { buildAndGetResults, queryContent } from 'test-helper';
23
import { beforeAll, expect, test } from 'vitest';
34

45
let contents: Awaited<ReturnType<typeof buildAndGetResults>>['contents'];
56

67
beforeAll(async () => {
7-
const fixturePath = __dirname;
8+
const fixturePath = path.resolve(__dirname, './js');
89
contents = (await buildAndGetResults({ fixturePath })).contents;
910
});
1011

1112
test('redirect.js default', async () => {
12-
const { content: indexContent, path: indexPath } = queryContent(
13+
const { content: indexContent, path: indexEsmPath } = queryContent(
1314
contents.esm0!,
1415
/esm\/index\.js/,
1516
);
17+
const { path: indexCjsPath } = await queryContent(
18+
contents.cjs0!,
19+
/cjs\/index\.cjs/,
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

3038
test('redirect.js.path false', async () => {
3139
const { content: indexContent } = queryContent(
3240
contents.esm1!,
3341
/esm\/index\.js/,
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

4756
test('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
/esm\/index\.js/,
5160
);
61+
const { path: indexCjsPath } = await queryContent(
62+
contents.cjs2!,
63+
/cjs\/index\.cjs/,
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

6884
test('redirect.js.extension: false', async () => {

tests/integration/redirect/js/rslib.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export default defineConfig({
6767
root: 'dist/js-path-externals-override/cjs',
6868
},
6969
externals: {
70-
'@/foo': './src/others/foo',
71-
'@/bar': './src/others/bar',
70+
'@/foo': './others/foo.cjs',
71+
'@/bar': './others/bar/index.cjs',
7272
},
7373
},
7474
}),

tests/integration/redirect/js/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import lodash from 'lodash';
33
import { bar as bar2 } from '@/bar';
44
import { foo as foo2 } from '@/foo';
55
import { bar } from './bar';
6-
import { foo } from './foo.ts';
6+
import { foo } from './foo';
77

88
export default lodash.toUpper(foo + bar + foo2 + bar2);

0 commit comments

Comments
 (0)