diff --git a/test/dts.test.ts b/test/dts.test.ts index 174a44388..e3914fbbb 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -258,29 +258,29 @@ test('should emit declaration files with experimentalDts', async () => { export function sharedFunction(value: T): T | null { return value || null } - + type sharedType = { shared: boolean } - + export type { sharedType } `, 'src/server.ts': ` export * from './shared' /** - * Comment for server render function + * Comment for server render function */ export function render(options: ServerRenderOptions): string { return JSON.stringify(options) } - + export interface ServerRenderOptions { /** * Comment for ServerRenderOptions.stream - * + * * @public - * + * * @my_custom_tag */ stream: boolean @@ -298,7 +298,7 @@ test('should emit declaration files with experimentalDts', async () => { import * as ServerThirdPartyNamespace from 'react-dom'; export { ServerThirdPartyNamespace } - // Export a third party module + // Export a third party module export * from 'react-dom/server'; `, @@ -308,7 +308,7 @@ test('should emit declaration files with experimentalDts', async () => { export function render(options: ClientRenderOptions): string { return JSON.stringify(options) } - + export interface ClientRenderOptions { document: boolean } @@ -473,3 +473,119 @@ test('declaration files with multiple entrypoints #316', async () => { 'dist/bar/index.d.ts', ).toMatchSnapshot() }) + +test('custom dts output extension', async ({ expect, task }) => { + const { outFiles } = await run( + getTestName(), + { + 'src/types.ts': `export type Person = { name: string }`, + 'src/index.ts': `export const foo = [1, 2, 3]\nexport type { Person } from './types'`, + 'tsup.config.ts': `export default { + name: '${task.name}', + entry: { index: 'src/index.ts' }, + dts: true, + format: ['esm', 'cjs'], + outExtension({ format }) { + return { + js: format === 'esm' ? '.cjs' : '.mjs', + dts: format === 'esm' ? '.d.cts' : '.d.mts', + } + }, + }`, + 'package.json': JSON.stringify( + { + name: 'custom-dts-output-extension', + description: task.name, + type: 'module', + }, + null, + 2, + ), + 'tsconfig.json': JSON.stringify( + { + compilerOptions: { + outDir: './dist', + rootDir: './src', + moduleResolution: 'Bundler', + module: 'ESNext', + strict: true, + skipLibCheck: true, + }, + include: ['src'], + }, + null, + 2, + ), + }, + { + entry: [], + }, + ) + expect(outFiles).toStrictEqual([ + 'index.cjs', + 'index.d.cts', + 'index.d.mts', + 'index.mjs', + ]) +}) + +test('custom dts output extension with api-extractor', async ({ + expect, + task, +}) => { + const { outFiles } = await run( + getTestName(), + { + 'src/types.ts': `export type Person = { name: string }`, + 'src/index.ts': `export const foo = [1, 2, 3]\nexport type { Person } from './types'`, + 'tsup.config.ts': `export default { + name: '${task.name}', + entry: { index: 'src/index.ts' }, + format: ['esm', 'cjs'], + experimentalDts: true, + outExtension({ format }) { + return { + js: format === 'cjs' ? '.cjs' : '.mjs', + dts: format === 'cjs' ? '.d.cts' : '.d.mts', + } + }, + }`, + 'package.json': JSON.stringify( + { + name: 'custom-dts-output-extension-with-api-extractor', + description: task.name, + type: 'module', + }, + null, + 2, + ), + 'tsconfig.json': JSON.stringify( + { + compilerOptions: { + outDir: './dist', + rootDir: './src', + moduleResolution: 'Bundler', + module: 'ESNext', + strict: true, + skipLibCheck: true, + }, + include: ['src'], + }, + null, + 2, + ), + }, + { + entry: [], + }, + ) + + expect(outFiles).toStrictEqual([ + '_tsup-dts-rollup.d.cts', + '_tsup-dts-rollup.d.mts', + 'index.cjs', + 'index.d.cts', + 'index.d.mts', + 'index.mjs', + ]) +}) diff --git a/test/index.test.ts b/test/index.test.ts index be853785d..3da659eb6 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -663,79 +663,6 @@ test('custom output extension', async () => { `) }) -test('custom dts output extension', async () => { - const { outFiles } = await run( - getTestName(), - { - 'input.ts': `export const foo = [1,2,3]`, - 'tsup.config.ts': `export default { - dts: true, - outExtension({ format }) { - return { - js: format === 'cjs' ? '.cjs' : '.mjs', - dts: format === 'cjs' ? '.d.cts' : '.d.mts' - } - } - }`, - }, - { - entry: ['input.ts'], - flags: ['--format', 'esm,cjs'], - }, - ) - expect(outFiles).toStrictEqual([ - 'input.cjs', - 'input.d.cts', - 'input.d.mts', - 'input.mjs', - ]) -}) - -test('custom dts output extension with api-extractor', async () => { - const { outFiles } = await run( - getTestName(), - { - 'src/index.ts': `export const foo = [1,2,3]`, - 'tsup.config.ts': `export default { - entry: { index: 'src/index.ts' }, - format: ['esm', 'cjs'], - experimentalDts: true, - outExtension({ format }) { - return { - js: format === 'cjs' ? '.cjs' : '.mjs', - dts: format === 'cjs' ? '.d.cts' : '.d.mts' - } - } - }`, - 'package.json': JSON.stringify({ - name: 'some-package', - type: 'module', - }), - 'tsconfig.json': JSON.stringify({ - compilerOptions: { - outDir: './dist', - rootDir: './src', - moduleResolution: 'NodeNext', - module: 'NodeNext', - }, - include: ['src'], - }), - }, - { - entry: [], - }, - ) - - expect(outFiles).toStrictEqual([ - '_tsup-dts-rollup.d.cts', - '_tsup-dts-rollup.d.mts', - 'index.cjs', - 'index.d.cts', - 'index.d.mts', - 'index.mjs', - ]) -}) - test('custom config file', async () => { const { outFiles } = await run( getTestName(),