Skip to content
Merged
Show file tree
Hide file tree
Changes from 65 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
2 changes: 1 addition & 1 deletion .codesandbox/templates/vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"@parcel/transformer-typescript-tsc": "^2.7.0",
"open-cli": "^7.0.1",
"parcel": "^2.7.0",
"parcel": "^2.9.3",
"typescript": "^5.0.2"
},
"keywords": [
Expand Down
35 changes: 31 additions & 4 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,8 +107,33 @@ 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
# Playwright suggests against caching the browser install
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium
- name: Run Playwright tests
run: npx playwright test
- name: Upload Test Output
uses: actions/upload-artifact@v3
if: failure()
with:
name: e2e-report
path: ./e2e/test-report/
- name: Upload test coverage
uses: actions/upload-artifact@v3
with:
name: coverage-e2e
path: ./e2e/test-results/**/coverage.json
coverage:
needs: [node-coverage]
needs: [node-coverage, e2e]
name: Coverage reporting
runs-on: ubuntu-latest
steps:
Expand All @@ -127,6 +150,10 @@ jobs:
with:
name: coverage-visual
path: .nyc_output
- uses: actions/download-artifact@v3
with:
name: coverage-e2e
path: .nyc_output
- run: ls -l .nyc_output
- run: npm run coverage:report
- uses: ShaMan123/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ change-output.md
before_commit
/coverage/
.idea/
/dist
**/dist
/cli_output/
e2e/test-report/
e2e/test-results/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lib/*.png
coverage/
test/
test*
e2e/
.DS_Store
.codesandbox/
.devcontainer/
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, coverage [#9078](https://github.com/fabricjs/fabric.js/pull/9078)
- chore(TS) Add type-checking to files excluded with ts-nocheck ( Parser mostly ) [#9085](https://github.com/fabricjs/fabric.js/pull/9085)
- test(Text): Add some tests for text in Jest [#9083](https://github.com/fabricjs/fabric.js/pull/9083)
- ci(): Install system deps only when necessary [#9086](https://github.com/fabricjs/fabric.js/pull/9086)
Expand Down
12 changes: 12 additions & 0 deletions e2e/imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { readJSONSync } from 'fs-extra';

/**
* The import map used by `./utils/setupApp` to inject into the page
* so test scripts can use modules (relative imports don't seem to work out of the box)
*
* **IMPORTANT**: be sure to update the paths field in `./tsconfig.json` to reflect imports correctly
*/
export default {
fabric: readJSONSync('./package.json').module.slice(1),
test: '/e2e/dist/test.js',
};
Binary file added e2e/site/favicon.ico
Binary file not shown.
18 changes: 6 additions & 12 deletions e2e/site/index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
<html>
<head>
<script type="text/javascript" src="/dist/index.js"></script>
<title>Fabric e2e Testing Suite</title>
<link rel="icon" type="image/x-icon" href="./favicon.ico" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to silence playwright raising an error

<style>
body {
padding: 0;
margin: 0;
background-color: black;
}
.canvas-container {
border: 1px solid black;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

was causing snapshot size mismatch

[data-fabric='wrapper'] {
background-color: white;
}
</style>
</head>
<body>
<canvas id="test-canvas" width="800" height="600"></canvas>
<canvas id="canvas" width="800" height="600"></canvas>
</body>
<script type="text/javascript">
const fabricCanvas = new fabric.Canvas(
document.getElementById('test-canvas'),
{ enableRetinaScaling: false }
);
window.fabricCanvas = fabricCanvas;
window.setupScene = (json) => fabricCanvas.loadFromJSON(json);
</script>
</html>
8 changes: 8 additions & 0 deletions e2e/tests/template/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test } from '@playwright/test';
import { TestUtil } from '../../utils/TestUtil';
import '../../utils/setupTest';

test('TEST NAME', async ({ page }) => {
const util = new TestUtil(page);
// write the test
});
18 changes: 18 additions & 0 deletions e2e/tests/template/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Runs in the **BROWSER**
* Use absolute imports defined in '../imports.ts'
*/

import * as fabric from 'fabric';
import { beforeAll } from 'test';

beforeAll((canvas) => {
const textbox = new fabric.Textbox('fabric.js test', {
width: 200,
top: 20,
});
canvas.add(textbox);
canvas.centerObjectH(textbox);

return { textbox };
});
34 changes: 34 additions & 0 deletions e2e/tests/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Runs from the BROWSER context
*/

import type { Object as FabricObject } from 'fabric';
import { Canvas } from 'fabric';

type Targets = Record<string, FabricObject>;

/**
* Call this method **once**
*/
export async function beforeAll(
/**
* @returns a map of {@link FabricObject} for playwright to access during tests
*/
cb: (canvas: Canvas) => Targets | Promise<Targets> | void,
options?
) {
const canvas = new Canvas(document.getElementById('canvas'), options);
window.canvas = canvas;
window.targets = (await cb(canvas)) || {};
window.dispatchEvent(new CustomEvent('setup:completed'));
}

/**
* Call this method **once**
*/
export async function afterAll(cb: (canvas: Canvas) => void | Promise<void>) {
window.__teardown = async () => {
await cb(window.canvas);
window.dispatchEvent(new CustomEvent('teardown:completed'));
};
}
53 changes: 0 additions & 53 deletions e2e/tests/text/text-editing.spec.ts

This file was deleted.

86 changes: 86 additions & 0 deletions e2e/tests/text/text-editing/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { expect, test } from '@playwright/test';
import { ObjectUtil } from '../../../utils/ObjectUtil';
import { TestUtil } from '../../../utils/TestUtil';
import '../../../utils/setupTest';

test('textbox typing and resizing', async ({ page }) => {
const util = new TestUtil(page);
const textboxUtil = new ObjectUtil('textbox', page);
const textCenter = await textboxUtil.getObjectCenter();

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

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

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

await page
.locator('textarea')
.type(
'insert text in a textbox from the keyboard will wrap text on current textbox width',
{
// delay: 160,
}
);

expect(await util.screenshot()).toMatchSnapshot({ name: 'typed.png' });

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

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

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

// 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 util.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 util.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(mlControlPoint.x - 300, mlControlPoint.y, {
steps: 40,
});
expect(await util.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 util.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.
9 changes: 9 additions & 0 deletions e2e/tests/text/text-editing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Textbox } from 'fabric';
import { beforeAll } from 'test';

beforeAll((canvas) => {
const textbox = new Textbox('initial text', { width: 200, left: 50 });
canvas.add(textbox);

return { textbox };
});
15 changes: 15 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"sourceMap": true,
"outDir": "./dist",
"allowSyntheticDefaultImports": true,
/**
* A reflection of the configured imports used by test scripts
* **IMPORTANT**: be sure to keep this updated to reflect `./imports.ts` correctly
*/
"paths": { "fabric": ["../dist"], "test": ["./tests/test.ts"] }
}
}
Loading