@@ -18,6 +18,16 @@ function prettyPrint(grammar) {
1818 return grammar . rules . map ( g => g . toString ( ) )
1919}
2020
21+ function typeScriptCheck ( isStrict ) {
22+ const { outPath, stdout, stderr} = externalNearleyc ( "grammars/typescript-test.ne" , ".ts" ) ;
23+ expect ( stderr ) . toBe ( "" ) ;
24+ expect ( stdout ) . toBe ( "" ) ;
25+ const spawnSync = sh ( `tsc ${ isStrict ? "--strict" : "" } ${ outPath } .ts` ) ;
26+ expect ( spawnSync . stdout ) . toBe ( "" ) ; // type errors get logged to stdout, not stderr
27+ const grammar = nearley . Grammar . fromCompiled ( require ( `./${ outPath } .js` ) . default ) ;
28+ expect ( parse ( grammar , "<123>" ) ) . toEqual ( [ [ '<' , '123' , '>' ] ] ) ;
29+ }
30+
2131
2232describe ( "bin/nearleyc" , function ( ) {
2333 after ( cleanup )
@@ -61,12 +71,12 @@ describe("bin/nearleyc", function() {
6171
6272 it ( 'builds for TypeScript' , function ( ) {
6373 this . timeout ( 10000 ) ; // It takes a while to run tsc!
64- const { outPath , stdout , stderr } = externalNearleyc ( "grammars/typescript-test.ne" , ".ts" ) ;
65- expect ( stderr ) . toBe ( "" ) ;
66- expect ( stdout ) . toBe ( "" ) ;
67- sh ( `tsc ${ outPath } .ts` ) ;
68- const grammar = nearley . Grammar . fromCompiled ( require ( `./ ${ outPath } .js` ) . default ) ;
69- expect ( parse ( grammar , "<123>" ) ) . toEqual ( [ [ '<' , '123' , '>' ] ] ) ;
74+ typeScriptCheck ( false ) ;
75+ } ) ;
76+
77+ it ( 'builds for TypeScript with `--strict` with no type errors' , function ( ) {
78+ this . timeout ( 10000 ) ;
79+ typeScriptCheck ( true ) ;
7080 } ) ;
7181
7282 it ( 'builds modules in folders' , function ( ) {
0 commit comments