Add test for related source files

This commit is contained in:
Jerko Steiner 2019-08-14 16:03:18 +07:00
parent b122ff093a
commit 385555123a
2 changed files with 31 additions and 11 deletions

View File

@ -14,15 +14,20 @@ describe('intergen', () => {
let i = 0
function createSourceFile(contents: string) {
i++
const sourceFile = path.join(tmpdir, templateName + i + '.ts')
fs.writeFileSync(sourceFile, contents)
sourceFiles.push(sourceFile)
return sourceFile
const module = templateName + i
const fullPath = path.join(tmpdir, module + '.ts')
fs.writeFileSync(fullPath, contents)
sourceFiles.push(fullPath)
return {fullPath, module}
}
function start(input: string) {
return intergen('intergen', '-i', input)
}
function execute(source: string): string {
const file = createSourceFile(source)
return intergen('intergen', '-i', file)
const {fullPath} = createSourceFile(source)
return start(fullPath)
}
afterEach(() => {
@ -157,4 +162,24 @@ export interface A {
}`)
})
it('generates interfaces from related source files', () => {
const {module: f1} = createSourceFile(`export class A {
a: number
}`)
const {module: f2} = createSourceFile(`import {A} from './${f1}'
export class B {
a: A
}`)
const {fullPath} =
createSourceFile(`export * from './${f2}'`)
const result = start(fullPath)
expect(result).toEqual(`export interface A {
a: number
}
export interface B {
a: A
}`)
})
})

View File

@ -314,11 +314,6 @@ export function intergen(...argv: string[]): string {
* Visit nodes finding exported classes
*/
function visit(node: ts.Node) {
console.log(node.getText(),
isNodeExported(node),
ts.getCombinedModifierFlags(node as any),
!!node.parent,
node.parent.kind === ts.SyntaxKind.SourceFile)
// Only consider exported nodes
if (!isNodeExported(node)) {
return