[Pkg-javascript-commits] [uglifyjs] 140/491: cache web assets between CI runs (#2089)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:29 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit 41beae4dd71920d2173bb2bc1efeb1231373c2a8
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Wed Jun 14 11:53:10 2017 +0800

    cache web assets between CI runs (#2089)
    
    - skip `test/jetstream.js` for `node at 0.12`
---
 .travis.yml           |  2 ++
 test/benchmark.js     |  4 +++-
 test/fetch.js         | 31 +++++++++++++++++++++++++++++++
 test/jetstream.js     | 12 +++++++++---
 test/mocha/release.js |  2 ++
 5 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 968addf..e199df2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,3 +10,5 @@ env:
 matrix:
   fast_finish: true
 sudo: false
+cache:
+  directories: tmp
diff --git a/test/benchmark.js b/test/benchmark.js
index e27ed2c..e34f085 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 0000000..5ca95bb
--- /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 a1b041a..1cc6d4a 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 bd1154a..1bf6e87 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);
     [

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list