Refactor parameter passing for the startBrowser(s)
functions in test.mjs
This commit prepares for the introduction of extra options in later commits by changing the function signatures of the `startBrowser(s)` functions to take parameter objects instead of plain parameters. This makes the call sites explicitly state which parameters they pass, improving overall readability as well.
This commit is contained in:
parent
24fcc042f4
commit
a1d84f8ce1
@ -250,8 +250,10 @@ function updateRefImages() {
|
|||||||
function examineRefImages() {
|
function examineRefImages() {
|
||||||
startServer();
|
startServer();
|
||||||
|
|
||||||
const startUrl = `http://${host}:${server.port}/test/resources/reftest-analyzer.html#web=/test/eq.log`;
|
startBrowser({
|
||||||
startBrowser("firefox", startUrl).then(function (browser) {
|
browserName: "firefox",
|
||||||
|
startUrl: `http://${host}:${server.port}/test/resources/reftest-analyzer.html#web=/test/eq.log`,
|
||||||
|
}).then(function (browser) {
|
||||||
browser.on("disconnected", function () {
|
browser.on("disconnected", function () {
|
||||||
stopServer();
|
stopServer();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
@ -339,26 +341,28 @@ function startRefTest(masterMode, showRefImages) {
|
|||||||
server.hooks.POST.push(refTestPostHandler);
|
server.hooks.POST.push(refTestPostHandler);
|
||||||
onAllSessionsClosed = finalize;
|
onAllSessionsClosed = finalize;
|
||||||
|
|
||||||
const baseUrl = `http://${host}:${server.port}/test/test_slave.html`;
|
await startBrowsers({
|
||||||
await startBrowsers(function (session) {
|
baseUrl: `http://${host}:${server.port}/test/test_slave.html`,
|
||||||
session.masterMode = masterMode;
|
initializeSession: session => {
|
||||||
session.taskResults = {};
|
session.masterMode = masterMode;
|
||||||
session.tasks = {};
|
session.taskResults = {};
|
||||||
session.remaining = manifest.length;
|
session.tasks = {};
|
||||||
manifest.forEach(function (item) {
|
session.remaining = manifest.length;
|
||||||
var rounds = item.rounds || 1;
|
manifest.forEach(function (item) {
|
||||||
var roundsResults = [];
|
var rounds = item.rounds || 1;
|
||||||
roundsResults.length = rounds;
|
var roundsResults = [];
|
||||||
session.taskResults[item.id] = roundsResults;
|
roundsResults.length = rounds;
|
||||||
session.tasks[item.id] = item;
|
session.taskResults[item.id] = roundsResults;
|
||||||
});
|
session.tasks[item.id] = item;
|
||||||
session.numRuns = 0;
|
});
|
||||||
session.numErrors = 0;
|
session.numRuns = 0;
|
||||||
session.numFBFFailures = 0;
|
session.numErrors = 0;
|
||||||
session.numEqNoSnapshot = 0;
|
session.numFBFFailures = 0;
|
||||||
session.numEqFailures = 0;
|
session.numEqNoSnapshot = 0;
|
||||||
monitorBrowserTimeout(session, handleSessionTimeout);
|
session.numEqFailures = 0;
|
||||||
}, baseUrl);
|
monitorBrowserTimeout(session, handleSessionTimeout);
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function checkRefsTmp() {
|
function checkRefsTmp() {
|
||||||
if (masterMode && fs.existsSync(refsTmpDir)) {
|
if (masterMode && fs.existsSync(refsTmpDir)) {
|
||||||
@ -798,11 +802,13 @@ async function startUnitTest(testUrl, name) {
|
|||||||
startServer();
|
startServer();
|
||||||
server.hooks.POST.push(unitTestPostHandler);
|
server.hooks.POST.push(unitTestPostHandler);
|
||||||
|
|
||||||
const baseUrl = `http://${host}:${server.port}${testUrl}`;
|
await startBrowsers({
|
||||||
await startBrowsers(function (session) {
|
baseUrl: `http://${host}:${server.port}${testUrl}`,
|
||||||
session.numRuns = 0;
|
initializeSession: session => {
|
||||||
session.numErrors = 0;
|
session.numRuns = 0;
|
||||||
}, baseUrl);
|
session.numErrors = 0;
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startIntegrationTest() {
|
async function startIntegrationTest() {
|
||||||
@ -810,9 +816,12 @@ async function startIntegrationTest() {
|
|||||||
startServer();
|
startServer();
|
||||||
|
|
||||||
const { runTests } = await import("./integration-boot.mjs");
|
const { runTests } = await import("./integration-boot.mjs");
|
||||||
await startBrowsers(function (session) {
|
await startBrowsers({
|
||||||
session.numRuns = 0;
|
baseUrl: null,
|
||||||
session.numErrors = 0;
|
initializeSession: session => {
|
||||||
|
session.numRuns = 0;
|
||||||
|
session.numErrors = 0;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
global.integrationBaseUrl = `http://${host}:${server.port}/build/generic/web/viewer.html`;
|
global.integrationBaseUrl = `http://${host}:${server.port}/build/generic/web/viewer.html`;
|
||||||
global.integrationSessions = sessions;
|
global.integrationSessions = sessions;
|
||||||
@ -888,7 +897,7 @@ function unitTestPostHandler(req, res) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startBrowser(browserName, startUrl = "") {
|
async function startBrowser({ browserName, startUrl }) {
|
||||||
const options = {
|
const options = {
|
||||||
product: browserName,
|
product: browserName,
|
||||||
headless: false,
|
headless: false,
|
||||||
@ -958,7 +967,7 @@ async function startBrowser(browserName, startUrl = "") {
|
|||||||
return browser;
|
return browser;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startBrowsers(initSessionCallback, baseUrl = null) {
|
async function startBrowsers({ baseUrl, initializeSession }) {
|
||||||
// Remove old browser revisions from Puppeteer's cache. Updating Puppeteer can
|
// Remove old browser revisions from Puppeteer's cache. Updating Puppeteer can
|
||||||
// cause new browser revisions to be downloaded, so trimming the cache will
|
// cause new browser revisions to be downloaded, so trimming the cache will
|
||||||
// prevent the disk from filling up over time.
|
// prevent the disk from filling up over time.
|
||||||
@ -997,10 +1006,10 @@ async function startBrowsers(initSessionCallback, baseUrl = null) {
|
|||||||
startUrl = baseUrl + queryParameters;
|
startUrl = baseUrl + queryParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
await startBrowser(browserName, startUrl)
|
await startBrowser({ browserName, startUrl })
|
||||||
.then(function (browser) {
|
.then(function (browser) {
|
||||||
session.browser = browser;
|
session.browser = browser;
|
||||||
initSessionCallback?.(session);
|
initializeSession(session);
|
||||||
})
|
})
|
||||||
.catch(function (ex) {
|
.catch(function (ex) {
|
||||||
console.log(`Error while starting ${browserName}: ${ex.message}`);
|
console.log(`Error while starting ${browserName}: ${ex.message}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user