Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
Add test to compile typescript-yoga template
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky committed Nov 9, 2018
1 parent ae86882 commit 11865a6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/graphqlgen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"jest": "23.6.0",
"ts-jest": "23.10.4",
"ts-node": "7.0.1",
"tslint": "5.11.0"
"tslint": "5.11.0",
"typescript": "^3.1.6"
}
}
55 changes: 55 additions & 0 deletions packages/graphqlgen/src/tests/typescript-yoga/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as ts from 'typescript'
import * as glob from 'glob'
import { execSync } from 'child_process'
import { join } from 'path'

const relative = (p: string) => join(__dirname, p)

function printErrors(diagnotics: ReadonlyArray<ts.Diagnostic>) {
diagnotics.forEach(diagnostic => {
if (diagnostic.file) {
let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(
diagnostic.start!,
)
let message = ts.flattenDiagnosticMessageText(
diagnostic.messageText,
'\n',
)
console.log(
`${diagnostic.file.fileName} (${line + 1},${character +
1}): ${message}`,
)
} else {
console.log(
`${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}`,
)
}
})
}

test('compile typescript-yoga', async () => {
const typescriptYogaRootDir = relative(
'../../../../graphqlgen-templates/typescript-yoga',
)

const fileNames = glob.sync(join(typescriptYogaRootDir, './src/**/*.ts'))

process.chdir(typescriptYogaRootDir)
execSync('yarn install && yarn generate')

const errors = ts
.createProgram(fileNames, {
skipLibCheck: true,
sourceMap: false,
noEmitOnError: true,
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.CommonJS,
})
.emit().diagnostics

if (errors.length > 0) {
printErrors(errors)
}

expect(errors.length).toEqual(0)
})

0 comments on commit 11865a6

Please sign in to comment.