Skip to content

Commit

Permalink
Merge pull request #204 from Mingun/coverage
Browse files Browse the repository at this point in the history
Small fixes and enable coverage output in the console
  • Loading branch information
hildjj authored Oct 25, 2021
2 parents 6b39853 + cf43e26 commit 13a56f5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 6 deletions.
7 changes: 6 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

module.exports = {
"collectCoverage": true,
"coverageReporters": ["lcov"],
"coverageReporters": ["lcov", "text"],
"coveragePathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/lib/parser.js",
"<rootDir>/test",
],
"roots": [
"<rootDir>/test",
],
Expand Down
2 changes: 2 additions & 0 deletions lib/compiler/asts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down
3 changes: 3 additions & 0 deletions lib/compiler/passes/generate-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ")");
}
}
Expand Down Expand Up @@ -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] + ".");
}
Expand Down Expand Up @@ -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);",
" }",
Expand Down
1 change: 1 addition & 0 deletions lib/grammar-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/cli/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/compiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 13a56f5

Please sign in to comment.