Skip to content

Commit

Permalink
chore: add example-6
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 20, 2024
1 parent f7a9abd commit e67e635
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
37 changes: 37 additions & 0 deletions fixtures/input/example-6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { DtsGenerationOption } from '../../src/types'
import type { BunPlugin } from 'bun'
import process from 'node:process'
import { generate } from '../../src/index'

export function dts(options?: DtsGenerationOption): BunPlugin {
return {
name: 'bun-plugin-dtsx',

async setup(build) {
const cwd = options?.cwd ?? process.cwd()
const root = options?.root ?? build.config.root
const entrypoints = options?.entrypoints ?? build.config.entrypoints
const outdir = options?.outdir ?? build.config.outdir
const keepComments = options?.keepComments ?? true
const clean = options?.clean ?? false
const tsconfigPath = options?.tsconfigPath ?? './tsconfig.json'

await generate({
...options,
cwd,
root,
entrypoints,
outdir,
keepComments,
clean,
tsconfigPath,
})
},
}
}

export { generate }

export type { DtsGenerationOption }

export default dts
10 changes: 10 additions & 0 deletions fixtures/output/example-6.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { DtsGenerationOption } from '../../src/types'
import type { BunPlugin } from 'bun'

export function dts(options?: DtsGenerationOption): BunPlugin

export function generate(options: DtsGenerationOption): Promise<void>

export { DtsGenerationOption }

export default dts
21 changes: 21 additions & 0 deletions test/dts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ describe('dts-generation', () => {
expect(generatedContent).toBe(expectedContent)
})

it('should properly generate types for example-6', async () => {
const example = 'example-6'

const config: DtsGenerationOption = {
entrypoints: [join(inputDir, `${example}.ts`)],
outdir: generatedDir,
clean: false,
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
}

await generate(config)

const outputPath = join(outputDir, `${example}.d.ts`)
const generatedPath = join(generatedDir, `${example}.d.ts`)

const expectedContent = await Bun.file(outputPath).text()
const generatedContent = await Bun.file(generatedPath).text()

expect(generatedContent).toBe(expectedContent)

Check failure on line 136 in test/dts.test.ts

View workflow job for this annotation

GitHub Actions / test

error: expect(received).toBe(expected)

Expected: "import type { DtsGenerationOption } from '../../src/types'\nimport type { BunPlugin } from 'bun'\n\nexport function dts(options?: DtsGenerationOption): BunPlugin\n\nexport function generate(options: DtsGenerationOption): Promise<void>\n\nexport { DtsGenerationOption }\n\nexport default dts\n" Received: "import type { DtsGenerationOption } from '../../src/types'\nimport type { BunPlugin } from 'bun'\n\nexport declare function dts(options?: DtsGenerationOption): BunPlugin\n\nexport default dts\n" at /home/runner/work/dtsx/dtsx/test/dts.test.ts:136:30
})

afterEach(async () => {
// Clean up generated files
try {
Expand Down

0 comments on commit e67e635

Please sign in to comment.