Skip to content
Snippets Groups Projects
Unverified Commit bc067c02 authored by metabase-bot[bot]'s avatar metabase-bot[bot] Committed by GitHub
Browse files

[E2E] Allow custom browser for Cypress database snapshot generation (#29271) (#29317)


* Extract `parseArguments` into utils

* Allow custom browser for Cypress snapshots generation

Co-authored-by: default avatarNemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
parent f3d182dd
No related branches found
No related tags found
No related merge requests found
const cypress = require("cypress");
const { parseArguments, args } = require("./cypress-runner-utils");
const getConfig = baseUrl => {
return {
browser: "chrome",
......@@ -11,7 +13,14 @@ const getConfig = baseUrl => {
};
const generateSnapshots = async (baseUrl, exitFunction) => {
const snapshotConfig = getConfig(baseUrl);
// We only ever care about a broswer out of all possible user arguments,
// when it comes to the snapshot generation.
// Anything else could result either in a failure or in a wrong database snapshot!
const { browser } = await parseArguments(args);
const customBrowser = browser ? { browser } : null;
const baseConfig = getConfig(baseUrl);
const snapshotConfig = Object.assign({}, baseConfig, customBrowser);
try {
const { status, message, totalFailed, failures } = await cypress.run(
......
const cypress = require("cypress");
const arg = require("arg");
const { executeYarnCommand } = require("./cypress-runner-utils");
const args = arg(
{
"--folder": String, // The name of the folder to run files from
"--open": [Boolean], // Run Cypress in open mode or not? Doesn't accept additional arguments
},
{ permissive: true }, // Passes all other flags and args to the Cypress parser
);
const {
executeYarnCommand,
parseArguments,
args,
} = require("./cypress-runner-utils");
const folder = args["--folder"];
const isFolder = !!folder;
const isOpenMode = args["--open"];
const parseArguments = async () => {
const cliArgs = args._;
// cypress.cli.parseArguments requires `cypress run` as the first two arguments
if (cliArgs[0] !== "cypress") {
cliArgs.unshift("cypress");
}
if (cliArgs[1] !== "run") {
cliArgs.splice(1, 0, "run");
}
return await cypress.cli.parseRunArguments(cliArgs);
};
const getSourceFolder = folder => {
return `./e2e/test/scenarios/${folder}/**/*.cy.spec.js`;
};
......@@ -50,7 +30,7 @@ const runCypress = async (baseUrl, exitFunction) => {
spec: isFolder && getSourceFolder(folder),
};
const userArgs = await parseArguments();
const userArgs = await parseArguments(args);
const finalConfig = Object.assign({}, defaultConfig, userArgs);
......
const { exec } = require("child_process");
const arg = require("arg");
const chalk = require("chalk");
const cypress = require("cypress");
function printBold(message) {
console.log(chalk.bold(message));
......@@ -30,9 +32,34 @@ function executeYarnCommand({ command, message } = {}) {
});
}
const args = arg(
{
"--folder": String, // The name of the folder to run files from
"--open": [Boolean], // Run Cypress in open mode or not? Doesn't accept additional arguments
},
{ permissive: true }, // Passes all other flags and args to the Cypress parser
);
async function parseArguments(args) {
const cliArgs = args._;
// cypress.cli.parseArguments requires `cypress run` as the first two arguments
if (cliArgs[0] !== "cypress") {
cliArgs.unshift("cypress");
}
if (cliArgs[1] !== "run") {
cliArgs.splice(1, 0, "run");
}
return await cypress.cli.parseRunArguments(cliArgs);
}
module.exports = {
printBold,
printYellow,
printCyan,
executeYarnCommand,
parseArguments,
args,
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment