Skip to content

Commit f6ce353

Browse files
committed
BREAKING CHANGE: browserType replaced with browserName. Added support for @playwright/test
1 parent 3077fff commit f6ce353

File tree

6 files changed

+2852
-2714
lines changed

6 files changed

+2852
-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: 9 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;
@@ -25,6 +26,7 @@ const config: Config = {
2526
project: "Default project",
2627
apiKey: "BAZ0EG0PRH4CRQPH19ZKAVADBP9E",
2728
enableSoftAssert: false,
29+
browserName: "chrome",
2830
};
2931

3032
beforeAll(async () => {
@@ -44,11 +46,11 @@ afterAll(async () => {
4446

4547
describe("playwright", () => {
4648
beforeEach(() => {
47-
playwrightVrt = new PlaywrightVisualRegressionTracker(browserType, config);
49+
playwrightVrt = new PlaywrightVisualRegressionTracker(browserName, config);
4850
});
4951

5052
it("constructor", async () => {
51-
expect(playwrightVrt["browser"]).toBe(browserType.name());
53+
expect(playwrightVrt["browser"]).toBe(browserName);
5254
expect(VisualRegressionTracker).toHaveBeenCalledWith(config);
5355
});
5456

@@ -111,7 +113,7 @@ describe("playwright", () => {
111113
expect(VisualRegressionTracker.prototype.track).toHaveBeenCalledWith({
112114
name: imageName,
113115
imageBase64: screenshot.toString("base64"),
114-
browser: browserType.name(),
116+
browser: browserName,
115117
viewport: `1800x1600`,
116118
os: trackOptions.agent?.os,
117119
device: trackOptions.agent?.device,
@@ -130,7 +132,7 @@ describe("playwright", () => {
130132
expect(VisualRegressionTracker.prototype.track).toHaveBeenCalledWith({
131133
name: imageName,
132134
imageBase64: screenshot.toString("base64"),
133-
browser: browserType.name(),
135+
browser: browserName,
134136
viewport: undefined,
135137
os: undefined,
136138
device: undefined,
@@ -181,7 +183,7 @@ describe("playwright", () => {
181183
expect(VisualRegressionTracker.prototype.track).toHaveBeenCalledWith({
182184
name: imageName,
183185
imageBase64: screenshot.toString("base64"),
184-
browser: browserType.name(),
186+
browser: browserName,
185187
viewport: trackOptions.agent?.viewport,
186188
os: trackOptions.agent?.os,
187189
device: trackOptions.agent?.device,
@@ -205,7 +207,7 @@ describe("playwright", () => {
205207
expect(VisualRegressionTracker.prototype.track).toHaveBeenCalledWith({
206208
name: imageName,
207209
imageBase64: screenshot.toString("base64"),
208-
browser: browserType.name(),
210+
browser: browserName,
209211
viewport: undefined,
210212
os: undefined,
211213
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)