Add test for related source files
This commit is contained in:
parent
b122ff093a
commit
385555123a
@ -14,15 +14,20 @@ describe('intergen', () => {
|
|||||||
let i = 0
|
let i = 0
|
||||||
function createSourceFile(contents: string) {
|
function createSourceFile(contents: string) {
|
||||||
i++
|
i++
|
||||||
const sourceFile = path.join(tmpdir, templateName + i + '.ts')
|
const module = templateName + i
|
||||||
fs.writeFileSync(sourceFile, contents)
|
const fullPath = path.join(tmpdir, module + '.ts')
|
||||||
sourceFiles.push(sourceFile)
|
fs.writeFileSync(fullPath, contents)
|
||||||
return sourceFile
|
sourceFiles.push(fullPath)
|
||||||
|
return {fullPath, module}
|
||||||
|
}
|
||||||
|
|
||||||
|
function start(input: string) {
|
||||||
|
return intergen('intergen', '-i', input)
|
||||||
}
|
}
|
||||||
|
|
||||||
function execute(source: string): string {
|
function execute(source: string): string {
|
||||||
const file = createSourceFile(source)
|
const {fullPath} = createSourceFile(source)
|
||||||
return intergen('intergen', '-i', file)
|
return start(fullPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEach(() => {
|
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
|
||||||
|
}`)
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@ -314,11 +314,6 @@ export function intergen(...argv: string[]): string {
|
|||||||
* Visit nodes finding exported classes
|
* Visit nodes finding exported classes
|
||||||
*/
|
*/
|
||||||
function visit(node: ts.Node) {
|
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
|
// Only consider exported nodes
|
||||||
if (!isNodeExported(node)) {
|
if (!isNodeExported(node)) {
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user