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.redux
parent
d239bf0107
commit
5c40fff136
@ -1,5 +1,6 @@
|
||||
{
|
||||
"env": {
|
||||
"commonjs": true,
|
||||
"jasmine": true
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
/* global require */
|
||||
|
||||
"use strict";
|
||||
|
||||
(function(root) {
|
||||
if (typeof module !== 'undefined') {
|
||||
root.peg = require("../lib/peg.js");
|
||||
}
|
||||
}(this));
|
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/* eslint-env node */
|
||||
/* eslint no-console: 0 */
|
||||
|
||||
/*
|
||||
* Small server whose main purpose is to ensure that both the specced code and
|
||||
* the specs get passed through Babel & Browserify before they are served to the
|
||||
* browser.
|
||||
*/
|
||||
|
||||
var express = require("express"),
|
||||
logger = require("morgan"),
|
||||
glob = require("glob"),
|
||||
browserify = require("browserify"),
|
||||
babelify = require("babelify");
|
||||
|
||||
var app = express();
|
||||
|
||||
app.use(logger("dev"));
|
||||
app.use(express.static(__dirname));
|
||||
|
||||
app.get("/bundle.js", function(req, res) {
|
||||
var files = glob.sync(__dirname + "/**/*.js", {
|
||||
ignore: __dirname + "/vendor/**/*"
|
||||
});
|
||||
|
||||
browserify(files)
|
||||
.transform(babelify, { presets: "es2015", compact: false })
|
||||
.bundle()
|
||||
.pipe(res);
|
||||
});
|
||||
|
||||
app.listen(8000, function() {
|
||||
console.log("Spec server running at http://localhost:8000...");
|
||||
});
|
||||
|
Loading…
Reference in New Issue