From 11865a61dcc26363cb18a3c0ff12fa6b3c0ea748 Mon Sep 17 00:00:00 2001 From: Flavian DESVERNE Date: Fri, 9 Nov 2018 19:12:04 +0100 Subject: [PATCH] Add test to compile typescript-yoga template --- packages/graphqlgen/package.json | 3 +- .../src/tests/typescript-yoga/index.test.ts | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 packages/graphqlgen/src/tests/typescript-yoga/index.test.ts diff --git a/packages/graphqlgen/package.json b/packages/graphqlgen/package.json index ea6496ab..3cc62315 100644 --- a/packages/graphqlgen/package.json +++ b/packages/graphqlgen/package.json @@ -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" } } diff --git a/packages/graphqlgen/src/tests/typescript-yoga/index.test.ts b/packages/graphqlgen/src/tests/typescript-yoga/index.test.ts new file mode 100644 index 00000000..95832d37 --- /dev/null +++ b/packages/graphqlgen/src/tests/typescript-yoga/index.test.ts @@ -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) { + 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) +})