Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async fix #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 92 additions & 85 deletions bin/qunit-puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,102 +13,109 @@ const timeout = parseInt(args[1] || 300000, 10);
const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();

// Attach to browser console log events, and log to node console
await page.on('console', (...params) => {
for (let i = 0; i < params.length; ++i)
console.log(`${params[i]}`);
});

var moduleErrors = [];
var testErrors = [];
var assertionErrors = [];

await page.exposeFunction('harness_moduleDone', context => {
if (context.failed) {
var msg = "Module Failed: " + context.name + "\n" + testErrors.join("\n");
moduleErrors.push(msg);
testErrors = [];
}
});

await page.exposeFunction('harness_testDone', context => {
if (context.failed) {
var msg = " Test Failed: " + context.name + assertionErrors.join(" ");
testErrors.push(msg);
assertionErrors = [];
process.stdout.write("F");
} else {
process.stdout.write(".");
}
});
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();

// Attach to browser console log events, and log to node console
await page.on('console', (...params) => {
for (let i = 0; i < params.length; ++i)
console.log(`${params[i]}`);
});

var moduleErrors = [];
var testErrors = [];
var assertionErrors = [];

await page.exposeFunction('harness_moduleDone', context => {
if (context.failed) {
var msg = "Module Failed: " + context.name + "\n" + testErrors.join("\n");
moduleErrors.push(msg);
testErrors = [];
}
});

await page.exposeFunction('harness_testDone', context => {
if (context.failed) {
var msg = " Test Failed: " + context.name + assertionErrors.join(" ");
testErrors.push(msg);
assertionErrors = [];
process.stdout.write("F");
} else {
process.stdout.write(".");
}
});

await page.exposeFunction('harness_log', context => {
if (context.result) { return; } // If success don't log
await page.exposeFunction('harness_log', context => {
if (context.result) { return; } // If success don't log

var msg = "\n Assertion Failed:";
if (context.message) {
msg += " " + context.message;
}
var msg = "\n Assertion Failed:";
if (context.message) {
msg += " " + context.message;
}

if (context.expected) {
msg += "\n Expected: " + context.expected + ", Actual: " + context.actual;
}
if (context.expected) {
msg += "\n Expected: " + context.expected + ", Actual: " + context.actual;
}

assertionErrors.push(msg);
});
assertionErrors.push(msg);
});

await page.exposeFunction('harness_done', context => {
console.log("\n");
await page.exposeFunction('harness_done', context => {
console.log("\n");

if (moduleErrors.length > 0) {
for (var idx=0; idx<moduleErrors.length; idx++) {
console.error(moduleErrors[idx]+"\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(", "));
browser.close();
if (context.failed > 0){
process.exit(1);
}else{
process.exit();
}
});
var stats = [
"Time: " + context.runtime + "ms",
"Total: " + context.total,
"Passed: " + context.passed,
"Failed: " + context.failed
];
console.log(stats.join(", "));

browser.close();
if (context.failed > 0){
process.exit(1);
}else{
process.exit();
}
});

await page.goto(targetURL);
await page.goto(targetURL);

await page.evaluate(() => {
QUnit.config.testTimeout = 10000;
await page.evaluate(() => {
QUnit.config.testTimeout = 10000;

// Cannot pass the window.harness_blah methods directly, because they are
// automatically defined as async methods, which QUnit does not support
QUnit.moduleDone((context) => { window.harness_moduleDone(context); });
QUnit.testDone((context) => { window.harness_testDone(context); });
QUnit.log((context) => { window.harness_log(context); });
QUnit.done((context) => { window.harness_done(context); });
// Cannot pass the window.harness_blah methods directly, because they are
// automatically defined as async methods, which QUnit does not support
QUnit.moduleDone((context) => { window.harness_moduleDone(context); });
QUnit.testDone((context) => { window.harness_testDone(context); });
QUnit.log((context) => { window.harness_log(context); });
QUnit.done((context) => { window.harness_done(context); });

console.log("\nRunning: " + JSON.stringify(QUnit.urlParams) + "\n");
});
console.log("\nRunning: " + JSON.stringify(QUnit.urlParams) + "\n");

function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
await wait(timeout);
if (!QUnit.config.autostart) {
QUnit.start();
}
});

console.error("Tests timed out");
browser.close();
process.exit(124);
})().catch((error) => {
console.error(error);
process.exit(1);
});
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
await wait(timeout);

console.error("Tests timed out");
browser.close();
process.exit(124);

} catch(err) {
console.error('ERROR:', err);
process.exit(1);
}
})()