mirror of
https://github.com/discourse/discourse.git
synced 2025-09-04 08:47:37 +08:00
Switch to chrome headless mode instead of phantomjs.
This commit is contained in:
parent
30ddc1f222
commit
6a4f391e38
13 changed files with 284 additions and 721 deletions
11
vendor/assets/javascripts/babel.js
vendored
11
vendor/assets/javascripts/babel.js
vendored
|
@ -2357,7 +2357,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
$export.B = 16; // bind
|
||||
$export.W = 32; // wrap
|
||||
$export.U = 64; // safe
|
||||
$export.R = 128; // real proto method for `library`
|
||||
$export.R = 128; // real proto method for `library`
|
||||
module.exports = $export;
|
||||
|
||||
/***/ }),
|
||||
|
@ -62209,13 +62209,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
"test": false,
|
||||
"throws": false
|
||||
},
|
||||
"phantomjs": {
|
||||
"console": true,
|
||||
"exports": true,
|
||||
"phantom": true,
|
||||
"require": true,
|
||||
"WebPage": true
|
||||
},
|
||||
"couch": {
|
||||
"emit": false,
|
||||
"exports": false,
|
||||
|
@ -62843,4 +62836,4 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
/***/ })
|
||||
/******/ ])))
|
||||
});
|
||||
;
|
||||
;
|
||||
|
|
171
vendor/assets/javascripts/run-qunit-chrome.js
vendored
171
vendor/assets/javascripts/run-qunit-chrome.js
vendored
|
@ -1,171 +0,0 @@
|
|||
// Chrome QUnit Test Runner
|
||||
// Author: David Taylor
|
||||
// Requires chrome-launcher and chrome-remote-interface from npm
|
||||
// An up-to-date version of chrome is also required
|
||||
|
||||
/* globals Promise */
|
||||
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
if (args.length < 1 || args.length > 2) {
|
||||
console.log("Usage: node run-qunit-chrome.js <URL> <timeout>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const chromeLauncher = require('chrome-launcher');
|
||||
const CDP = require('chrome-remote-interface');
|
||||
|
||||
(function() {
|
||||
|
||||
function launchChrome() {
|
||||
return chromeLauncher.launch({
|
||||
chromeFlags: [
|
||||
'--disable-gpu',
|
||||
'--headless',
|
||||
'--no-sandbox'
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
launchChrome().then(chrome => {
|
||||
CDP({
|
||||
port: chrome.port
|
||||
}).then(protocol => {
|
||||
const {Page, Runtime} = protocol;
|
||||
Promise.all([Page.enable(), Runtime.enable()]).then(()=>{
|
||||
|
||||
Runtime.consoleAPICalled((response) => {
|
||||
const message = response['args'][0].value;
|
||||
|
||||
// If it's a simple test result, write without newline
|
||||
if(message === "." || message === "F"){
|
||||
process.stdout.write(message);
|
||||
}else{
|
||||
console.log(message);
|
||||
}
|
||||
});
|
||||
|
||||
Page.navigate({
|
||||
url: args[0]
|
||||
});
|
||||
|
||||
Page.loadEventFired(() => {
|
||||
|
||||
Runtime.evaluate({
|
||||
expression: `(${qunit_script})()`
|
||||
}).then(() => {
|
||||
const timeout = parseInt(args[1] || 300000, 10);
|
||||
var start = Date.now();
|
||||
|
||||
var interval = setInterval(() => {
|
||||
if (Date.now() > start + timeout) {
|
||||
console.error("Tests timed out");
|
||||
|
||||
protocol.close();
|
||||
chrome.kill();
|
||||
process.exit(124);
|
||||
} else {
|
||||
|
||||
Runtime.evaluate({
|
||||
expression: `(${check_script})()`
|
||||
}).then(numFails => {
|
||||
if (numFails.result.type !== 'undefined') {
|
||||
clearInterval(interval);
|
||||
protocol.close();
|
||||
chrome.kill();
|
||||
|
||||
if (numFails.result.value > 0) {
|
||||
process.exit(1);
|
||||
} else {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
}).catch(error);
|
||||
}
|
||||
}, 250);
|
||||
}).catch(error(1));
|
||||
});
|
||||
}).catch(error(3));
|
||||
}).catch(error(4));
|
||||
}).catch(error(5));
|
||||
})();
|
||||
|
||||
function error(code){
|
||||
return function(){
|
||||
console.log("A promise failed to resolve code:"+code);
|
||||
process.exit(1);
|
||||
};
|
||||
}
|
||||
|
||||
// The following functions are converted to strings
|
||||
// And then sent to chrome to be evalaluated
|
||||
function logQUnit() {
|
||||
var moduleErrors = [];
|
||||
var testErrors = [];
|
||||
var assertionErrors = [];
|
||||
|
||||
console.log("\nRunning: " + JSON.stringify(QUnit.urlParams) + "\n");
|
||||
|
||||
QUnit.config.testTimeout = 10000;
|
||||
|
||||
QUnit.moduleDone(function(context) {
|
||||
if (context.failed) {
|
||||
var msg = "Module Failed: " + context.name + "\n" + testErrors.join("\n");
|
||||
moduleErrors.push(msg);
|
||||
testErrors = [];
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.testDone(function(context) {
|
||||
if (context.failed) {
|
||||
var msg = " Test Failed: " + context.name + assertionErrors.join(" ");
|
||||
testErrors.push(msg);
|
||||
assertionErrors = [];
|
||||
console.log("F");
|
||||
} else {
|
||||
console.log(".");
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.log(function(context) {
|
||||
if (context.result) { return; }
|
||||
|
||||
var msg = "\n Assertion Failed:";
|
||||
if (context.message) {
|
||||
msg += " " + context.message;
|
||||
}
|
||||
|
||||
if (context.expected) {
|
||||
msg += "\n Expected: " + context.expected + ", Actual: " + context.actual;
|
||||
}
|
||||
|
||||
assertionErrors.push(msg);
|
||||
});
|
||||
|
||||
QUnit.done(function(context) {
|
||||
console.log("\n");
|
||||
|
||||
if (moduleErrors.length > 0) {
|
||||
for (var idx=0; idx<moduleErrors.length; idx++) {
|
||||
console.error(moduleErrors[idx]+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
var stats = [
|
||||
"Time: " + context.runtime + "ms",
|
||||
"Total: " + context.total,
|
||||
"Passed: " + context.passed,
|
||||
"Failed: " + context.failed
|
||||
];
|
||||
console.log(stats.join(", "));
|
||||
window.qunitDone = context;
|
||||
});
|
||||
}
|
||||
const qunit_script = logQUnit.toString();
|
||||
|
||||
function check() {
|
||||
if(window.qunitDone){
|
||||
return window.qunitDone.failed;
|
||||
}
|
||||
}
|
||||
const check_script = check.toString();
|
148
vendor/assets/javascripts/run-qunit.js
vendored
148
vendor/assets/javascripts/run-qunit.js
vendored
|
@ -1,66 +1,104 @@
|
|||
// PhantomJS QUnit Test Runner
|
||||
// Chrome QUnit Test Runner
|
||||
// Author: David Taylor
|
||||
// Requires chrome-launcher and chrome-remote-interface from npm
|
||||
// An up-to-date version of chrome is also required
|
||||
|
||||
/*globals QUnit phantom*/
|
||||
/* globals Promise */
|
||||
|
||||
var system = require("system"),
|
||||
args = phantom.args;
|
||||
|
||||
if (args === undefined) {
|
||||
args = system.args;
|
||||
args.shift();
|
||||
}
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
if (args.length < 1 || args.length > 2) {
|
||||
console.log("Usage: " + phantom.scriptName + " <URL> <timeout>");
|
||||
phantom.exit(1);
|
||||
console.log("Usage: node run-qunit.js <URL> <timeout>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var page = require("webpage").create();
|
||||
const chromeLauncher = require('chrome-launcher');
|
||||
const CDP = require('chrome-remote-interface');
|
||||
|
||||
page.onConsoleMessage = function(msg) {
|
||||
if (msg.slice(0, 8) === "WARNING:") { return; }
|
||||
if (msg.slice(0, 6) === "DEBUG:") { return; }
|
||||
(function() {
|
||||
|
||||
console.log(msg);
|
||||
};
|
||||
function launchChrome() {
|
||||
return chromeLauncher.launch({
|
||||
chromeFlags: [
|
||||
'--disable-gpu',
|
||||
'--headless',
|
||||
'--no-sandbox'
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
page.onCallback = function (message) {
|
||||
// forward the message to the standard output
|
||||
system.stdout.write(message);
|
||||
};
|
||||
launchChrome().then(chrome => {
|
||||
CDP({
|
||||
port: chrome.port
|
||||
}).then(protocol => {
|
||||
const {Page, Runtime} = protocol;
|
||||
Promise.all([Page.enable(), Runtime.enable()]).then(()=>{
|
||||
|
||||
page.open(args[0], function(status) {
|
||||
if (status !== "success") {
|
||||
console.error("Unable to access network");
|
||||
phantom.exit(1);
|
||||
} else {
|
||||
page.evaluate(logQUnit);
|
||||
Runtime.consoleAPICalled((response) => {
|
||||
const message = response['args'][0].value;
|
||||
|
||||
var timeout = parseInt(args[1] || 300000, 10),
|
||||
start = Date.now();
|
||||
|
||||
var interval = setInterval(function() {
|
||||
if (Date.now() > start + timeout) {
|
||||
console.error("Tests timed out");
|
||||
phantom.exit(124);
|
||||
} else {
|
||||
var qunitDone = page.evaluate(function() {
|
||||
return window.qunitDone;
|
||||
// If it's a simple test result, write without newline
|
||||
if(message === "." || message === "F"){
|
||||
process.stdout.write(message);
|
||||
}else{
|
||||
console.log(message);
|
||||
}
|
||||
});
|
||||
|
||||
if (qunitDone) {
|
||||
clearInterval(interval);
|
||||
if (qunitDone.failed > 0) {
|
||||
phantom.exit(1);
|
||||
} else {
|
||||
phantom.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
});
|
||||
Page.navigate({
|
||||
url: args[0]
|
||||
});
|
||||
|
||||
Page.loadEventFired(() => {
|
||||
|
||||
Runtime.evaluate({
|
||||
expression: `(${qunit_script})()`
|
||||
}).then(() => {
|
||||
const timeout = parseInt(args[1] || 300000, 10);
|
||||
var start = Date.now();
|
||||
|
||||
var interval = setInterval(() => {
|
||||
if (Date.now() > start + timeout) {
|
||||
console.error("Tests timed out");
|
||||
|
||||
protocol.close();
|
||||
chrome.kill();
|
||||
process.exit(124);
|
||||
} else {
|
||||
|
||||
Runtime.evaluate({
|
||||
expression: `(${check_script})()`
|
||||
}).then(numFails => {
|
||||
if (numFails.result.type !== 'undefined') {
|
||||
clearInterval(interval);
|
||||
protocol.close();
|
||||
chrome.kill();
|
||||
|
||||
if (numFails.result.value > 0) {
|
||||
process.exit(1);
|
||||
} else {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
}).catch(error);
|
||||
}
|
||||
}, 250);
|
||||
}).catch(error(1));
|
||||
});
|
||||
}).catch(error(3));
|
||||
}).catch(error(4));
|
||||
}).catch(error(5));
|
||||
})();
|
||||
|
||||
function error(code){
|
||||
return function(){
|
||||
console.log("A promise failed to resolve code:"+code);
|
||||
process.exit(1);
|
||||
};
|
||||
}
|
||||
|
||||
// The following functions are converted to strings
|
||||
// And then sent to chrome to be evalaluated
|
||||
function logQUnit() {
|
||||
var moduleErrors = [];
|
||||
var testErrors = [];
|
||||
|
@ -83,9 +121,9 @@ function logQUnit() {
|
|||
var msg = " Test Failed: " + context.name + assertionErrors.join(" ");
|
||||
testErrors.push(msg);
|
||||
assertionErrors = [];
|
||||
window.callPhantom("F");
|
||||
console.log("F");
|
||||
} else {
|
||||
window.callPhantom(".");
|
||||
console.log(".");
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -123,3 +161,11 @@ function logQUnit() {
|
|||
window.qunitDone = context;
|
||||
});
|
||||
}
|
||||
const qunit_script = logQUnit.toString();
|
||||
|
||||
function check() {
|
||||
if(window.qunitDone){
|
||||
return window.qunitDone.failed;
|
||||
}
|
||||
}
|
||||
const check_script = check.toString();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue