Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Nov 8, 2024
1 parent 23a98f6 commit ba4db2f
Showing 1 changed file with 189 additions and 0 deletions.
189 changes: 189 additions & 0 deletions test/dts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,195 @@ describe('dts-generation', () => {
expect(generatedContent).toBe(expectedContent)
})

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

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)
})

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

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)
})

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

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)
})

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

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)
})

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

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)
})

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

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)
})

it('should properly generate types for type example/0001', async () => {
const example = '0001'

const config: DtsGenerationOption = {
entrypoints: [join(inputDir, `example/${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)
})

it('should properly generate types for type example/0002', async () => {
const example = '0002'

const config: DtsGenerationOption = {
entrypoints: [join(inputDir, `example/${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)
})

it('should properly generate types for type example/0003', async () => {
const example = '0003'

const config: DtsGenerationOption = {
entrypoints: [join(inputDir, `example/${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)
})

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

0 comments on commit ba4db2f

Please sign in to comment.