diff --git a/package.json b/package.json index eeae4ea..db4dd2b 100644 --- a/package.json +++ b/package.json @@ -47,8 +47,10 @@ "precoverage": "npm run test", "coverage": "nyc report --reporter=text-lcov | coveralls", "pretest": "npm run lint", - "test": "nyc --reporter=lcov --reporter=text-summary npm run test:mocha", + "test": "nyc --reporter=lcov --reporter=text-summary npm run test:mocha:all", "test:mocha": "mocha --reporter dot", + "test:mocha:legacy": "NO_SET=1 mocha --reporter dot", + "test:mocha:all": "npm run test:mocha && npm run test:mocha:legacy", "test:watch": "mocha --reporter min --watch", "test:chrome": "karma start" } diff --git a/test/core/seq.test.js b/test/core/seq.test.js index 921233c..719bdc9 100644 --- a/test/core/seq.test.js +++ b/test/core/seq.test.js @@ -1,56 +1,43 @@ "use strict"; -testSetUsage(function setUsage(api) { - it(api.setTestDescription("Parsimmon.seq"), function() { - var parser = Parsimmon.seq( - Parsimmon.string("("), - Parsimmon.regexp(/[^)]/) - .many() - .map(function(xs) { - return xs.join(""); - }), - Parsimmon.string(")") - ); +it("Parsimmon.seq", function() { + var parser = Parsimmon.seq( + Parsimmon.string("("), + Parsimmon.regexp(/[^)]/) + .many() + .map(function(xs) { + return xs.join(""); + }), + Parsimmon.string(")") + ); - assert.deepEqual( - api.scopeSet(function scopeSet() { - return parser.parse("(string between parens)"); - }).value, - ["(", "string between parens", ")"] - ); + assert.deepEqual(parser.parse("(string between parens)").value, [ + "(", + "string between parens", + ")" + ]); - assert.deepEqual( - api.scopeSet(function scopeSet() { - return parser.parse("(string"); - }), - { - status: false, - index: { - offset: 7, - line: 1, - column: 8 - }, - expected: ["')'", "/[^)]/"] - } - ); + assert.deepEqual(parser.parse("(string"), { + status: false, + index: { + offset: 7, + line: 1, + column: 8 + }, + expected: ["')'", "/[^)]/"] + }); - assert.deepEqual( - api.scopeSet(function scopeSet() { - return parser.parse("starts wrong (string between parens)"); - }), - { - status: false, - index: { - offset: 0, - line: 1, - column: 1 - }, - expected: ["'('"] - } - ); + assert.deepEqual(parser.parse("starts wrong (string between parens)"), { + status: false, + index: { + offset: 0, + line: 1, + column: 1 + }, + expected: ["'('"] + }); - assert.throws(function() { - Parsimmon.seq("not a parser"); - }); + assert.throws(function() { + Parsimmon.seq("not a parser"); }); }); diff --git a/test/setup.js b/test/setup.js index aa9fbfc..ff8fe4b 100644 --- a/test/setup.js +++ b/test/setup.js @@ -17,6 +17,12 @@ delete Object.prototype.__magic__; })(); +if (typeof process !== "undefined") { + if (process.env.NO_SET) { + delete globalThis.Set; + } +} + // Karma loads these for us if (typeof require !== "undefined") { globalThis.assert = require("chai").assert; @@ -28,32 +34,3 @@ globalThis.equivalentParsers = function equivalentParsers(p1, p2, inputs) { assert.deepEqual(p1.parse(inputs[i]), p2.parse(inputs[i])); } }; - -// In order to test a scenario where "Set" is not available, we need -// to scope out a execution without Set only for code under test. The -// chai libraries will error if Set doesnt exist when assertions run. -globalThis.testSetUsage = function testSetUsage(innerFn) { - var origSet = globalThis.Set; - var setAvailableScenarios = [true, false]; - for (var i = 0; i < setAvailableScenarios.length; i++) { - var api = { - setTestDescription: function setTestDescription(desc) { - if (!setAvailableScenarios[i]) { - return desc + " (no Set)"; - } - return desc; - }, - scopeSet: function scopeSet(fn) { - if (!setAvailableScenarios[i]) { - delete globalThis.Set; - } - var result = fn(); - if (!setAvailableScenarios[i]) { - globalThis.Set = origSet; - } - return result; - } - }; - innerFn(api); - } -};