From 385555123a9c435aa4639f4a37c54df36a511336 Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Wed, 14 Aug 2019 16:03:18 +0700 Subject: [PATCH] Add test for related source files --- .../scripts/src/commands/intergen.test.ts | 37 ++++++++++++++++--- packages/scripts/src/commands/intergen.ts | 5 --- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/packages/scripts/src/commands/intergen.test.ts b/packages/scripts/src/commands/intergen.test.ts index db158fe..f9d1dd8 100644 --- a/packages/scripts/src/commands/intergen.test.ts +++ b/packages/scripts/src/commands/intergen.test.ts @@ -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 +}`) + }) + }) diff --git a/packages/scripts/src/commands/intergen.ts b/packages/scripts/src/commands/intergen.ts index 5c6014d..6d68001 100644 --- a/packages/scripts/src/commands/intergen.ts +++ b/packages/scripts/src/commands/intergen.ts @@ -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