Skip to content

Feature/title option #81

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

Merged
merged 3 commits into from
Aug 9, 2022
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ cy.matchImage({
// helps with screenshots being scaled 2x on high-density screens like Mac Retina
// default: true
forceDeviceScaleFactor: false,
// title used for naming the image file
// default: Cypress.currentTest.titlePath (your test title)
title: `${Cypress.currentTest.titlePath.join(' ')} (${Cypress.browser.displayName})`
})
```

Expand Down
3 changes: 2 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare global {
updateImages?: boolean;
imagesDir?: string;
maxDiffThreshold?: number;
title?: string;
};

interface Chainable<Subject> {
Expand All @@ -30,7 +31,7 @@ Cypress.Commands.add(
{ prevSubject: "optional" },
(subject, options = {}) => {
const $el = subject as JQuery<HTMLElement> | undefined;
let title = Cypress.currentTest.titlePath.join(" ");
let title = options.title || Cypress.currentTest.titlePath.join(" ");
if (typeof nameCacheCounter[title] === "undefined")
nameCacheCounter[title] = -1;
title += ` #${++nameCacheCounter[title]}`;
Expand Down