Tests: Require specific modules instead of the whole library

Requiring the whole library was a relict from the time where the tests
were exercising the browser build when run in the browser.
redux
David Majda 8 years ago
parent 9f36131637
commit 6817f3b964

@ -2,15 +2,13 @@
let chai = require("chai");
let helpers = require("./helpers");
let peg = require("../../../../lib/peg");
let pass = require("../../../../lib/compiler/passes/generate-bytecode");
chai.use(helpers);
let expect = chai.expect;
describe("compiler pass |generateBytecode|", function() {
let pass = peg.compiler.passes.generate.generateBytecode;
function bytecodeDetails(bytecode) {
return {
rules: [{ bytecode: bytecode }]

@ -1,6 +1,6 @@
"use strict";
let peg = require("../../../../lib/peg");
let parser = require("../../../../lib/parser");
module.exports = function(chai, utils) {
let Assertion = chai.Assertion;
@ -44,7 +44,7 @@ module.exports = function(chai, utils) {
}
}
let ast = peg.parser.parse(grammar);
let ast = parser.parse(grammar);
utils.flag(this, "object")(ast, options);
@ -58,7 +58,7 @@ module.exports = function(chai, utils) {
});
Assertion.addMethod("reportError", function(grammar, props) {
let ast = peg.parser.parse(grammar);
let ast = parser.parse(grammar);
let passed, result;

@ -2,15 +2,13 @@
let chai = require("chai");
let helpers = require("./helpers");
let peg = require("../../../../lib/peg");
let pass = require("../../../../lib/compiler/passes/remove-proxy-rules");
chai.use(helpers);
let expect = chai.expect;
describe("compiler pass |removeProxyRules|", function() {
let pass = peg.compiler.passes.transform.removeProxyRules;
describe("when a proxy rule isn't listed in |allowedStartRules|", function() {
it("updates references and removes it", function() {
expect(pass).to.changeAST(

@ -2,15 +2,13 @@
let chai = require("chai");
let helpers = require("./helpers");
let peg = require("../../../../lib/peg");
let pass = require("../../../../lib/compiler/passes/report-duplicate-labels");
chai.use(helpers);
let expect = chai.expect;
describe("compiler pass |reportDuplicateLabels|", function() {
let pass = peg.compiler.passes.check.reportDuplicateLabels;
describe("in a sequence", function() {
it("reports labels duplicate with labels of preceding elements", function() {
expect(pass).to.reportError("start = a:'a' a:'a'", {

@ -2,15 +2,13 @@
let chai = require("chai");
let helpers = require("./helpers");
let peg = require("../../../../lib/peg");
let pass = require("../../../../lib/compiler/passes/report-duplicate-rules");
chai.use(helpers);
let expect = chai.expect;
describe("compiler pass |reportDuplicateRules|", function() {
let pass = peg.compiler.passes.check.reportDuplicateRules;
it("reports duplicate rules", function() {
expect(pass).to.reportError([
"start = 'a'",

@ -2,15 +2,13 @@
let chai = require("chai");
let helpers = require("./helpers");
let peg = require("../../../../lib/peg");
let pass = require("../../../../lib/compiler/passes/report-infinite-recursion");
chai.use(helpers);
let expect = chai.expect;
describe("compiler pass |reportInfiniteRecursion|", function() {
let pass = peg.compiler.passes.check.reportInfiniteRecursion;
it("reports direct left recursion", function() {
expect(pass).to.reportError("start = start", {
message: "Possible infinite loop when parsing (left recursion: start -> start).",

@ -2,15 +2,13 @@
let chai = require("chai");
let helpers = require("./helpers");
let peg = require("../../../../lib/peg");
let pass = require("../../../../lib/compiler/passes/report-infinite-repetition");
chai.use(helpers);
let expect = chai.expect;
describe("compiler pass |reportInfiniteRepetition|", function() {
let pass = peg.compiler.passes.check.reportInfiniteRepetition;
it("reports infinite loops for zero_or_more", function() {
expect(pass).to.reportError("start = ('')*", {
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",

@ -2,15 +2,13 @@
let chai = require("chai");
let helpers = require("./helpers");
let peg = require("../../../../lib/peg");
let pass = require("../../../../lib/compiler/passes/report-undefined-rules");
chai.use(helpers);
let expect = chai.expect;
describe("compiler pass |reportUndefinedRules|", function() {
let pass = peg.compiler.passes.check.reportUndefinedRules;
it("reports undefined rules", function() {
expect(pass).to.reportError("start = undefined", {
message: "Rule \"undefined\" is not defined.",

@ -1,7 +1,7 @@
"use strict";
let chai = require("chai");
let peg = require("../../lib/peg");
let parser = require("../../lib/parser");
let expect = chai.expect;
@ -170,7 +170,7 @@ describe("PEG.js grammar parser", function() {
let Assertion = chai.Assertion;
Assertion.addMethod("parseAs", function(expected) {
let result = peg.parser.parse(utils.flag(this, "object"));
let result = parser.parse(utils.flag(this, "object"));
stripLocation(result);
@ -188,7 +188,7 @@ describe("PEG.js grammar parser", function() {
let passed, result;
try {
result = peg.parser.parse(utils.flag(this, "object"));
result = parser.parse(utils.flag(this, "object"));
passed = true;
} catch (e) {
result = e;

Loading…
Cancel
Save