Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

111 attempts in the name of the screenshot on cypress sdk #115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/cypress/src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Cypress.Commands.add(
test: {
title: Cypress.currentTest.title,
titlePath: Cypress.currentTest.titlePath,
retry: Cypress.currentRetry,
// @ts-ignore
retries: cy.state("runnable")._retries,
},
browser: {
name: Cypress.browser.name,
Expand Down
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
Loading