From 700c70f1ac28bd129e9a3bcda0e6d7edfa4d8cda Mon Sep 17 00:00:00 2001 From: fi3ework Date: Wed, 27 Nov 2024 15:59:50 +0800 Subject: [PATCH] test: multiple entries now do not affect each other --- tests/integration/entry/index.test.ts | 39 ++++++++++++++++++- .../entry/multiple/rslib.config.ts | 6 ++- tests/integration/entry/multiple/src/foo.ts | 4 +- tests/integration/entry/multiple/src/index.ts | 3 +- .../integration/entry/multiple/src/shared.ts | 1 + tests/scripts/shared.ts | 1 + 6 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 tests/integration/entry/multiple/src/shared.ts diff --git a/tests/integration/entry/index.test.ts b/tests/integration/entry/index.test.ts index 97ccdd1b3..238746e0a 100644 --- a/tests/integration/entry/index.test.ts +++ b/tests/integration/entry/index.test.ts @@ -1,5 +1,5 @@ import { join } from 'node:path'; -import { buildAndGetResults } from 'test-helper'; +import { buildAndGetResults, queryContent } from 'test-helper'; import { expect, test } from 'vitest'; test('single entry bundle', async () => { @@ -20,20 +20,55 @@ test('single entry bundle', async () => { test('multiple entry bundle', async () => { const fixturePath = join(__dirname, 'multiple'); - const { files } = await buildAndGetResults({ fixturePath }); + const { files, contents } = await buildAndGetResults({ fixturePath }); expect(files).toMatchInlineSnapshot(` { "cjs": [ "/tests/integration/entry/multiple/dist/cjs/bar.cjs", + "/tests/integration/entry/multiple/dist/cjs/foo.cjs", "/tests/integration/entry/multiple/dist/cjs/index.cjs", + "/tests/integration/entry/multiple/dist/cjs/shared.cjs", ], "esm": [ "/tests/integration/entry/multiple/dist/esm/bar.js", + "/tests/integration/entry/multiple/dist/esm/foo.js", "/tests/integration/entry/multiple/dist/esm/index.js", + "/tests/integration/entry/multiple/dist/esm/shared.js", ], } `); + + const index = queryContent(contents.esm, 'index.js', { basename: true }); + expect(index).toMatchInlineSnapshot(` + "const shared = 'shared'; + const foo = 'foo' + shared; + const src_rslib_entry_text = ()=>\`hello \${foo} \${shared}\`; + export { src_rslib_entry_text as text }; + " + `); + + const foo = queryContent(contents.esm, 'foo.js', { basename: true }); + expect(foo).toMatchInlineSnapshot(` + "const shared = 'shared'; + const foo = 'foo' + shared; + export { foo }; + " + `); + + const bar = queryContent(contents.esm, 'bar.js', { basename: true }); + expect(bar).toMatchInlineSnapshot(` + "const bar = 'bar'; + export { bar }; + " + `); + + const shared = queryContent(contents.esm, 'shared.js', { basename: true }); + expect(shared).toMatchInlineSnapshot(` + "const shared = 'shared'; + export { shared }; + " + `); }); test('glob entry bundleless', async () => { diff --git a/tests/integration/entry/multiple/rslib.config.ts b/tests/integration/entry/multiple/rslib.config.ts index e6694b52c..db7608bd2 100644 --- a/tests/integration/entry/multiple/rslib.config.ts +++ b/tests/integration/entry/multiple/rslib.config.ts @@ -5,8 +5,10 @@ export default defineConfig({ lib: [generateBundleEsmConfig(), generateBundleCjsConfig()], source: { entry: { - index: ['./src/index.ts'], - bar: ['./src/bar.ts'], + index: './src/index.ts', + foo: './src/foo.ts', + bar: './src/bar.ts', + shared: './src/shared.ts', }, }, }); diff --git a/tests/integration/entry/multiple/src/foo.ts b/tests/integration/entry/multiple/src/foo.ts index 3329a7d97..9e2973263 100644 --- a/tests/integration/entry/multiple/src/foo.ts +++ b/tests/integration/entry/multiple/src/foo.ts @@ -1 +1,3 @@ -export const foo = 'foo'; +import { shared } from './shared'; + +export const foo = 'foo' + shared; diff --git a/tests/integration/entry/multiple/src/index.ts b/tests/integration/entry/multiple/src/index.ts index 3c8dc405f..97cc2ec82 100644 --- a/tests/integration/entry/multiple/src/index.ts +++ b/tests/integration/entry/multiple/src/index.ts @@ -1,3 +1,4 @@ import { foo } from './foo'; +import { shared } from './shared'; -export const text = () => `hello ${foo}`; +export const text = () => `hello ${foo} ${shared}`; diff --git a/tests/integration/entry/multiple/src/shared.ts b/tests/integration/entry/multiple/src/shared.ts new file mode 100644 index 000000000..cd35843de --- /dev/null +++ b/tests/integration/entry/multiple/src/shared.ts @@ -0,0 +1 @@ +export const shared = 'shared'; diff --git a/tests/scripts/shared.ts b/tests/scripts/shared.ts index f61c0cb90..2b3a483a8 100644 --- a/tests/scripts/shared.ts +++ b/tests/scripts/shared.ts @@ -166,6 +166,7 @@ export async function getResults( if (fileSet.length === 1) { entryFile = fileSet[0]; } else { + // TODO: Do not support multiple entry files yet. entryFile = fileSet.find((file) => file.includes('index')); mfExposeFile = fileSet.find((file) => file.includes('expose')); }