Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
9dbcc6d
step
ShaMan123 Jul 8, 2023
693ba03
Update text-editing.spec.ts
ShaMan123 Jul 8, 2023
31316ca
cute
ShaMan123 Jul 8, 2023
2d9c037
snapshots!
ShaMan123 Jul 8, 2023
885a85c
great
ShaMan123 Jul 8, 2023
5b92828
update CHANGELOG.md
github-actions[bot] Jul 8, 2023
dfcd4c8
beautiful
ShaMan123 Jul 8, 2023
5eedece
Merge branch 'test-playwright' of https://github.com/fabricjs/fabric.…
ShaMan123 Jul 8, 2023
da7004a
Update tests.yml
ShaMan123 Jul 8, 2023
a2d8bbe
Update tests.yml
ShaMan123 Jul 8, 2023
ad95201
Update tests.yml
ShaMan123 Jul 8, 2023
f696407
Update playwright.config.ts
ShaMan123 Jul 8, 2023
0f7264c
Update tests.yml
ShaMan123 Jul 8, 2023
eabe24c
Update tests.yml
ShaMan123 Jul 8, 2023
43f20be
update CHANGELOG.md
github-actions[bot] Jul 8, 2023
36aa953
Update playwright.config.ts
ShaMan123 Jul 14, 2023
7f1b2ee
Update tests.yml
ShaMan123 Jul 14, 2023
072be5d
Merge branch 'master' into test-playwright
ShaMan123 Jul 14, 2023
77d7bb7
Update tests.yml
ShaMan123 Jul 14, 2023
d1d6fa9
Update tests.yml
ShaMan123 Jul 14, 2023
28bfaa7
Update playwright.config.ts
ShaMan123 Jul 14, 2023
daf1846
coverage
ShaMan123 Jul 14, 2023
3f3b314
fix snapshot naming
ShaMan123 Jul 14, 2023
0b15bcd
Update .npmignore
ShaMan123 Jul 14, 2023
3a56887
Update text-editing.spec.ts
ShaMan123 Jul 14, 2023
f1d1b58
again
ShaMan123 Jul 14, 2023
1676c42
Update tests.yml
ShaMan123 Jul 14, 2023
ce5d820
fix coverage reporting
ShaMan123 Jul 14, 2023
bb8b5e4
try cache playwright browsers
ShaMan123 Jul 14, 2023
ea51a06
Update tests.yml
ShaMan123 Jul 14, 2023
d76c5b6
update CHANGELOG.md
github-actions[bot] Jul 14, 2023
7a8ae28
perf(): install only chromium
ShaMan123 Jul 14, 2023
cd2f566
cache playwright browsers
ShaMan123 Jul 14, 2023
92e58eb
update CHANGELOG.md
github-actions[bot] Jul 14, 2023
ac351ad
perf(): install only chromium
ShaMan123 Jul 14, 2023
042bc8e
Update tests.yml
ShaMan123 Jul 14, 2023
15e8f86
Merge branch 'test-playwright' of https://github.com/fabricjs/fabric.…
ShaMan123 Jul 14, 2023
203a8bc
extract methods for reuse
ShaMan123 Jul 16, 2023
9e72d8e
Update playwright.config.ts
ShaMan123 Jul 16, 2023
a3ac0d6
Create startVanillaApp.ts
ShaMan123 Jul 16, 2023
948874b
Create setupApp.ts
ShaMan123 Jul 16, 2023
484544b
Update setupApp.ts
ShaMan123 Jul 16, 2023
32406ca
Update package.json
ShaMan123 Jul 16, 2023
9135347
config
ShaMan123 Jul 16, 2023
a03f22c
feat(): allow vanilla app in tests
ShaMan123 Jul 16, 2023
b1927e3
Revert "extract methods for reuse"
ShaMan123 Jul 16, 2023
ab7c15a
progress
ShaMan123 Jul 16, 2023
90aabcc
point
ShaMan123 Jul 16, 2023
056170a
progress
ShaMan123 Jul 16, 2023
98c5a13
rename
ShaMan123 Jul 16, 2023
40e0f0f
Update tsconfig.json
ShaMan123 Jul 16, 2023
66f8d7d
Update index.html
ShaMan123 Jul 16, 2023
4d56f0f
Update setupTest.ts
ShaMan123 Jul 16, 2023
a76d408
fix race condition
ShaMan123 Jul 16, 2023
614ba02
mv
ShaMan123 Jul 16, 2023
524f3c1
stable
ShaMan123 Jul 16, 2023
696c766
cleanup
ShaMan123 Jul 16, 2023
a47d078
Update setupCoverage.ts
ShaMan123 Jul 16, 2023
8bd78b3
Merge branch 'master' into test-playwright
ShaMan123 Jul 16, 2023
40e91b2
Update setupApp.ts
ShaMan123 Jul 16, 2023
e61db33
Update tsconfig.json
ShaMan123 Jul 16, 2023
0892b4c
finalize hopefully
ShaMan123 Jul 16, 2023
69b1d2c
watch mode
ShaMan123 Jul 16, 2023
ef3d685
Update setupCoverage.ts
ShaMan123 Jul 16, 2023
a47e09f
template
ShaMan123 Jul 16, 2023
7a0da31
body
ShaMan123 Jul 17, 2023
7e806d4
selectors
ShaMan123 Jul 17, 2023
2048de7
multiple canvas init
ShaMan123 Jul 17, 2023
fe6d6d7
Update setupTest.ts
ShaMan123 Jul 17, 2023
562b234
Update playwright.config.ts
ShaMan123 Jul 17, 2023
acd274d
run CI in headed mode
ShaMan123 Jul 17, 2023
c1222e6
mv
ShaMan123 Jul 17, 2023
8cef2bf
comments
ShaMan123 Jul 17, 2023
5d49b4c
cleanup
ShaMan123 Jul 17, 2023
3fba4c3
Update index.ts
ShaMan123 Jul 17, 2023
78cc1ee
Update index.ts
ShaMan123 Jul 17, 2023
3e38676
extract
ShaMan123 Jul 17, 2023
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
17 changes: 14 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ jobs:
- name: Build fabric.js
uses: ./.github/actions/build-fabric-cached
- name: Run ${{ matrix.target }} ${{ matrix.suite }} headless test
uses: coactions/setup-xvfb@v1
with:
run: npm run test -- -c ${{ matrix.target }} -s ${{ matrix.suite }}
run: xvfb-run npm run test -- -c ${{ matrix.target }} -s ${{ matrix.suite }}
node:
needs: [prime-build]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -109,6 +107,19 @@ jobs:
with:
name: coverage-jest
path: .nyc_output/*.json
e2e:
needs: [prime-build]
name: Playwright tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cached-install
- name: Build fabric.js
uses: ./.github/actions/build-fabric-cached
- name: Run playwright tests
run: |
npx playwright install
xvfb-run npm run test:e2e
coverage:
needs: [node-coverage]
name: Coverage reporting
Expand Down
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]

- test(playwright): add snapshots, refactor utils [#9078](https://github.com/fabricjs/fabric.js/pull/9078)
- chore(TS): Fix ITextBehaviour enterEditing type [#9075](https://github.com/fabricjs/fabric.js/pull/9075)
- chore(TS): export FabricObjectProps and GroupProps [#9025](https://github.com/fabricjs/fabric.js/pull/9025)
- chore(TS): Replace BaseFabricObject with FabricObject [#9016](https://github.com/fabricjs/fabric.js/pull/9016)
Expand Down
75 changes: 55 additions & 20 deletions e2e/tests/text/text-editing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { test } from '@playwright/test';
import {
addTextbox,
getObjectCenter,
clickCanvas,
getObjectControlPoint,
} from '../../utils/objects';
test('text typing itext vs textbox', async ({ page }) => {
import { expect, test } from '@playwright/test';
import { TestUtil } from '../../utils/TestUtil';

test('textbox typing and resizing', async ({ page }) => {
const util = new TestUtil(page);
await page.goto('http://127.0.0.1:8080/e2e/site');
const textboxID = 'text1';
await addTextbox(page, textboxID, 'initial text', {
const textboxUtil = await util.addTextbox('initial text', {
width: 200,
left: 50,
});
const textCenter = await getObjectCenter(page, textboxID);
await clickCanvas(page, {
const textCenter = await textboxUtil.getObjectCenter();

expect(await page.screenshot()).toMatchSnapshot({ name: 'initial.png' });

await util.clickCanvas({
position: textCenter,
clickCount: 2,
delay: 200,
});

expect(await page.screenshot()).toMatchSnapshot({ name: 'start.png' });

await page
.locator('textarea')
.type(
Expand All @@ -28,26 +29,60 @@ test('text typing itext vs textbox', async ({ page }) => {
}
);

const controlPoint = await getObjectControlPoint(page, textboxID, 'mr');
expect(await page.screenshot()).toMatchSnapshot({ name: 'typed.png' });

const mrControlPoint = await textboxUtil.getObjectControlPoint('mr');

// click outside to stop editing
await clickCanvas(page, {
await util.clickCanvas({
position: {
x: controlPoint.x + 20,
y: controlPoint.y,
x: mrControlPoint.x + 20,
y: mrControlPoint.y,
},
clickCount: 1,
delay: 200,
});
expect(await page.screenshot()).toMatchSnapshot({ name: 'exit_editing.png' });

// click the object to select it
await clickCanvas(page, {
await util.clickCanvas({
position: textCenter,
});

// drag the control
await page.mouse.move(controlPoint.x, controlPoint.y);
// drag the mr control
await page.mouse.move(mrControlPoint.x, mrControlPoint.y);
await page.mouse.down();
await page.mouse.move(mrControlPoint.x + 300, mrControlPoint.y, {
steps: 40,
});
expect(await page.screenshot()).toMatchSnapshot({
name: 'increase_width_mr.png',
});
// drag in the opposite direction
await page.mouse.move(mrControlPoint.x - 300, mrControlPoint.y, {
steps: 60,
});
await page.mouse.up();
expect(await page.screenshot()).toMatchSnapshot({
name: 'decrease_width_mr.png',
});

// drag the ml control
const mlControlPoint = await textboxUtil.getObjectControlPoint('ml');
await page.mouse.move(mlControlPoint.x, mlControlPoint.y);
await page.mouse.down();
await page.mouse.move(controlPoint.x + 300, controlPoint.y, { steps: 40 });
await page.mouse.move(mlControlPoint.x - 300, mlControlPoint.y, {
steps: 40,
});
expect(await page.screenshot()).toMatchSnapshot({
name: 'increase_width_ml.png',
});
// drag in the opposite direction
await page.mouse.move(mlControlPoint.x + 300, mlControlPoint.y, {
steps: 60,
});
await page.mouse.up();
expect(await page.screenshot()).toMatchSnapshot({
name: 'decrease_width_ml.png',
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions e2e/utils/ObjectUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Page, expect } from '@playwright/test';
import type { Canvas, Object as FabricObject } from '../..';

export class ObjectUtil {
constructor(readonly objectId: string, readonly page: Page) {}

executeInBrowser<C, R>(
runInBrowser: (
context: Omit<C, 'objectId'> & {
object: FabricObject;
canvas: Canvas;
}
) => R,
context?: C
): Promise<R> {
return this.page.evaluate(
({ objectId, runInBrowser, ...context }) => {
return eval(runInBrowser)({
object:
objectId &&
fabricCanvas.getObjects().find((obj) => obj.id === objectId),
canvas: fabricCanvas,
...context,
});
},
{
...context,
objectId: this.objectId,
runInBrowser: runInBrowser.toString(),
}
);
}

getObjectCenter() {
return this.executeInBrowser(({ object }) => object.getCenterPoint());
}

getObjectControlPoint(controlName: string) {
return this.executeInBrowser(
({ object, controlName }) => object.oCoords[controlName],
{ controlName }
);
}

async expectObjectToMatch<T extends Record<string, unknown>>(expected: T) {
const snapshot = await this.executeInBrowser(({ object }) => object);
expect(snapshot).toMatchObject(expected);
}
}
29 changes: 29 additions & 0 deletions e2e/utils/TestUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Page } from '@playwright/test';
import { ObjectUtil } from './ObjectUtil';

let ID = 0;
const uuid = () => `test${ID++}`;

export class TestUtil {
constructor(readonly page: Page) {}

clickCanvas(clickProperties: Parameters<Page['click']>[1]) {
return this.page.click('canvas.upper-canvas', clickProperties);
}

async addTextbox(text: string, properties) {
const id = uuid();
await this.page.evaluate(
({ id, text, ...properties }) => {
const textbox = new fabric.Textbox(text, {
...properties,
id,
});
fabricCanvas.add(textbox);
return id;
},
{ id, text, ...properties }
);
return new ObjectUtil(id, this.page);
}
}
36 changes: 0 additions & 36 deletions e2e/utils/objects.ts

This file was deleted.

1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const config: PlaywrightTestConfig = {
name: 'chromium',
use: {
...devices['Desktop Chrome'],
browserName: 'chromium',
},
},
],
Expand Down