Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: multiple entries now do not affect each other #485

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions tests/integration/entry/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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": [
"<ROOT>/tests/integration/entry/multiple/dist/cjs/bar.cjs",
"<ROOT>/tests/integration/entry/multiple/dist/cjs/foo.cjs",
"<ROOT>/tests/integration/entry/multiple/dist/cjs/index.cjs",
"<ROOT>/tests/integration/entry/multiple/dist/cjs/shared.cjs",
],
"esm": [
"<ROOT>/tests/integration/entry/multiple/dist/esm/bar.js",
"<ROOT>/tests/integration/entry/multiple/dist/esm/foo.js",
"<ROOT>/tests/integration/entry/multiple/dist/esm/index.js",
"<ROOT>/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 () => {
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/entry/multiple/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
});
4 changes: 3 additions & 1 deletion tests/integration/entry/multiple/src/foo.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const foo = 'foo';
import { shared } from './shared';

export const foo = 'foo' + shared;
3 changes: 2 additions & 1 deletion tests/integration/entry/multiple/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { foo } from './foo';
import { shared } from './shared';

export const text = () => `hello ${foo}`;
export const text = () => `hello ${foo} ${shared}`;
1 change: 1 addition & 0 deletions tests/integration/entry/multiple/src/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const shared = 'shared';
1 change: 1 addition & 0 deletions tests/scripts/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
Loading