implement test/jetstream.js --debug (#2058)
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var site = "http://browserbench.org/JetStream/";
|
var site = "http://browserbench.org/JetStream";
|
||||||
if (typeof phantom == "undefined") {
|
if (typeof phantom == "undefined") {
|
||||||
// workaround for tty output truncation upon process.exit()
|
// workaround for tty output truncation upon process.exit()
|
||||||
[process.stdout, process.stderr].forEach(function(stream){
|
[process.stdout, process.stderr].forEach(function(stream){
|
||||||
@@ -11,45 +11,62 @@ if (typeof phantom == "undefined") {
|
|||||||
stream._handle.setBlocking(true);
|
stream._handle.setBlocking(true);
|
||||||
});
|
});
|
||||||
var args = process.argv.slice(2);
|
var args = process.argv.slice(2);
|
||||||
|
var debug = args.indexOf("--debug");
|
||||||
|
if (debug >= 0) {
|
||||||
|
args.splice(debug, 1);
|
||||||
|
debug = true;
|
||||||
|
} else {
|
||||||
|
debug = false;
|
||||||
|
}
|
||||||
if (!args.length) {
|
if (!args.length) {
|
||||||
args.push("-mcb", "beautify=false,webkit");
|
args.push("-mcb", "beautify=false,webkit");
|
||||||
}
|
}
|
||||||
args.push("--timings");
|
args.push("--timings");
|
||||||
var child_process = require("child_process");
|
var child_process = require("child_process");
|
||||||
try {
|
|
||||||
require("phantomjs-prebuilt");
|
|
||||||
} catch(e) {
|
|
||||||
child_process.execSync("npm install phantomjs-prebuilt@2.1.14 --no-save");
|
|
||||||
}
|
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
var server = http.createServer(function(request, response) {
|
var server = http.createServer(function(request, response) {
|
||||||
request.resume();
|
request.resume();
|
||||||
var url = decodeURIComponent(request.url.slice(1));
|
var url = site + request.url;
|
||||||
var stderr = "";
|
|
||||||
var uglifyjs = child_process.fork("bin/uglifyjs", args, {
|
|
||||||
silent: true
|
|
||||||
}).on("exit", function(code) {
|
|
||||||
console.log("uglifyjs", url.indexOf(site) == 0 ? url.slice(site.length) : url, args.join(" "));
|
|
||||||
console.log(stderr);
|
|
||||||
if (code) throw new Error("uglifyjs failed with code " + code);
|
|
||||||
});
|
|
||||||
uglifyjs.stderr.on("data", function(data) {
|
|
||||||
stderr += data;
|
|
||||||
}).setEncoding("utf8");
|
|
||||||
uglifyjs.stdout.pipe(response);
|
|
||||||
http.get(url, function(res) {
|
http.get(url, function(res) {
|
||||||
res.pipe(uglifyjs.stdin);
|
response.writeHead(res.statusCode, {
|
||||||
});
|
"Content-Type": res.headers["content-type"]
|
||||||
}).listen().on("listening", function() {
|
});
|
||||||
var phantomjs = require("phantomjs-prebuilt");
|
if (/\.js$/.test(url)) {
|
||||||
var program = phantomjs.exec(process.argv[1], server.address().port);
|
var stderr = "";
|
||||||
program.stdout.pipe(process.stdout);
|
var uglifyjs = child_process.fork("bin/uglifyjs", args, {
|
||||||
program.stderr.pipe(process.stderr);
|
silent: true
|
||||||
program.on("exit", function(code) {
|
}).on("exit", function(code) {
|
||||||
server.close();
|
console.log("uglifyjs", url.slice(site.length + 1), args.join(" "));
|
||||||
if (code) throw new Error("JetStream failed!");
|
console.log(stderr);
|
||||||
console.log("JetStream completed successfully.");
|
if (code) throw new Error("uglifyjs failed with code " + code);
|
||||||
|
});
|
||||||
|
uglifyjs.stderr.on("data", function(data) {
|
||||||
|
stderr += data;
|
||||||
|
}).setEncoding("utf8");
|
||||||
|
uglifyjs.stdout.pipe(response);
|
||||||
|
res.pipe(uglifyjs.stdin);
|
||||||
|
} else {
|
||||||
|
res.pipe(response);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}).listen();
|
||||||
|
server.on("listening", function() {
|
||||||
|
var port = server.address().port;
|
||||||
|
if (debug) {
|
||||||
|
console.log("http://localhost:" + port + "/");
|
||||||
|
} else {
|
||||||
|
child_process.exec("npm install phantomjs-prebuilt@2.1.14 --no-save", function(error) {
|
||||||
|
if (error) throw error;
|
||||||
|
var program = require("phantomjs-prebuilt").exec(process.argv[1], port);
|
||||||
|
program.stdout.pipe(process.stdout);
|
||||||
|
program.stderr.pipe(process.stderr);
|
||||||
|
program.on("exit", function(code) {
|
||||||
|
server.close();
|
||||||
|
if (code) throw new Error("JetStream failed!");
|
||||||
|
console.log("JetStream completed successfully.");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
server.timeout = 0;
|
server.timeout = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -63,10 +80,6 @@ if (typeof phantom == "undefined") {
|
|||||||
phantom.exit(1);
|
phantom.exit(1);
|
||||||
};
|
};
|
||||||
var url = "http://localhost:" + require("system").args[1] + "/";
|
var url = "http://localhost:" + require("system").args[1] + "/";
|
||||||
page.onResourceRequested = function(requestData, networkRequest) {
|
|
||||||
if (/\.js$/.test(requestData.url))
|
|
||||||
networkRequest.changeUrl(url + encodeURIComponent(requestData.url));
|
|
||||||
}
|
|
||||||
page.onConsoleMessage = function(msg) {
|
page.onConsoleMessage = function(msg) {
|
||||||
if (/Error:/i.test(msg)) {
|
if (/Error:/i.test(msg)) {
|
||||||
console.error(msg);
|
console.error(msg);
|
||||||
@@ -77,8 +90,8 @@ if (typeof phantom == "undefined") {
|
|||||||
phantom.exit();
|
phantom.exit();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
page.open(site, function(status) {
|
page.open(url, function(status) {
|
||||||
if (status != "success") phantomjs.exit(1);
|
if (status != "success") phantom.exit(1);
|
||||||
page.evaluate(function() {
|
page.evaluate(function() {
|
||||||
JetStream.switchToQuick();
|
JetStream.switchToQuick();
|
||||||
JetStream.start();
|
JetStream.start();
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ describe("test/benchmark.js", function() {
|
|||||||
|
|
||||||
describe("test/jetstream.js", function() {
|
describe("test/jetstream.js", function() {
|
||||||
this.timeout(20 * 60 * 1000);
|
this.timeout(20 * 60 * 1000);
|
||||||
it("Should install phantomjs-prebuilt", function(done) {
|
|
||||||
run("npm", ["install", "phantomjs-prebuilt@2.1.14"], done);
|
|
||||||
});
|
|
||||||
[
|
[
|
||||||
"-mc",
|
"-mc",
|
||||||
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
||||||
|
|||||||
Reference in New Issue
Block a user