This repository has been archived by the owner on Jan 19, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ae4a37
commit 6827445
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
compiled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const square = n => n * n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use strict"; | ||
|
||
var square = function square(n) { | ||
return n * n; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var http = require("http"); | ||
var serveStatic = require("serve-static"); | ||
var request = require("supertest"); | ||
var assert = require("assert"); | ||
var babelMiddleware = require("./"); | ||
|
||
var serve = serveStatic("cache"); | ||
var babel = babelMiddleware({ | ||
options: { | ||
presets: ["es2015"] | ||
}, | ||
src: "fixtures", | ||
dest: "compiled", | ||
ignore: /node_modules/ | ||
}); | ||
|
||
var server = http.createServer(function(req, res) { | ||
function onError(err) { | ||
res.statusCode = err.status || 500; | ||
res.end(err.message); | ||
return; | ||
} | ||
babel(req, res, function(err) { | ||
if (err) return onError(err); | ||
serve(req, res, function(err) { | ||
if (err) return onError(err); | ||
res.setHeader("Content-Type", "text/javascript"); | ||
res.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("babelMiddleware()", function() { | ||
it("should compile", function(done) { | ||
request(server) | ||
.get("/fixture.js") | ||
.expect(function(res) { | ||
assert.ok( | ||
res.text.indexOf("function square(n) {") > -1, | ||
"`" + res.text + "` should contain `function square(n) {`" | ||
); | ||
}) | ||
.expect(200, done); | ||
}); | ||
|
||
it("should not compile", function(done) { | ||
request(server) | ||
.get("/fixture.txt") | ||
.expect(function(res) { | ||
assert.equal(res.text, ""); | ||
}) | ||
.expect(200, done); | ||
}); | ||
}); |