Skip to content

Commit da8191a

Browse files
authored
test: multiple entries now do not affect each other (#485)
1 parent 7c34973 commit da8191a

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

tests/integration/entry/index.test.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { join } from 'node:path';
2-
import { buildAndGetResults } from 'test-helper';
2+
import { buildAndGetResults, queryContent } from 'test-helper';
33
import { expect, test } from 'vitest';
44

55
test('single entry bundle', async () => {
@@ -20,20 +20,55 @@ test('single entry bundle', async () => {
2020

2121
test('multiple entry bundle', async () => {
2222
const fixturePath = join(__dirname, 'multiple');
23-
const { files } = await buildAndGetResults({ fixturePath });
23+
const { files, contents } = await buildAndGetResults({ fixturePath });
2424

2525
expect(files).toMatchInlineSnapshot(`
2626
{
2727
"cjs": [
2828
"<ROOT>/tests/integration/entry/multiple/dist/cjs/bar.cjs",
29+
"<ROOT>/tests/integration/entry/multiple/dist/cjs/foo.cjs",
2930
"<ROOT>/tests/integration/entry/multiple/dist/cjs/index.cjs",
31+
"<ROOT>/tests/integration/entry/multiple/dist/cjs/shared.cjs",
3032
],
3133
"esm": [
3234
"<ROOT>/tests/integration/entry/multiple/dist/esm/bar.js",
35+
"<ROOT>/tests/integration/entry/multiple/dist/esm/foo.js",
3336
"<ROOT>/tests/integration/entry/multiple/dist/esm/index.js",
37+
"<ROOT>/tests/integration/entry/multiple/dist/esm/shared.js",
3438
],
3539
}
3640
`);
41+
42+
const index = queryContent(contents.esm, 'index.js', { basename: true });
43+
expect(index).toMatchInlineSnapshot(`
44+
"const shared = 'shared';
45+
const foo = 'foo' + shared;
46+
const src_rslib_entry_text = ()=>\`hello \${foo} \${shared}\`;
47+
export { src_rslib_entry_text as text };
48+
"
49+
`);
50+
51+
const foo = queryContent(contents.esm, 'foo.js', { basename: true });
52+
expect(foo).toMatchInlineSnapshot(`
53+
"const shared = 'shared';
54+
const foo = 'foo' + shared;
55+
export { foo };
56+
"
57+
`);
58+
59+
const bar = queryContent(contents.esm, 'bar.js', { basename: true });
60+
expect(bar).toMatchInlineSnapshot(`
61+
"const bar = 'bar';
62+
export { bar };
63+
"
64+
`);
65+
66+
const shared = queryContent(contents.esm, 'shared.js', { basename: true });
67+
expect(shared).toMatchInlineSnapshot(`
68+
"const shared = 'shared';
69+
export { shared };
70+
"
71+
`);
3772
});
3873

3974
test('glob entry bundleless', async () => {

tests/integration/entry/multiple/rslib.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ export default defineConfig({
55
lib: [generateBundleEsmConfig(), generateBundleCjsConfig()],
66
source: {
77
entry: {
8-
index: ['./src/index.ts'],
9-
bar: ['./src/bar.ts'],
8+
index: './src/index.ts',
9+
foo: './src/foo.ts',
10+
bar: './src/bar.ts',
11+
shared: './src/shared.ts',
1012
},
1113
},
1214
});
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const foo = 'foo';
1+
import { shared } from './shared';
2+
3+
export const foo = 'foo' + shared;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { foo } from './foo';
2+
import { shared } from './shared';
23

3-
export const text = () => `hello ${foo}`;
4+
export const text = () => `hello ${foo} ${shared}`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const shared = 'shared';

tests/scripts/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export async function getResults(
166166
if (fileSet.length === 1) {
167167
entryFile = fileSet[0];
168168
} else {
169+
// TODO: Do not support multiple entry files yet.
169170
entryFile = fileSet.find((file) => file.includes('index'));
170171
mfExposeFile = fileSet.find((file) => file.includes('expose'));
171172
}

0 commit comments

Comments
 (0)