-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests(): Start moving visual tests to playwright #9481
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3b8398a
fix the issue with the bug
asturur 01f3b04
update CHANGELOG.md
github-actions[bot] 3651a92
add tests for this specific case
asturur 535f84f
Merge branch 'master' into fix-initial-box-skew
asturur 8dac950
some progress
asturur c3e82e8
move visual rendering test to e2e
asturur bd099d8
move visual rendering test to e2e
asturur 9449a3e
proposal rendering visual tests
asturur 38b435e
Merge branch 'master' into create-tests-rendering-same-window
asturur 5487424
moved one level deeper
asturur 349734f
name the files
asturur cc005a9
changelog
asturur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I under this.
Do you want to create a new canvas for every test?
Why? What is the gain?
What about simply resizing the canvas before the test and adding a
canvas.clear()
after the snapshot call?Seems more straight forward, simpler and faster and can be exposed on the CanvasUtil.