diff --git a/tests/integration/redirect/__fixtures__/src/bar/index.ts b/tests/integration/redirect/__fixtures__/src/bar/index.ts deleted file mode 100644 index 0b87c7fd0..000000000 --- a/tests/integration/redirect/__fixtures__/src/bar/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { value } from '../constant'; - -export const bar = 'bar' + value; diff --git a/tests/integration/redirect/__fixtures__/src/constant.ts b/tests/integration/redirect/__fixtures__/src/constant.ts deleted file mode 100644 index efeee5db1..000000000 --- a/tests/integration/redirect/__fixtures__/src/constant.ts +++ /dev/null @@ -1 +0,0 @@ -export const value = 1; diff --git a/tests/integration/redirect/__fixtures__/src/foo.ts b/tests/integration/redirect/__fixtures__/src/foo.ts deleted file mode 100644 index 3329a7d97..000000000 --- a/tests/integration/redirect/__fixtures__/src/foo.ts +++ /dev/null @@ -1 +0,0 @@ -export const foo = 'foo'; diff --git a/tests/integration/redirect/__fixtures__/src/index.ts b/tests/integration/redirect/__fixtures__/src/index.ts deleted file mode 100644 index e892487c7..000000000 --- a/tests/integration/redirect/__fixtures__/src/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import lodash from 'lodash'; - -import { bar as bar2 } from '@/bar'; -import { foo as foo2 } from '@/foo'; -import { bar } from './bar'; -import { foo } from './foo.ts'; - -export default function (): string { - return lodash.toUpper(foo + bar + foo2 + bar2); -} diff --git a/tests/integration/redirect/js/index.test.ts b/tests/integration/redirect/js.test.ts similarity index 79% rename from tests/integration/redirect/js/index.test.ts rename to tests/integration/redirect/js.test.ts index 8d4868ad3..beadceda3 100644 --- a/tests/integration/redirect/js/index.test.ts +++ b/tests/integration/redirect/js.test.ts @@ -1,18 +1,24 @@ +import path from 'node:path'; import { buildAndGetResults, queryContent } from 'test-helper'; import { beforeAll, expect, test } from 'vitest'; let contents: Awaited>['contents']; beforeAll(async () => { - const fixturePath = __dirname; + const fixturePath = path.resolve(__dirname, './js'); contents = (await buildAndGetResults({ fixturePath })).contents; }); test('redirect.js default', async () => { - const { content: indexContent, path: indexPath } = queryContent( + const { content: indexContent, path: indexEsmPath } = queryContent( contents.esm0!, /esm\/index\.js/, ); + const { path: indexCjsPath } = await queryContent( + contents.cjs0!, + /cjs\/index\.cjs/, + ); + expect(indexContent).toMatchInlineSnapshot(` "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js"; @@ -22,9 +28,11 @@ test('redirect.js default', async () => { " `); - expect((await import(indexPath)).default).toMatchInlineSnapshot( - `"FOOBAR1FOOBAR1"`, - ); + const esmResult = await import(indexEsmPath); + const cjsResult = await import(indexCjsPath); + + expect(esmResult.default).toEqual(cjsResult.default); + expect(esmResult.default).toMatchInlineSnapshot(`"FOOBAR1FOOBAR1"`); }); test('redirect.js.path false', async () => { @@ -32,6 +40,7 @@ test('redirect.js.path false', async () => { contents.esm1!, /esm\/index\.js/, ); + expect(indexContent).toMatchInlineSnapshot(` "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "@/bar.js"; @@ -45,10 +54,15 @@ test('redirect.js.path false', async () => { }); test('redirect.js.path with user override externals', async () => { - const { content: indexContent, path: indexPath } = queryContent( + const { content: indexContent, path: indexEsmPath } = queryContent( contents.esm2!, /esm\/index\.js/, ); + const { path: indexCjsPath } = await queryContent( + contents.cjs2!, + /cjs\/index\.cjs/, + ); + expect(indexContent).toMatchInlineSnapshot(` "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; 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 () => { " `); - expect((await import(indexPath)).default).toMatchInlineSnapshot( - `"FOOBAR1OTHERFOOOTHERBAR2"`, // cspell:disable-line - ); + const esmResult = await import(indexEsmPath); + const cjsResult = await import(indexCjsPath); + + expect(esmResult.default).toEqual(cjsResult.default); + expect(esmResult.default).toMatchInlineSnapshot(`"FOOBAR1OTHERFOOOTHERBAR2"`); // cspell:disable-line }); test('redirect.js.extension: false', async () => { diff --git a/tests/integration/redirect/js/rslib.config.ts b/tests/integration/redirect/js/rslib.config.ts index 35fbcb09f..ab17005d1 100644 --- a/tests/integration/redirect/js/rslib.config.ts +++ b/tests/integration/redirect/js/rslib.config.ts @@ -67,8 +67,8 @@ export default defineConfig({ root: 'dist/js-path-externals-override/cjs', }, externals: { - '@/foo': './src/others/foo', - '@/bar': './src/others/bar', + '@/foo': './others/foo.cjs', + '@/bar': './others/bar/index.cjs', }, }, }), diff --git a/tests/integration/redirect/js/src/index.ts b/tests/integration/redirect/js/src/index.ts index fc6813abc..72d073a11 100644 --- a/tests/integration/redirect/js/src/index.ts +++ b/tests/integration/redirect/js/src/index.ts @@ -3,6 +3,6 @@ import lodash from 'lodash'; import { bar as bar2 } from '@/bar'; import { foo as foo2 } from '@/foo'; import { bar } from './bar'; -import { foo } from './foo.ts'; +import { foo } from './foo'; export default lodash.toUpper(foo + bar + foo2 + bar2);