Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- chore(): update playwright [#10780](https://github.com/fabricjs/fabric.js/pull/10780)
- chore(): up dev deps [#10773](https://github.com/fabricjs/fabric.js/pull/10773)
- chore(): up deps [#10771](https://github.com/fabricjs/fabric.js/pull/10771)
- chore(): remove moment dev dependency [#10770](https://github.com/fabricjs/fabric.js/pull/10770)
Expand Down
32 changes: 20 additions & 12 deletions e2e/utils/CanvasUtil.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import type { JSHandle } from '@playwright/test';
import type { PageFunctionOn } from 'playwright-core/types/structs';
import type { LocatorScreenshotOptions, Page } from '@playwright/test';
import type {
JSHandle,
LocatorScreenshotOptions,
Page,
} from '@playwright/test';
import type { Canvas, XY } from 'fabric';
import os from 'node:os';
import type { ObjectUtil } from './ObjectUtil';
import * as fabric from 'fabric';

export class CanvasUtil {
executeInBrowser: JSHandle<Canvas>['evaluate'];
evaluateHandle: JSHandle<Canvas>['evaluateHandle'];

constructor(
readonly page: Page,
readonly selector = '#canvas',
) {}
) {
this.executeInBrowser = this._executeInBrowserImpl.bind(this);
this.evaluateHandle = this._evaluateHandleImpl.bind(this);
}

click(clickProperties: Parameters<Page['click']>[1]) {
return this.page.click(`canvas_top=${this.selector}`, clickProperties);
Expand Down Expand Up @@ -84,17 +92,17 @@ export class CanvasUtil {
);
}

async executeInBrowser<C, R>(
runInBrowser: PageFunctionOn<Canvas, C, R>,
context: C,
): Promise<R> {
private async _executeInBrowserImpl(
runInBrowser: any,
context?: any,
): Promise<any> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i see. This will be hard to remember in a month or two why is in this way. Let me think if some ts notation is a bit better for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wrote on the issue I opened in playwright that i dislike this approach they suggested
first I had it with just copying the type manually
but I am not sure which one approach is worse

lets see if they reexport the type again, if not then you will have to decide on how to proceed
but in any case, just slapping any type I think is the least optimal solution

return (await this.evaluateSelf()).evaluate(runInBrowser, context);
}

async evaluateHandle<C, R>(
runInBrowser: PageFunctionOn<Canvas, C, R>,
context: C,
): Promise<JSHandle<R>> {
private async _evaluateHandleImpl(
runInBrowser: any,
context?: any,
): Promise<any> {
return (await this.evaluateSelf()).evaluateHandle(runInBrowser, context);
}
}
25 changes: 15 additions & 10 deletions e2e/utils/ObjectUtil.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import type { JSHandle, Page } from '@playwright/test';
import { expect } from '@playwright/test';
import type { FabricObject } from 'fabric';
import type { PageFunctionOn } from 'playwright-core/types/structs';

export class ObjectUtil<T extends FabricObject = FabricObject> {
executeInBrowser: JSHandle<T>['evaluate'];
evaluateHandle: JSHandle<T>['evaluateHandle'];

constructor(
readonly page: Page,
/**
* the key matching the a key returned from the {@link beforeAll} or {@link before} callback
*/
readonly objectId: string,
) {}
) {
this.executeInBrowser = this._executeInBrowserImpl.bind(this);
this.evaluateHandle = this._evaluateHandleImpl.bind(this);
}

evaluateSelf() {
return this.page.evaluateHandle(
Expand All @@ -19,17 +24,17 @@ export class ObjectUtil<T extends FabricObject = FabricObject> {
);
}

async executeInBrowser<C, R>(
runInBrowser: PageFunctionOn<T, C, R>,
context: C,
): Promise<R> {
private async _executeInBrowserImpl(
runInBrowser: any,
context?: any,
): Promise<any> {
return (await this.evaluateSelf()).evaluate(runInBrowser, context);
}

async evaluateHandle<C, R>(
runInBrowser: PageFunctionOn<T, C | undefined, R>,
context?: C,
): Promise<JSHandle<R>> {
private async _evaluateHandleImpl(
runInBrowser: any,
context?: any,
): Promise<any> {
return (await this.evaluateSelf()).evaluateHandle(runInBrowser, context);
}

Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@babel/preset-env": "^7.28.3",
"@babel/preset-typescript": "^7.27.1",
"@eslint/js": "^9.37.0",
"@playwright/test": "^1.55.0",
"@playwright/test": "^1.56.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-terser": "^0.4.4",
Expand Down
Loading