2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-04 08:47:37 +08:00

Preparation for using chrome for qunit in docker images (#5062)

Move use_chrome option to ENV variable
Rewrite script to work with node 6 (current LTS version used in discourse_docker)
Add node stuff to gitignore
This commit is contained in:
David Taylor 2017-08-18 19:08:58 +01:00 committed by Sam
parent e976b98efc
commit d65570a8a1
3 changed files with 76 additions and 65 deletions

View file

@ -3,6 +3,8 @@
// 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) {
@ -13,83 +15,88 @@ if (args.length < 1 || args.length > 2) {
const chromeLauncher = require('chrome-launcher');
const CDP = require('chrome-remote-interface');
(async function() {
(function() {
async function launchChrome() {
return await chromeLauncher.launch({
function launchChrome() {
return chromeLauncher.launch({
chromeFlags: [
'--disable-gpu',
'--headless'
'--headless',
'--no-sandbox'
]
});
}
const chrome = await launchChrome();
const protocol = await CDP({
port: chrome.port
});
const {
Page,
Runtime
} = protocol;
await Page.enable();
await Runtime.enable();
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;
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(async() => {
await Runtime.evaluate({
expression: `(${qunit_script})()`
});
const timeout = parseInt(args[1] || 300000, 10);
var start = Date.now();
var interval = setInterval(async() => {
if (Date.now() > start + timeout) {
console.error("Tests timed out");
protocol.close();
chrome.kill();
process.exit(124);
} else {
const numFails = await Runtime.evaluate({
expression: `(${check_script})()`
// If it's a simple test result, write without newline
if(message === "." || message === "F"){
process.stdout.write(message);
}else{
console.log(message);
}
});
if (numFails.result.type !== 'undefined') {
clearInterval(interval);
protocol.close();
chrome.kill();
Page.navigate({
url: args[0]
});
if (numFails.value > 0) {
process.exit(1);
} else {
process.exit();
}
}
}
}, 250);
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.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() {
@ -161,4 +168,4 @@ function check() {
return window.qunitDone.failed;
}
}
const check_script = check.toString();
const check_script = check.toString();