From 21eb2bc26cbcdaff564a5b937236a57b8fc5e4bb Mon Sep 17 00:00:00 2001 From: Mingun Date: Sun, 17 Oct 2021 01:00:19 +0500 Subject: [PATCH 1/5] Remove unnecessary awaits - VS Code complains about that --- test/cli/run.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cli/run.spec.ts b/test/cli/run.spec.ts index b116224c..87e97c7b 100644 --- a/test/cli/run.spec.ts +++ b/test/cli/run.spec.ts @@ -184,12 +184,12 @@ Options: -h, --help display help for command `; - await expect(await exec({ + await expect(exec({ args: ["-h"], - })).toBe(HELP); - await expect(await exec({ + })).resolves.toBe(HELP); + await expect(exec({ args: ["--help"], - })).toBe(HELP); + })).resolves.toBe(HELP); }); it("rejects invalid options", async() => { From d1b52dc4bc7b7d3a89bd3bdb5ef92ff41a7059f0 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 16 Oct 2021 20:24:18 +0500 Subject: [PATCH 2/5] Fix a typo --- test/unit/compiler.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/compiler.spec.js b/test/unit/compiler.spec.js index 2bf29fb9..7b487bdb 100644 --- a/test/unit/compiler.spec.js +++ b/test/unit/compiler.spec.js @@ -21,7 +21,7 @@ describe("Peggy compiler", () => { })).to.throw('Unknown start rule "bar"'); }); - it("checks ouput type", () => { + it("checks output type", () => { const ast = parser.parse("foo='1'"); expect(compiler.compile(ast, compiler.passes, { output: "source", From f80b250ac1362ea084922e85710d1526c27099b0 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 16 Oct 2021 20:25:05 +0500 Subject: [PATCH 3/5] Output coverage data into console --- jest.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 1f57e312..910af74d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,7 +2,7 @@ module.exports = { "collectCoverage": true, - "coverageReporters": ["lcov"], + "coverageReporters": ["lcov", "text"], "roots": [ "/test", ], From 70a2f92282d4436b1ebbea2e117685562dc97864 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 16 Oct 2021 20:51:59 +0500 Subject: [PATCH 4/5] Exclude unreachable lines from a coverage It is difficult to reach them because this are various workarounds for cross-platform work --- lib/compiler/asts.js | 2 ++ lib/compiler/passes/generate-js.js | 3 +++ lib/grammar-error.js | 1 + lib/parser.js | 1 + 4 files changed, 7 insertions(+) diff --git a/lib/compiler/asts.js b/lib/compiler/asts.js index 47753cff..73b0ba6f 100644 --- a/lib/compiler/asts.js +++ b/lib/compiler/asts.js @@ -21,6 +21,8 @@ const asts = { } } + // istanbul ignore next Presence of rules checked using another approach that not involve this function + // Any time when it is called the rules always exist return -1; }, diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index 570eb07f..0cb6ba02 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -134,6 +134,7 @@ function generateJS(ast, options) { + ")"; } case "any": return "peg$anyExpectation()"; + // istanbul ignore next Because we never generate expectation type we cannot reach this branch default: throw new Error("Unknown expectation type (" + JSON.stringify(e) + ")"); } } @@ -525,6 +526,7 @@ function generateJS(ast, options) { ip++; break; + // istanbul ignore next Because we never generate invalid bytecode we cannot reach this branch default: throw new Error("Invalid opcode: " + bc[ip] + "."); } @@ -594,6 +596,7 @@ function generateJS(ast, options) { "", "function peg$SyntaxError(message, expected, found, location) {", " var self = Error.call(this, message);", + " // istanbul ignore next Check is a necessary evil to support older environments", " if (Object.setPrototypeOf) {", " Object.setPrototypeOf(self, peg$SyntaxError.prototype);", " }", diff --git a/lib/grammar-error.js b/lib/grammar-error.js index 06717644..c400d7b6 100644 --- a/lib/grammar-error.js +++ b/lib/grammar-error.js @@ -2,6 +2,7 @@ // See: https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work // This is roughly what typescript generates, it's not called after super(), where it's needed. +// istanbul ignore next This is a special black magic that cannot be covered everywhere const setProtoOf = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function(d, b) { diff --git a/lib/parser.js b/lib/parser.js index 8c46ab7f..99cce8b7 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -30,6 +30,7 @@ function peg$subclass(child, parent) { function peg$SyntaxError(message, expected, found, location) { var self = Error.call(this, message); + // istanbul ignore next Check is a necessary evil to support older environments if (Object.setPrototypeOf) { Object.setPrototypeOf(self, peg$SyntaxError.prototype); } From cf43e26ed7226309afcb835fa8350b594220441c Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 16 Oct 2021 21:30:26 +0500 Subject: [PATCH 5/5] Exclude generated `parser.js` and test helpers from coverage --- jest.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jest.config.js b/jest.config.js index 910af74d..1db05826 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,6 +3,11 @@ module.exports = { "collectCoverage": true, "coverageReporters": ["lcov", "text"], + "coveragePathIgnorePatterns": [ + "/node_modules/", + "/lib/parser.js", + "/test", + ], "roots": [ "/test", ],