Skip to content

Commit 8cd057d

Browse files
authored
test: add tests of dts: false and dts.distPath (#65)
1 parent 140f955 commit 8cd057d

File tree

8 files changed

+149
-15
lines changed

8 files changed

+149
-15
lines changed

e2e/cases/dts/__snapshots__/index.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`dts when bundle: false 1`] = `
3+
exports[`dts when bundle: false > basic - bundleless dts 1`] = `
44
{
55
"./dist/esm/index.d.ts": "export * from './utils/numbers';
66
export * from './utils/strings';
@@ -20,7 +20,7 @@ export declare const str3 = "str3";
2020
}
2121
`;
2222

23-
exports[`dts when bundle: true 1`] = `
23+
exports[`dts when bundle: true > basic - bundle dts 1`] = `
2424
{
2525
"esm": "export declare const num1 = 1;
2626
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig(__dirname, {
7+
bundle: false,
8+
dts: {
9+
bundle: false,
10+
distPath: './dist/custom',
11+
},
12+
}),
13+
generateBundleCjsConfig(__dirname, {
14+
bundle: false,
15+
}),
16+
],
17+
source: {
18+
entry: {
19+
main: ['./src/**'],
20+
},
21+
},
22+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig(__dirname, {
7+
bundle: false,
8+
dts: false,
9+
}),
10+
generateBundleCjsConfig(__dirname, {
11+
bundle: false,
12+
}),
13+
],
14+
source: {
15+
entry: {
16+
main: ['./src/**'],
17+
},
18+
},
19+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig(__dirname, {
7+
dts: {
8+
bundle: true,
9+
distPath: './dist/custom',
10+
},
11+
}),
12+
generateBundleCjsConfig(__dirname),
13+
],
14+
source: {
15+
entry: {
16+
main: './src/index.ts',
17+
},
18+
},
19+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig(__dirname, {
7+
dts: false,
8+
}),
9+
generateBundleCjsConfig(__dirname),
10+
],
11+
source: {
12+
entry: {
13+
main: './src/index.ts',
14+
},
15+
},
16+
});

e2e/cases/dts/index.test.ts

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,76 @@
11
import { join } from 'node:path';
22
import { buildAndGetResults } from '@e2e/helper';
3-
import { expect, test } from 'vitest';
3+
import { describe, expect, test } from 'vitest';
44

5-
test('dts when bundle: false', async () => {
6-
const fixturePath = join(__dirname, 'bundle-false');
7-
const { files, contents } = await buildAndGetResults(fixturePath, 'dts');
5+
describe('dts when bundle: false', () => {
6+
test('basic - bundleless dts', async () => {
7+
const fixturePath = join(__dirname, 'bundle-false');
8+
const { files, contents } = await buildAndGetResults(
9+
fixturePath,
10+
'rslib.config.ts',
11+
'dts',
12+
);
813

9-
expect(files.esm?.length).toBe(4);
10-
expect(files.esm?.[0]!.endsWith('.d.ts')).toEqual(true);
11-
expect(contents.esm).toMatchSnapshot();
14+
expect(files.esm?.length).toBe(4);
15+
expect(files.esm?.[0]!.endsWith('.d.ts')).toEqual(true);
16+
expect(contents.esm).toMatchSnapshot();
17+
});
18+
19+
test('dts false - bundleless dts', async () => {
20+
const fixturePath = join(__dirname, 'bundle-false');
21+
const { files } = await buildAndGetResults(
22+
fixturePath,
23+
'rslib.false.config.ts',
24+
'dts',
25+
);
26+
27+
expect(files.esm).toBe(undefined);
28+
});
29+
30+
test('distPath - bundleless dts', async () => {
31+
const fixturePath = join(__dirname, 'bundle-false');
32+
const { files } = await buildAndGetResults(
33+
fixturePath,
34+
'rslib.distpath.config.ts',
35+
'dts',
36+
);
37+
expect(files.esm?.length).toBe(4);
38+
expect(files.esm?.[0]!.startsWith('./dist/custom')).toEqual(true);
39+
});
1240
});
1341

14-
test('dts when bundle: true', async () => {
15-
const fixturePath = join(__dirname, 'bundle');
16-
const { entryFiles, entries } = await buildAndGetResults(fixturePath, 'dts');
42+
describe('dts when bundle: true', () => {
43+
test('basic - bundle dts', async () => {
44+
const fixturePath = join(__dirname, 'bundle');
45+
const { entryFiles, entries } = await buildAndGetResults(
46+
fixturePath,
47+
'rslib.config.ts',
48+
'dts',
49+
);
50+
51+
expect(entryFiles.esm!.endsWith('index.d.ts')).toEqual(true);
52+
expect(entries).toMatchSnapshot();
53+
});
54+
55+
test('dts false - bundle dts', async () => {
56+
const fixturePath = join(__dirname, 'bundle');
57+
const { entryFiles } = await buildAndGetResults(
58+
fixturePath,
59+
'rslib.false.config.ts',
60+
'dts',
61+
);
62+
63+
expect(entryFiles.esm).toEqual(undefined);
64+
});
65+
66+
test('distPath - bundle dts', async () => {
67+
const fixturePath = join(__dirname, 'bundle');
68+
const { entryFiles } = await buildAndGetResults(
69+
fixturePath,
70+
'rslib.distpath.config.ts',
71+
'dts',
72+
);
1773

18-
expect(entryFiles.esm!.endsWith('index.d.ts')).toEqual(true);
19-
expect(entries).toMatchSnapshot();
74+
expect(entryFiles.esm!.startsWith('./dist/custom')).toEqual(true);
75+
});
2076
});

e2e/scripts/shared.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export async function getResults(
104104

105105
export const buildAndGetResults = async (
106106
fixturePath: string,
107+
configFile = 'rslib.config.ts',
107108
type: 'js' | 'dts' = 'js',
108109
): Promise<{
109110
contents: Record<string, Record<string, string>>;
@@ -113,7 +114,7 @@ export const buildAndGetResults = async (
113114
rspackConfig: InspectConfigResult['origin']['bundlerConfigs'];
114115
rsbuildConfig: InspectConfigResult['origin']['rsbuildConfig'];
115116
}> => {
116-
const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts'));
117+
const rslibConfig = await loadConfig(join(fixturePath, configFile));
117118
process.chdir(fixturePath);
118119
const rsbuildInstance = await build(rslibConfig);
119120
const {

scripts/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ craco
2222
crossorigin
2323
datauri
2424
deepmerge
25+
distpath
2526
docgen
2627
dogfooding
2728
envinfo

0 commit comments

Comments
 (0)