-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
73 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import path from 'path' | ||
import { generate } from '../src' | ||
|
||
console.log('Generating output...', path.join(__dirname, '..')) | ||
|
||
generate({ | ||
cwd: path.join(__dirname, '..'), | ||
root: path.join(__dirname, '..', 'src'), | ||
outdir: path.join(__dirname, '..', 'dist'), | ||
clean: true, | ||
tsconfigPath: path.join(__dirname, '..', 'tsconfig.json'), | ||
}) | ||
|
||
console.log('Generated') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,59 @@ | ||
import { describe, it, expect } from 'bun:test' | ||
import { describe, it, expect, afterEach } from 'bun:test' | ||
import { join } from 'node:path' | ||
import { readdir } from 'node:fs/promises' | ||
import { generate } from '../src/generate' | ||
import type { DtsGenerationConfig } from '../src/types' | ||
import type { DtsGenerationOption } from '../src/types' | ||
import { rm } from 'node:fs/promises' | ||
|
||
describe('dts-generation', () => { | ||
const cwdDir = join(__dirname, '..') | ||
const inputDir = join(cwdDir, 'fixtures/input') | ||
const outputDir = join(cwdDir, 'fixtures/output') | ||
|
||
const config: DtsGenerationConfig = { | ||
cwd: cwdDir, | ||
root: inputDir, | ||
outdir: outputDir, | ||
keepComments: true, | ||
clean: false, | ||
tsconfigPath: join(cwdDir, 'tsconfig.json'), | ||
} | ||
|
||
it('should generate correct type declarations for all input files', async () => { | ||
// Generate the declaration files | ||
const testDir = join(__dirname, '../fixtures') | ||
const inputDir = join(testDir, 'input') | ||
const outputDir = join(testDir, 'output') | ||
const generatedDir = join(testDir, 'generated') | ||
|
||
it('should properly generate types for example-1', async () => { | ||
const config: DtsGenerationOption = { | ||
file: join(__dirname, '..', 'tsconfig.json'), | ||
outdir: generatedDir, | ||
clean: true, | ||
tsconfigPath: join(__dirname, '..', 'tsconfig.json'), | ||
} | ||
|
||
await generate(config) | ||
|
||
// Get all input files | ||
const inputFiles = await readdir(inputDir) | ||
const example = 'example-1' | ||
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() | ||
|
||
for (const file of inputFiles) { | ||
const outputPath = join(outputDir, file.replace('.ts', '.d.ts')) | ||
const generatedPath = join(outputDir, file.replace('.ts', '.d.ts')) | ||
expect(generatedContent).toBe(expectedContent) | ||
|
||
// Read expected and generated content | ||
const expectedContent = await Bun.file(outputPath).text() | ||
const generatedContent = await Bun.file(generatedPath).text() | ||
}) | ||
|
||
it('should properly generate types for example-2', async () => { | ||
await testExample('example-2') | ||
Check failure on line 35 in test/dts.test.ts GitHub Actions / testReferenceError: Can't find variable: testExample
|
||
}) | ||
|
||
it('should properly generate types for example-3', async () => { | ||
await testExample('example-3') | ||
Check failure on line 39 in test/dts.test.ts GitHub Actions / testReferenceError: Can't find variable: testExample
|
||
}) | ||
|
||
it('should properly generate types for example-4', async () => { | ||
await testExample('example-4') | ||
Check failure on line 43 in test/dts.test.ts GitHub Actions / testReferenceError: Can't find variable: testExample
|
||
}) | ||
|
||
it('should properly generate types for example-5', async () => { | ||
await testExample('example-5') | ||
Check failure on line 47 in test/dts.test.ts GitHub Actions / testReferenceError: Can't find variable: testExample
|
||
}) | ||
|
||
// Compare the contents | ||
expect(generatedContent.trim()).toBe(expectedContent.trim()) | ||
afterEach(async () => { | ||
// Clean up generated files | ||
try { | ||
await rm(generatedDir, { recursive: true, force: true }) | ||
console.log('Cleaned up generated files') | ||
} catch (error) { | ||
console.error('Error cleaning up generated files:', error) | ||
} | ||
}) | ||
}) |