This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to compile typescript-yoga template
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/graphqlgen/src/tests/typescript-yoga/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |