Skip to content

Commit

Permalink
test(module-tools): adjust dts test and add case for declarationMap (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
10Derozan authored Dec 4, 2023
1 parent 5d2f474 commit 5d09f4a
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 193 deletions.
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export default defineConfig({
buildType: 'bundle',
dts: {
distPath: './types',
only: true,
respectExternal: false,
},
outDir: './dist/bundle-dist-path',
outDir: './dist/bundle',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export default defineConfig({
buildType: 'bundleless',
dts: {
distPath: './types',
only: true,
},
outDir: './dist/bundleless-dist-path',
outDir: './dist/bundleless',
},
});
131 changes: 27 additions & 104 deletions tests/integration/module/fixtures/build/dts/dts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,156 +16,79 @@ afterAll(() => {
const fixtureDir = __dirname;
const enableDts = true;

describe('dts is false', () => {
describe('dts build', () => {
it('buildType is bundle', async () => {
const configFile = path.join(fixtureDir, './false-bundle.ts');
const { success } = await runCli({
const configFile = path.join(fixtureDir, './dts-bundle.ts');
await runCli({
argv: ['build'],
configFile,
appDirectory: fixtureDir,
enableDts,
});
expect(success).toBeTruthy();
// dts.distPath
const distDtsFilePath = path.join(
fixtureDir,
'./dist/false-bundle/index.d.ts',
'./dist/bundle/types/index.d.ts',
);
expect(await fs.pathExists(distDtsFilePath)).toBeFalsy();
const distJsFilePath = path.join(fixtureDir, './dist/bundle/index.js');
// dts.only
expect(fs.existsSync(distJsFilePath)).toBeFalsy();
const content = await fs.readFile(distDtsFilePath, 'utf8');
// dts.respectExternal
expect(content.includes('export { Ref } from')).toBeTruthy();
});

it('buildType is bundleless', async () => {
const configFile = path.join(fixtureDir, './false-bundleless.ts');
const { success } = await runCli({
const configFile = path.join(fixtureDir, './dts-bundleless.ts');
await runCli({
argv: ['build'],
configFile,
appDirectory: fixtureDir,
enableDts,
});
expect(success).toBeTruthy();
const distDtsFilePath = path.join(
const distMapPath = path.join(
fixtureDir,
'./dist/false-bundleless/index.d.ts',
'./dist/bundleless/types/index.d.ts.map',
);
expect(await fs.pathExists(distDtsFilePath)).toBeFalsy();
const content = JSON.parse(await fs.readFile(distMapPath, 'utf8'));
// source map
expect(
path.resolve(path.dirname(distMapPath), content.sources[0]) ===
path.resolve(fixtureDir, 'src/index.ts'),
).toBeTruthy();
});
});

describe('dts.distPath', () => {
it('buildType is bundle', async () => {
const configFile = path.join(fixtureDir, './distPath-bundle.ts');
const { success } = await runCli({
argv: ['build'],
configFile,
appDirectory: fixtureDir,
enableDts,
});
expect(success).toBeTruthy();
const distDtsFilePath = path.join(
fixtureDir,
'./dist/bundle-dist-path/types/index.d.ts',
);
expect(await fs.pathExists(distDtsFilePath)).toBeTruthy();
});

it('buildType is bundleless', async () => {
const configFile = path.join(fixtureDir, './distPath-bundleless.ts');
const { success } = await runCli({
argv: ['build'],
configFile,
appDirectory: fixtureDir,
enableDts,
});
expect(success).toBeTruthy();

let distDtsFilePath = path.join(
fixtureDir,
'./dist/bundleless-dist-path/types/index.d.ts',
);
expect(await fs.pathExists(distDtsFilePath)).toBeTruthy();
distDtsFilePath = path.join(
fixtureDir,
'./dist/bundleless-dist-path/types/b.d.ts',
);
expect(await fs.pathExists(distDtsFilePath)).toBeTruthy();
});
});

describe('dts.tsconfigPath', () => {
describe('dts is false', () => {
it('buildType is bundle', async () => {
const configFile = path.join(fixtureDir, './tsconfigPath-bundle.ts');
const configFile = path.join(fixtureDir, './false-bundle.ts');
const { success } = await runCli({
argv: ['build'],
configFile,
appDirectory: fixtureDir,
enableDts,
});

expect(success).toBeTruthy();
const distDtsFilePath = path.join(
fixtureDir,
'./dist/tsconfig-path/bundle/index.d.ts',
);
expect(await fs.pathExists(distDtsFilePath)).toBeTruthy();
});

it('buildType is bundleless', async () => {
const configFile = path.join(fixtureDir, './tsconfigPath-bundleless.ts');
const { success } = await runCli({
argv: ['build'],
configFile,
appDirectory: fixtureDir,
enableDts,
});
expect(success).toBeTruthy();
let distDtsFilePath = path.join(
fixtureDir,
'./dist/tsconfig-path/bundleless/index.d.ts',
);
expect(await fs.pathExists(distDtsFilePath)).toBeTruthy();

distDtsFilePath = path.join(
fixtureDir,
'./dist/tsconfig-path/bundleless/b.d.ts',
);
expect(await fs.pathExists(distDtsFilePath)).toBeTruthy();
});
});

describe('dts.only is true', () => {
it('buildType is bundle', async () => {
const configFile = path.join(fixtureDir, './only-bundle.ts');
const { success } = await runCli({
argv: ['build'],
configFile,
appDirectory: fixtureDir,
enableDts,
});
expect(success).toBeTruthy();
let distDtsFilePath = path.join(
fixtureDir,
'./dist/only-bundle/index.d.ts',
'./dist/false-bundle/index.d.ts',
);
expect(await fs.pathExists(distDtsFilePath)).toBeTruthy();
distDtsFilePath = path.join(fixtureDir, './dist/only-bundle/index.js');
expect(await fs.pathExists(distDtsFilePath)).toBeFalsy();
});

it('buildType is bundleless', async () => {
const configFile = path.join(fixtureDir, './only-bundleless.ts');
const configFile = path.join(fixtureDir, './false-bundleless.ts');
const { success } = await runCli({
argv: ['build'],
configFile,
appDirectory: fixtureDir,
enableDts,
});
expect(success).toBeTruthy();
let distDtsFilePath = path.join(
const distDtsFilePath = path.join(
fixtureDir,
'./dist/only-bundleless/index.d.ts',
'./dist/false-bundleless/index.d.ts',
);
expect(await fs.pathExists(distDtsFilePath)).toBeTruthy();

distDtsFilePath = path.join(fixtureDir, './dist/only-bundleless/index.js');
expect(await fs.pathExists(distDtsFilePath)).toBeFalsy();
});
});
Expand Down
11 changes: 0 additions & 11 deletions tests/integration/module/fixtures/build/dts/only-bundle.ts

This file was deleted.

11 changes: 0 additions & 11 deletions tests/integration/module/fixtures/build/dts/only-bundleless.ts

This file was deleted.

5 changes: 4 additions & 1 deletion tests/integration/module/fixtures/build/dts/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"name": "dts-test",
"version": "1.0.0"
"version": "1.0.0",
"devDependencies": {
"react": "^18.2.0"
}
}
1 change: 1 addition & 0 deletions tests/integration/module/fixtures/build/dts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { b } from '@src/b';

console.info(b);

export type { Ref } from 'react';
export type { A } from './b';
2 changes: 0 additions & 2 deletions tests/integration/module/fixtures/build/dts/src1/b.ts

This file was deleted.

5 changes: 0 additions & 5 deletions tests/integration/module/fixtures/build/dts/src1/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions tests/integration/module/fixtures/build/dts/src2/b.ts

This file was deleted.

5 changes: 0 additions & 5 deletions tests/integration/module/fixtures/build/dts/src2/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions tests/integration/module/fixtures/build/dts/tsconfig-bundle.json

This file was deleted.

This file was deleted.

4 changes: 3 additions & 1 deletion tests/integration/module/fixtures/build/dts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"baseUrl": "./",
"paths": {
"@src/*": ["./src/*"]
}
},
"declaration": true,
"declarationMap": true
},
"include": ["src"]
}
15 changes: 0 additions & 15 deletions tests/integration/module/fixtures/build/dts/tsconfigPath-bundle.ts

This file was deleted.

This file was deleted.

0 comments on commit 5d09f4a

Please sign in to comment.