|
1 | | -import { afterEach, beforeAll, describe, expect, it } from 'bun:test' |
| 1 | +import { describe, it, expect } from 'bun:test' |
2 | 2 | import { join } from 'node:path' |
3 | | -import { generateDeclarationsFromFiles } from '../src/generate' |
| 3 | +import { readdir } from 'node:fs/promises' |
| 4 | +import { generate } from '../src/generate' |
| 5 | +import type { DtsGenerationConfig } from '../src/types' |
4 | 6 |
|
5 | 7 | describe('dts-generation', () => { |
6 | | - beforeAll(() => { |
7 | | - process.env.APP_ENV = 'test' |
8 | | - }) |
| 8 | + const cwdDir = join(__dirname, '..') |
| 9 | + const inputDir = join(cwdDir, 'fixtures/input') |
| 10 | + const outputDir = join(cwdDir, 'fixtures/output') |
9 | 11 |
|
10 | | - const testDir = join(__dirname, '../fixtures/input/') |
11 | | - const expectedOutputPath = join(__dirname, '../fixtures/output/examples-1-5.d.ts') |
| 12 | + const config: DtsGenerationConfig = { |
| 13 | + cwd: cwdDir, |
| 14 | + root: inputDir, |
| 15 | + outdir: outputDir, |
| 16 | + keepComments: true, |
| 17 | + clean: false, |
| 18 | + tsconfigPath: join(cwdDir, 'tsconfig.json'), |
| 19 | + } |
12 | 20 |
|
13 | | - it('should generate correct type declarations', async () => { |
14 | | - const output = await generateDeclarationsFromFiles(testDir) |
| 21 | + it('should generate correct type declarations for all input files', async () => { |
| 22 | + // Generate the declaration files |
| 23 | + await generate(config) |
15 | 24 |
|
16 | | - // Write the output to a file for comparison (optional) |
17 | | - // await fs.writeFile(expectedOutputPath, output); |
| 25 | + // Get all input files |
| 26 | + const inputFiles = await readdir(inputDir) |
18 | 27 |
|
19 | | - // Expected output (you can adjust this based on your actual expected output) |
20 | | - const expectedOutput = Bun.file(expectedOutputPath).text() |
| 28 | + for (const file of inputFiles) { |
| 29 | + const outputPath = join(outputDir, file.replace('.ts', '.d.ts')) |
| 30 | + const generatedPath = join(outputDir, file.replace('.ts', '.d.ts')) |
21 | 31 |
|
22 | | - // Compare the generated output with the expected output |
23 | | - expect((output)).toBe(await expectedOutput) |
24 | | - }) |
| 32 | + // Read expected and generated content |
| 33 | + const expectedContent = await Bun.file(outputPath).text() |
| 34 | + const generatedContent = await Bun.file(generatedPath).text() |
25 | 35 |
|
26 | | - afterEach(() => { |
27 | | - // Clean up any files or state if necessary |
| 36 | + // Compare the contents |
| 37 | + expect(generatedContent.trim()).toBe(expectedContent.trim()) |
| 38 | + } |
28 | 39 | }) |
29 | 40 | }) |
0 commit comments