Skip to content

Commit 0a0e8e6

Browse files
committed
feat: add typings
1 parent 4d5288c commit 0a0e8e6

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"sideEffects": false,
88
"license": "MIT",
99
"scripts": {
10-
"build": "del-cli dist && microbundle src/*.ts -f cjs,esm",
10+
"build": "del-cli dist && microbundle src/{constants,plugin,support}.ts -f cjs,esm",
1111
"lint": "eslint '**/*.ts' --ignore-pattern '**/*.d.ts'",
1212
"lint.fix": "yarn lint --fix",
1313
"lint.ci": "yarn lint --max-warnings 0",

src/commands.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
import { FILE_SUFFIX, LINK_PREFIX, TASK } from "./constants";
22
import type pixelmatch from "pixelmatch";
33

4+
declare global {
5+
// eslint-disable-next-line @typescript-eslint/no-namespace
6+
namespace Cypress {
7+
type MatchImageOptions = {
8+
suffix?: string;
9+
screenshotConfig?: Partial<Cypress.ScreenshotDefaultsOptions>;
10+
diffConfig?: Parameters<typeof pixelmatch>[5];
11+
};
12+
13+
interface Chainable {
14+
/**
15+
* Command to create and compare image snapshots.
16+
* @memberof Cypress.Chainable
17+
* @example cy.get('.my-element').matchImage();
18+
*/
19+
matchImage<T extends Chainable<unknown>>(this: T, options?: Cypress.MatchImageOptions): T;
20+
}
21+
}
22+
}
23+
424
const nameCacheCounter: Record<string, number> = {};
525

626
Cypress.Commands.add(
727
"matchImage",
828
{ prevSubject: "optional" },
929
(
1030
subject?: JQuery<HTMLElement>,
11-
options: {
12-
suffix?: string;
13-
screenshotConfig?: Partial<Cypress.ScreenshotDefaultsOptions>;
14-
diffConfig?: Parameters<typeof pixelmatch>[5];
15-
} = {}
31+
options: Cypress.MatchImageOptions = {}
1632
) => {
1733
let title = Cypress.currentTest.titlePath.join(" ");
1834
if (typeof nameCacheCounter[title] === "undefined")
@@ -31,8 +47,10 @@ Cypress.Commands.add(
3147
let imgPath: string;
3248
return (subject ? cy.wrap(subject) : cy)
3349
.screenshot(screenshotPath as string, {
34-
onAfterScreenshot(_el, props) {
50+
...options.screenshotConfig,
51+
onAfterScreenshot(el, props) {
3552
imgPath = props.path;
53+
options.screenshotConfig?.onAfterScreenshot?.(el, props);
3654
},
3755
})
3856
.then(() => imgPath);

src/support.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './commands';
12
import { FILE_SUFFIX, LINK_PREFIX, OVERLAY_CLASS, TASK } from "./constants";
23

34
function generateOverlayTemplate(

0 commit comments

Comments
 (0)