Skip to content
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

Adds Error message for when there are no screenshots #6773

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 26 additions & 0 deletions contributor_docs/unit_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,29 @@ If you need to add a new test file, add it to that folder, then add the filename
When you add a new test, running `npm test` will generate new screenshots for any visual tests that do not yet have them. Those screenshots will then be used as a reference the next time tests run to make sure the sketch looks the same. If a test intentionally needs to look different, you can delete the folder matching the test name in the `test/unit/visual/screenshots` folder, and then re-run `npm test` to generate a new one.

To manually inspect all visual tests, run `grunt yui:dev` to launch a local server, then go to http://127.0.0.1:9001/test/visual.html to see a list of all test cases.


In a continuous integration (CI) environment, optimizing test speed is essential. It is advantageous to keep the code concise, avoid unnecessary frames, minimize canvas size, and load assets only when essential for the specific functionality under test.
To address scenarios involving operations like asynchronous 3D model rendering, consider returning a promise that resolves upon completing all the necessary tests, ensuring efficiency in your visual testing approach. Here's an example of how you can asynchronous 3D model rendering in your visual tests:

```js
visualSuite('3D Model rendering', function() {
visualTest('OBJ model is displayed correctly', function(p5, screenshot) {
// Return a Promise to ensure the test runner waits for the asynchronous operation to complete
return new Promise(resolve => {
p5.createCanvas(50, 50, p5.WEBGL);
// Load the model asynchronously
p5.loadModel('unit/assets/teapot.obj', model => {
p5.background(200);
p5.rotateX(10 * 0.01);
p5.rotateY(10 * 0.01);
p5.model(model);
// Take a screenshot for visual comparison
screenshot();
// Resolve the Promise to indicate completion
resolve();
});
});
});
});
```
4 changes: 4 additions & 0 deletions test/unit/visual/visualTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ window.visualTest = function(
actual.push(myp5.get());
});


if (actual.length === 0) {
throw new Error('No screenshots were generated. Check if your test generates screenshots correctly. If the test includes asynchronous operations, ensure they complete before the test ends.');
}
if (expectedScreenshots && actual.length !== expectedScreenshots) {
throw new Error(
`Expected ${expectedScreenshots} screenshot(s) but generated ${actual.length}`
Expand Down
Loading