Only store videos of failed Cypress tests
`cypressSplit` function overrides the `after:spec` trigger which is used for removing videos of successful tests. Fixes: #29471 Signed-off-by: Hynek Mlnarik <hmlnarik@redhat.com>
This commit is contained in:
parent
d8a7773947
commit
7daa2a0471
1 changed files with 25 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { defineConfig } from "cypress";
|
import { defineConfig } from "cypress";
|
||||||
import cypressSplit from "cypress-split";
|
import cypressSplit from "cypress-split";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
|
import { isAsyncFunction } from "node:util/types";
|
||||||
|
|
||||||
const isCI = process.env.CI === "true";
|
const isCI = process.env.CI === "true";
|
||||||
|
|
||||||
|
@ -23,8 +24,10 @@ export default defineConfig({
|
||||||
slowTestThreshold: 30000,
|
slowTestThreshold: 30000,
|
||||||
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
|
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
|
||||||
setupNodeEvents(on, config) {
|
setupNodeEvents(on, config) {
|
||||||
on("after:spec", (spec, results) => {
|
// after:spec collides with cypressSplit function below and is overridden there
|
||||||
if (results.video) {
|
|
||||||
|
function afterSpecRemoveSuccessfulVideos(spec, results) {
|
||||||
|
if (results?.video) {
|
||||||
// Do we have failures for any retry attempts?
|
// Do we have failures for any retry attempts?
|
||||||
const failures = results.tests.some((test) =>
|
const failures = results.tests.some((test) =>
|
||||||
test.attempts.some((attempt) => attempt.state === "failed"),
|
test.attempts.some((attempt) => attempt.state === "failed"),
|
||||||
|
@ -35,9 +38,27 @@ export default defineConfig({
|
||||||
fs.unlinkSync(results.video);
|
fs.unlinkSync(results.video);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
cypressSplit(on, config);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cypressSplit(chainedOn, config);
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue