Skip to content

Commit

Permalink
cache web assets between CI runs (#2089)
Browse files Browse the repository at this point in the history
- skip `test/jetstream.js` for `node@0.12`
  • Loading branch information
alexlamsl committed Jun 14, 2017
1 parent 82db918 commit 41beae4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -10,3 +10,5 @@ env:
matrix:
fast_finish: true
sudo: false
cache:
directories: tmp
4 changes: 3 additions & 1 deletion test/benchmark.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions 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);
});
};
12 changes: 9 additions & 3 deletions test/jetstream.js
Expand Up @@ -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 = "";
Expand Down
2 changes: 2 additions & 0 deletions 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;
Expand Down Expand Up @@ -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);
[
Expand Down

0 comments on commit 41beae4

Please sign in to comment.