Skip to content

Commit 35d193f

Browse files
committed
chore: wip
1 parent b3f3882 commit 35d193f

1 file changed

Lines changed: 29 additions & 18 deletions

File tree

test/dts.test.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
1-
import { afterEach, beforeAll, describe, expect, it } from 'bun:test'
1+
import { describe, it, expect } from 'bun:test'
22
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'
46

57
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')
911

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+
}
1220

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

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

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'))
2131

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()
2535

26-
afterEach(() => {
27-
// Clean up any files or state if necessary
36+
// Compare the contents
37+
expect(generatedContent.trim()).toBe(expectedContent.trim())
38+
}
2839
})
2940
})

0 commit comments

Comments
 (0)