From 5c40fff136ef9225a51685711ed884cfffeb2e4d Mon Sep 17 00:00:00 2001 From: David Majda Date: Thu, 8 Sep 2016 13:29:06 +0200 Subject: [PATCH] Pass spec code through Babel before serving it to the browser This will allow to use ES2015 constructs in spec code. The change required introducing a small server, which serves both PEG.js and spec code passed through Babel and bundled together. This allowed to convert the specs to regular modules and get rid of the hackery that was previously needed to make them run both in Node.js and in the browser. Note the specs no longer exercise the browser version. This will allow to spec PEG.js internals in the future. See #442. --- Makefile | 3 ++ spec/.eslintrc.json | 1 + spec/README.md | 14 ++----- spec/api/generated-parser-api.spec.js | 4 +- spec/api/pegjs-api.spec.js | 4 +- spec/api/plugin-api.spec.js | 4 +- .../generated-parser-behavior.spec.js | 4 +- spec/helpers.js | 9 ----- spec/index.html | 16 +------- spec/server | 37 +++++++++++++++++++ .../compiler/passes/generate-bytecode.spec.js | 4 +- spec/unit/compiler/passes/helpers.js | 4 +- .../passes/remove-proxy-rules.spec.js | 4 +- .../passes/report-duplicate-labels.spec.js | 4 +- .../passes/report-duplicate-rules.spec.js | 4 +- .../passes/report-infinite-recursion.spec.js | 4 +- .../passes/report-infinite-repetition.spec.js | 4 +- .../passes/report-undefined-rules.spec.js | 4 +- spec/unit/parser.spec.js | 4 +- 19 files changed, 74 insertions(+), 58 deletions(-) delete mode 100644 spec/helpers.js create mode 100755 spec/server diff --git a/Makefile b/Makefile index 9c8d89b..6f9840a 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,8 @@ PARSER_OUT_FILE_NEW = $(LIB_DIR)/parser.js.new BROWSER_FILE_DEV = $(BROWSER_DIR)/peg-$(PEGJS_VERSION).js BROWSER_FILE_MIN = $(BROWSER_DIR)/peg-$(PEGJS_VERSION).min.js +SPEC_SERVER_FILE = $(SPEC_DIR)/server + VERSION_FILE = VERSION # ===== Executables ===== @@ -103,6 +105,7 @@ lint: $(ESLINT) \ `find $(LIB_DIR) -name '*.js'` \ `find $(SPEC_DIR) -name '*.js' -and -not -path '$(SPEC_DIR)/vendor/*'` \ + $(SPEC_SERVER_FILE) \ $(BENCHMARK_DIR)/*.js \ $(BENCHMARK_RUN) \ $(PEGJS) diff --git a/spec/.eslintrc.json b/spec/.eslintrc.json index 52939e2..a3dc8e0 100644 --- a/spec/.eslintrc.json +++ b/spec/.eslintrc.json @@ -1,5 +1,6 @@ { "env": { + "commonjs": true, "jasmine": true } } diff --git a/spec/README.md b/spec/README.md index fc1376a..71c8cd9 100644 --- a/spec/README.md +++ b/spec/README.md @@ -38,18 +38,12 @@ All commands in the following steps need to be executed in PEG.js root directory $ npm install ``` - 3. Build browser version of PEG.js: + 3. Serve the spec suite using a web server: ```console - $ make browser + $ spec/server ``` - 4. Serve PEG.js root directory using a web server: + 4. Point your browser to the [spec suite](http://localhost:8000/). - ```console - $ node_modules/.bin/http-server - ``` - - 5. Point your browser to the [spec suite](http://localhost:8080/spec/index.html). - - 6. Watch the specs pass (or fail). + 5. Watch the specs pass (or fail). diff --git a/spec/api/generated-parser-api.spec.js b/spec/api/generated-parser-api.spec.js index 3231d93..3ff1dcf 100644 --- a/spec/api/generated-parser-api.spec.js +++ b/spec/api/generated-parser-api.spec.js @@ -1,8 +1,10 @@ /* eslint no-console: 0 */ -/* global peg, console */ +/* global console */ "use strict"; +var peg = require("../../lib/peg"); + describe("generated parser API", function() { describe("parse", function() { it("parses input", function() { diff --git a/spec/api/pegjs-api.spec.js b/spec/api/pegjs-api.spec.js index 5448f12..9d02c66 100644 --- a/spec/api/pegjs-api.spec.js +++ b/spec/api/pegjs-api.spec.js @@ -1,7 +1,7 @@ -/* global peg */ - "use strict"; +var peg = require("../../lib/peg"); + describe("PEG.js API", function() { describe("generate", function() { it("generates a parser", function() { diff --git a/spec/api/plugin-api.spec.js b/spec/api/plugin-api.spec.js index 73eb7f8..d89356f 100644 --- a/spec/api/plugin-api.spec.js +++ b/spec/api/plugin-api.spec.js @@ -1,7 +1,7 @@ -/* global peg */ - "use strict"; +var peg = require("../../lib/peg"); + describe("plugin API", function() { beforeEach(function() { this.addMatchers({ diff --git a/spec/behavior/generated-parser-behavior.spec.js b/spec/behavior/generated-parser-behavior.spec.js index 8a0107b..2824569 100644 --- a/spec/behavior/generated-parser-behavior.spec.js +++ b/spec/behavior/generated-parser-behavior.spec.js @@ -1,8 +1,10 @@ /* eslint no-console: 0 */ -/* global peg, console */ +/* global console */ "use strict"; +var peg = require("../../lib/peg"); + describe("generated parser behavior", function() { function varyOptimizationOptions(block) { function clone(object) { diff --git a/spec/helpers.js b/spec/helpers.js deleted file mode 100644 index 3e60a00..0000000 --- a/spec/helpers.js +++ /dev/null @@ -1,9 +0,0 @@ -/* global require */ - -"use strict"; - -(function(root) { - if (typeof module !== 'undefined') { - root.peg = require("../lib/peg.js"); - } -}(this)); diff --git a/spec/index.html b/spec/index.html index 2ab1a45..a0734bd 100644 --- a/spec/index.html +++ b/spec/index.html @@ -6,21 +6,7 @@ - - - - - - - - - - - - - - - +