2022-07-25 09:52:56 +00:00
|
|
|
import { defineConfig } from "cypress";
|
2024-02-20 10:10:54 +00:00
|
|
|
import cypressSplit from "cypress-split";
|
2024-02-27 13:03:34 +00:00
|
|
|
import fs from "node:fs";
|
2024-05-13 08:34:35 +00:00
|
|
|
import { isAsyncFunction } from "node:util/types";
|
2024-02-27 13:03:34 +00:00
|
|
|
|
|
|
|
const isCI = process.env.CI === "true";
|
2022-07-25 09:52:56 +00:00
|
|
|
|
|
|
|
export default defineConfig({
|
2024-02-27 13:03:34 +00:00
|
|
|
video: isCI,
|
2022-07-25 09:52:56 +00:00
|
|
|
projectId: "j4yhox",
|
|
|
|
chromeWebSecurity: false,
|
2024-06-07 16:05:03 +00:00
|
|
|
viewportWidth: 1920,
|
|
|
|
viewportHeight: 1200,
|
2022-07-25 09:52:56 +00:00
|
|
|
defaultCommandTimeout: 30000,
|
|
|
|
numTestsKeptInMemory: 30,
|
2023-02-10 10:10:35 +00:00
|
|
|
experimentalMemoryManagement: true,
|
2022-08-12 19:55:27 +00:00
|
|
|
|
2022-10-11 08:14:10 +00:00
|
|
|
retries: {
|
|
|
|
runMode: 3,
|
|
|
|
},
|
|
|
|
|
2022-07-25 09:52:56 +00:00
|
|
|
e2e: {
|
|
|
|
baseUrl: "http://localhost:8080",
|
|
|
|
slowTestThreshold: 30000,
|
|
|
|
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
|
2024-02-20 10:10:54 +00:00
|
|
|
setupNodeEvents(on, config) {
|
2024-10-10 10:10:54 +00:00
|
|
|
on("before:browser:launch", (browser, launchOptions) => {
|
|
|
|
if (browser.family === "firefox") {
|
|
|
|
// launchOptions.preferences is a map of preference names to values
|
|
|
|
// login is not working in firefox when testing_localhost_is_secure_when_hijacked is false
|
|
|
|
launchOptions.preferences[
|
|
|
|
"network.proxy.testing_localhost_is_secure_when_hijacked"
|
|
|
|
] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return launchOptions;
|
|
|
|
});
|
2024-05-13 08:34:35 +00:00
|
|
|
// after:spec collides with cypressSplit function below and is overridden there
|
|
|
|
|
|
|
|
function afterSpecRemoveSuccessfulVideos(spec, results) {
|
|
|
|
if (results?.video) {
|
2024-02-27 13:03:34 +00:00
|
|
|
// Do we have failures for any retry attempts?
|
|
|
|
const failures = results.tests.some((test) =>
|
|
|
|
test.attempts.some((attempt) => attempt.state === "failed"),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!failures) {
|
|
|
|
// delete the video if the spec passed and no tests retried
|
2024-05-15 10:37:50 +00:00
|
|
|
fs.rmSync(results.video, { force: true });
|
2024-02-27 13:03:34 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-13 08:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function chainedOn(event, callback) {
|
|
|
|
if (event === "after:spec") {
|
|
|
|
if (isAsyncFunction(callback)) {
|
|
|
|
on(event, async (spec, results) => {
|
|
|
|
afterSpecRemoveSuccessfulVideos(spec, results);
|
|
|
|
await callback(spec, results);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
on(event, (spec, results) => {
|
|
|
|
afterSpecRemoveSuccessfulVideos(spec, results);
|
|
|
|
callback(spec, results);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
on(event, callback);
|
|
|
|
}
|
|
|
|
}
|
2024-02-27 13:03:34 +00:00
|
|
|
|
2024-05-13 08:34:35 +00:00
|
|
|
cypressSplit(chainedOn, config);
|
2024-02-27 13:03:34 +00:00
|
|
|
|
2024-02-20 10:10:54 +00:00
|
|
|
return config;
|
|
|
|
},
|
2022-07-25 09:52:56 +00:00
|
|
|
},
|
|
|
|
});
|