-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(): Start moving visual tests to playwright (#9481)
- Loading branch information
Showing
12 changed files
with
890 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import setup from '../../../setup'; | ||
import { CanvasUtil } from '../../../utils/CanvasUtil'; | ||
import { TestingCanvas } from '../../../utils/createNodeSnapshot'; | ||
import { renderTests } from './renderingCases'; | ||
import * as fabric from 'fabric/node'; | ||
|
||
setup(); | ||
|
||
test('VISUAL RENDERING TESTS', async ({ page }, config) => { | ||
for (const testCase of renderTests) { | ||
if (testCase.disabled !== 'browser') { | ||
await test.step(`browser - ${testCase.title}`, async () => { | ||
// enable and disable this inside the loop | ||
config.config.updateSnapshots = 'missing'; | ||
await page.evaluate( | ||
(testTitle) => renderingTestMap.get(testTitle)(), | ||
testCase.title | ||
); | ||
expect( | ||
await new CanvasUtil(page).screenshot(), | ||
`browser snapshot` | ||
).toMatchSnapshot({ | ||
name: testCase.golden || `${testCase.title}.png`, | ||
maxDiffPixelRatio: testCase.percentage, | ||
}); | ||
}); | ||
} | ||
if (testCase.disabled !== 'node') { | ||
await test.step(`node - ${testCase.title}`, async () => { | ||
// we want the browser snapshot of a test to be committed and not the node snapshot | ||
config.config.updateSnapshots = 'none'; | ||
const canvas = new TestingCanvas(null, { | ||
enableRetinaScaling: false, | ||
renderOnAddRemove: false, | ||
width: testCase.size[0], | ||
height: testCase.size[1], | ||
}); | ||
await testCase.renderFunction(canvas, fabric); | ||
canvas.renderAll(); | ||
const buffer = await canvas.getNodeCanvas().toBuffer(); | ||
expect( | ||
buffer, | ||
`node snapshot should match browser snapshot` | ||
).toMatchSnapshot({ | ||
name: testCase.golden || `${testCase.title}.png`, | ||
maxDiffPixelRatio: testCase.percentage, | ||
}); | ||
}); | ||
} | ||
} | ||
}); |
Binary file added
BIN
+309 Bytes
e2e/tests/visual-output/rendering/index.spec.ts-snapshots/generic1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.75 KB
e2e/tests/visual-output/rendering/index.spec.ts-snapshots/polygonWithStroke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.3 KB
e2e/tests/visual-output/rendering/index.spec.ts-snapshots/polygonbboxWithSkew.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.07 KB
e2e/tests/visual-output/rendering/index.spec.ts-snapshots/shadownonscaling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+699 Bytes
e2e/tests/visual-output/rendering/index.spec.ts-snapshots/strokeNegativeScale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Runs in the **BROWSER** | ||
*/ | ||
|
||
import * as fabric from 'fabric'; | ||
import { renderTests } from './renderingCases'; | ||
import { beforeRenderTest } from '../../test'; | ||
|
||
beforeRenderTest( | ||
(canvas) => { | ||
const boundTests = renderTests.map((renderTest) => { | ||
return { | ||
boundFunction: async () => { | ||
canvas.clear(); | ||
canvas.setDimensions({ | ||
width: renderTest.size[0], | ||
height: renderTest.size[1], | ||
}); | ||
await renderTest.renderFunction(canvas, fabric); | ||
}, | ||
title: renderTest.title, | ||
}; | ||
}); | ||
return boundTests; | ||
}, | ||
{ | ||
enableRetinaScaling: false, | ||
} | ||
); |
Oops, something went wrong.