diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/benchmark.js | 4 | ||||
-rw-r--r-- | test/fetch.js | 31 | ||||
-rw-r--r-- | test/jetstream.js | 12 | ||||
-rw-r--r-- | test/mocha/release.js | 2 |
4 files changed, 45 insertions, 4 deletions
diff --git a/test/benchmark.js b/test/benchmark.js index e27ed2c3..e34f0858 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -4,6 +4,7 @@ "use strict"; var createHash = require("crypto").createHash; +var fetch = require("./fetch"); var fork = require("child_process").fork; var args = process.argv.slice(2); if (!args.length) { @@ -52,7 +53,8 @@ urls.forEach(function(url) { output: 0, log: "" }; - require(url.slice(0, url.indexOf(":"))).get(url, function(res) { + fetch(url, function(err, res) { + if (err) throw err; var uglifyjs = fork("bin/uglifyjs", args, { silent: true }); res.on("data", function(data) { results[url].input += data.length; diff --git a/test/fetch.js b/test/fetch.js new file mode 100644 index 00000000..5ca95bbb --- /dev/null +++ b/test/fetch.js @@ -0,0 +1,31 @@ +var fs = require("fs"); +var path = require("path"); + +try { + fs.mkdirSync("./tmp"); +} catch (e) { + if (e.code != "EEXIST") throw e; +} + +function local(url) { + return path.join("./tmp", encodeURIComponent(url)); +} + +function read(url) { + return fs.createReadStream(local(url)); +} + +module.exports = function(url, callback) { + var result = read(url); + result.on("error", function(e) { + if (e.code != "ENOENT") return callback(e); + require(url.slice(0, url.indexOf(":"))).get(url, function(res) { + if (res.statusCode !== 200) return callback(res); + res.pipe(fs.createWriteStream(local(url)).on("close", function() { + callback(null, read(url)); + })); + }); + }).on("open", function() { + callback(null, result); + }); +}; diff --git a/test/jetstream.js b/test/jetstream.js index a1b041a8..1cc6d4a7 100644 --- a/test/jetstream.js +++ b/test/jetstream.js @@ -23,13 +23,19 @@ if (typeof phantom == "undefined") { } args.push("--timings"); var child_process = require("child_process"); + var fetch = require("./fetch"); var http = require("http"); var server = http.createServer(function(request, response) { request.resume(); var url = site + request.url; - http.get(url, function(res) { - response.writeHead(res.statusCode, { - "Content-Type": res.headers["content-type"] + fetch(url, function(err, res) { + if (err) throw err; + response.writeHead(200, { + "Content-Type": { + css: "text/css", + js: "application/javascript", + png: "image/png" + }[url.slice(url.lastIndexOf(".") + 1)] || "text/html; charset=utf-8" }); if (/\.js$/.test(url)) { var stderr = ""; diff --git a/test/mocha/release.js b/test/mocha/release.js index bd1154ad..1bf6e87b 100644 --- a/test/mocha/release.js +++ b/test/mocha/release.js @@ -1,4 +1,5 @@ var assert = require("assert"); +var semver = require("semver"); var spawn = require("child_process").spawn; if (!process.env.UGLIFYJS_TEST_ALL) return; @@ -32,6 +33,7 @@ describe("test/benchmark.js", function() { }); }); +if (semver.satisfies(process.version, "0.12")) return; describe("test/jetstream.js", function() { this.timeout(20 * 60 * 1000); [ |