Skip to content

Commit

Permalink
typescript --strict check
Browse files Browse the repository at this point in the history
  • Loading branch information
bandaloo committed Nov 29, 2020
1 parent 0313b2c commit 751cf45
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions test/nearleyc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 751cf45

Please sign in to comment.