Skip to content

Commit

Permalink
fix(cypress): rename screenshots with retries
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Feb 2, 2024
1 parent 070d380 commit 0bf532b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/cypress/src/task.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference types="cypress" />
import { UploadParameters, upload } from "@argos-ci/core";
import { basename, extname, join, dirname } from "node:path";
import { rename } from "node:fs/promises";

export type RegisterArgosTaskOptions = Omit<
UploadParameters,
Expand All @@ -17,6 +19,24 @@ export function registerArgosTask(
config: Cypress.Config,
options?: RegisterArgosTaskOptions,
) {
on("after:screenshot", async (details) => {
// Get the base filename without extension
const baseName = basename(details.path, extname(details.path));

// Remove attempt from the filename
const newBaseName = baseName.replace(/ \(attempt \d+\)/, "");

// Construct a new path with the original file extension
const newPath = join(
dirname(details.path),
newBaseName + extname(details.path),
);

// Rename the file
await rename(details.path, newPath);

return { path: newPath };
});
on("after:run", async () => {
const { screenshotsFolder } = config;
if (!screenshotsFolder) return;
Expand Down

0 comments on commit 0bf532b

Please sign in to comment.