Skip to content
Snippets Groups Projects
Unverified Commit f5f07e3d authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Allow multiple `--spec` arguments in Cypress `run` command (#15917)

* Extract `printBold()` function

* Allow multiple `--spec` arguments
parent bb87338b
No related branches found
No related tags found
No related merge requests found
......@@ -13,10 +13,12 @@ const server = BackendResource.get({ dbKey: "" });
// --spec <single-spec-path> - Specifies a path to a single test file
const userArgs = process.argv.slice(2);
const isOpenMode = userArgs.includes("--open");
const sourceFolder = userArgs.includes("--folder");
const singleFile = userArgs.includes("--spec");
const isFolderFlag = userArgs.includes("--folder");
const isSpecFlag = userArgs.includes("--spec");
const sourceFolderLocation = userArgs[userArgs.indexOf("--folder") + 1];
const singleFileName = userArgs[userArgs.indexOf("--spec") + 1];
const specs = userArgs[userArgs.indexOf("--spec") + 1];
const isSingleSpec = !specs.match(/,/);
const testFiles = isSingleSpec ? specs : specs.split(",");
function readFile(fileName) {
return new Promise(function(resolve, reject) {
......@@ -38,46 +40,40 @@ const init = async () => {
);
}
if (sourceFolder) {
console.log(chalk.bold(`Running tests in '${sourceFolderLocation}'`));
}
const logMessage = isFolderFlag
? `Running tests in '${sourceFolderLocation}'`
: `Running '${testFiles}'`;
if (singleFile) {
console.log(chalk.bold(`Running single spec '${singleFileName}'`));
}
printBold(logMessage);
try {
const version = await readFile(
__dirname + "/../../../resources/version.properties",
);
console.log(chalk.bold("Running e2e test runner with this build:"));
printBold("Running e2e test runner with this build:");
process.stdout.write(chalk.cyan(version));
console.log(
chalk.bold(
"If that version seems too old, please run `./bin/build version uberjar`.\n",
),
printBold(
"If that version seems too old, please run `./bin/build version uberjar`.\n",
);
} catch (e) {
console.log(
chalk.bold(
"No version file found. Please run `./bin/build version uberjar`.",
),
printBold(
"No version file found. Please run `./bin/build version uberjar`.",
);
process.exit(1);
}
console.log(chalk.bold("Starting backend"));
printBold("Starting backend");
await BackendResource.start(server);
console.log(chalk.bold("Generating snapshots"));
printBold("Generating snapshots");
await generateSnapshots();
console.log(chalk.bold("Starting Cypress"));
printBold("Starting Cypress");
const baseConfig = { baseUrl: server.host };
const folderConfig = sourceFolder && {
const folderConfig = isFolderFlag && {
integrationFolder: sourceFolderLocation,
};
const specsConfig = singleFile && { testFiles: singleFileName };
const specsConfig = isSpecFlag && { testFiles };
const ignoreConfig =
// if we're not running specific tests, avoid including db and smoketests
folderConfig || specsConfig
......@@ -127,7 +123,7 @@ const init = async () => {
};
const cleanup = async (exitCode = 0) => {
console.log(chalk.bold("Cleaning up..."));
printBold("Cleaning up...");
await BackendResource.stop(server);
process.exit(exitCode);
};
......@@ -163,3 +159,7 @@ async function generateSnapshots() {
cypressProcess.on("exit", resolve);
});
}
function printBold(message) {
console.log(chalk.bold(message));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment