Skip to content

Commit 9fc513a

Browse files
authored
Merge pull request #97 from Visual-Regression-Tracker/94-playwright/test
BREAKING CHANGE: `browserType` replaced with `browserName`. Added support for `@playwright/test`
2 parents 3077fff + dbfe40d commit 9fc513a

File tree

6 files changed

+2851
-2714
lines changed

6 files changed

+2851
-2714
lines changed

lib/playwright.interfaces.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ export interface Agent {
6262
viewport?: string;
6363
}
6464

65-
export interface PageTrackOptions {
65+
interface BaseTrackOptions {
6666
diffTollerancePercent?: number;
6767
ignoreAreas?: IgnoreArea[];
68-
screenshotOptions?: PageScreenshotOptions;
6968
agent?: Agent;
7069
}
7170

72-
export interface ElementHandleTrackOptions {
73-
diffTollerancePercent?: number;
74-
ignoreAreas?: IgnoreArea[];
71+
export interface PageTrackOptions extends BaseTrackOptions {
72+
screenshotOptions?: PageScreenshotOptions;
73+
}
74+
75+
export interface ElementHandleTrackOptions extends BaseTrackOptions {
7576
screenshotOptions?: ElementHandleScreenshotOptions;
76-
agent?: Agent;
7777
}

lib/playwrightVisualRegressionTracker.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import {
77
PlaywrightVisualRegressionTracker,
88
PageTrackOptions,
99
ElementHandleTrackOptions,
10-
} from ".";
10+
} from "./index";
1111
import { mocked } from "ts-jest/utils";
1212
import { MaybeMocked } from "ts-jest/dist/utils/testing";
1313

1414
jest.mock("@visual-regression-tracker/sdk-js");
1515

16+
let browserName = chromium.name();
1617
let browserType = chromium;
1718
let browser: Browser;
1819
let context: BrowserContext;
@@ -44,11 +45,11 @@ afterAll(async () => {
4445

4546
describe("playwright", () => {
4647
beforeEach(() => {
47-
playwrightVrt = new PlaywrightVisualRegressionTracker(browserType, config);
48+
playwrightVrt = new PlaywrightVisualRegressionTracker(browserName, config);
4849
});
4950

5051
it("constructor", async () => {
51-
expect(playwrightVrt["browser"]).toBe(browserType.name());
52+
expect(playwrightVrt["browser"]).toBe(browserName);
5253
expect(VisualRegressionTracker).toHaveBeenCalledWith(config);
5354
});
5455

@@ -111,7 +112,7 @@ describe("playwright", () => {
111112
expect(VisualRegressionTracker.prototype.track).toHaveBeenCalledWith({
112113
name: imageName,
113114
imageBase64: screenshot.toString("base64"),
114-
browser: browserType.name(),
115+
browser: browserName,
115116
viewport: `1800x1600`,
116117
os: trackOptions.agent?.os,
117118
device: trackOptions.agent?.device,
@@ -130,7 +131,7 @@ describe("playwright", () => {
130131
expect(VisualRegressionTracker.prototype.track).toHaveBeenCalledWith({
131132
name: imageName,
132133
imageBase64: screenshot.toString("base64"),
133-
browser: browserType.name(),
134+
browser: browserName,
134135
viewport: undefined,
135136
os: undefined,
136137
device: undefined,
@@ -181,7 +182,7 @@ describe("playwright", () => {
181182
expect(VisualRegressionTracker.prototype.track).toHaveBeenCalledWith({
182183
name: imageName,
183184
imageBase64: screenshot.toString("base64"),
184-
browser: browserType.name(),
185+
browser: browserName,
185186
viewport: trackOptions.agent?.viewport,
186187
os: trackOptions.agent?.os,
187188
device: trackOptions.agent?.device,
@@ -205,7 +206,7 @@ describe("playwright", () => {
205206
expect(VisualRegressionTracker.prototype.track).toHaveBeenCalledWith({
206207
name: imageName,
207208
imageBase64: screenshot.toString("base64"),
208-
browser: browserType.name(),
209+
browser: browserName,
209210
viewport: undefined,
210211
os: undefined,
211212
device: undefined,

lib/playwrightVisualRegressionTracker.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
VisualRegressionTracker,
3-
Config,
43
BuildResponse,
4+
Config,
55
} from "@visual-regression-tracker/sdk-js";
6-
import { Page, Browser, BrowserType, ElementHandle } from "playwright";
6+
import { Page, ElementHandle } from "playwright";
77
import {
88
PageTrackOptions,
99
ElementHandleTrackOptions,
@@ -13,9 +13,9 @@ export class PlaywrightVisualRegressionTracker {
1313
private vrt: VisualRegressionTracker;
1414
private browser: string;
1515

16-
constructor(browserType: BrowserType<Browser>, config?: Config) {
16+
constructor(browserName: string, config?: Config) {
1717
this.vrt = new VisualRegressionTracker(config);
18-
this.browser = browserType.name();
18+
this.browser = browserName;
1919
}
2020

2121
async start(): Promise<BuildResponse> {
@@ -26,7 +26,11 @@ export class PlaywrightVisualRegressionTracker {
2626
return this.vrt.stop();
2727
}
2828

29-
async trackPage(page: Page, name: string, options?: PageTrackOptions) {
29+
async trackPage(
30+
page: Pick<Page, "viewportSize" | "screenshot">,
31+
name: string,
32+
options?: PageTrackOptions
33+
) {
3034
const viewportSize = page.viewportSize();
3135
return this.vrt.track({
3236
name,

0 commit comments

Comments
 (0)