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

[Cypress runner] Use Cypress Module API to generate Cypress snapshots (#17010)

parent 005c221e
No related branches found
No related tags found
No related merge requests found
const cypress = require("cypress");
const getConfig = baseUrl => {
return {
configFile: "frontend/test/__support__/e2e/cypress-snapshots.json",
config: {
baseUrl,
},
};
};
const generateSnapshots = async (baseUrl, exitFunction) => {
const snapshotConfig = getConfig(baseUrl);
try {
const results = await cypress.run(snapshotConfig);
// At least one test failed. We can't continue to the next step.
// Cypress tests rely on snapshots correctly generated at this stage.
if (results.totalFailed > 0) {
await exitFunction(1);
}
// Something went wrong and Cypress failed to even run tests
if (results.status === "failed" && results.failures) {
console.error(results.message);
await exitFunction(results.failures);
}
} catch (e) {
console.error("Unable to generate snapshots\n", e);
await exitFunction(1);
}
};
module.exports = generateSnapshots;
import { spawn } from "child_process";
const getVersion = require("./cypress-runner-get-version");
const generateSnapshots = require("./generate-cypress-snapshots");
const { printBold, printYellow } = require("./cypress-runner-utils");
// Use require for BackendResource to run it after the mock afterAll has been set
const BackendResource = require("./backend.js").BackendResource;
const server = BackendResource.get({ dbKey: "" });
const baseUrl = server.host;
// We currently accept three (optional) command line arguments
// --open - Opens the Cypress test browser
......@@ -29,7 +31,7 @@ const init = async () => {
await BackendResource.start(server);
printBold("Generating snapshots");
await generateSnapshots();
await generateSnapshots(baseUrl, cleanup);
printBold("Starting Cypress");
if (!isOpenMode) {
......@@ -108,22 +110,3 @@ launch();
process.on("SIGTERM", cleanup);
process.on("SIGINT", cleanup);
async function generateSnapshots() {
const cypressProcess = spawn(
"yarn",
[
"cypress",
"run",
"--config-file",
"frontend/test/__support__/e2e/cypress-snapshots.json",
"--config",
`baseUrl=${server.host}`,
],
{ stdio: "inherit" },
);
return new Promise((resolve, reject) => {
cypressProcess.on("exit", resolve);
});
}
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