From 751cf45b30fa5ac9105f2d63f30501dde9471d43 Mon Sep 17 00:00:00 2001 From: bandaloo Date: Sun, 29 Nov 2020 15:45:21 -0500 Subject: [PATCH] typescript --strict check --- test/nearleyc.test.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/nearleyc.test.js b/test/nearleyc.test.js index 5be62a8b..2c304380 100644 --- a/test/nearleyc.test.js +++ b/test/nearleyc.test.js @@ -18,6 +18,16 @@ function prettyPrint(grammar) { return grammar.rules.map(g => g.toString()) } +function typeScriptCheck(isStrict) { + const {outPath, stdout, stderr} = externalNearleyc("grammars/typescript-test.ne", ".ts"); + expect(stderr).toBe(""); + expect(stdout).toBe(""); + const spawnSync = sh(`tsc ${isStrict ? "--strict" : ""} ${outPath}.ts`); + expect(spawnSync.stdout).toBe(""); // type errors get logged to stdout, not stderr + const grammar = nearley.Grammar.fromCompiled(require(`./${outPath}.js`).default); + expect(parse(grammar, "<123>")).toEqual([ [ '<', '123', '>' ] ]); +} + describe("bin/nearleyc", function() { after(cleanup) @@ -61,12 +71,12 @@ describe("bin/nearleyc", function() { it('builds for TypeScript', function() { this.timeout(10000); // It takes a while to run tsc! - const {outPath, stdout, stderr} = externalNearleyc("grammars/typescript-test.ne", ".ts"); - expect(stderr).toBe(""); - expect(stdout).toBe(""); - sh(`tsc ${outPath}.ts`); - const grammar = nearley.Grammar.fromCompiled(require(`./${outPath}.js`).default); - expect(parse(grammar, "<123>")).toEqual([ [ '<', '123', '>' ] ]); + typeScriptCheck(false); + }); + + it('builds for TypeScript with `--strict` with no type errors', function() { + this.timeout(10000); + typeScriptCheck(true); }); it('builds modules in folders', function() {