Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
some changes returns
  • Loading branch information
Vaivaswat2244 committed Mar 20, 2025
commit 76f30b068c69448ffa8d2a3a23639d94d63dbb1f
31 changes: 30 additions & 1 deletion contributor_docs/unit_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,33 @@ const MIN_CLUSTER_SIZE = 4; // Minimum significant cluster size
const MAX_TOTAL_DIFF_PIXELS = 40; // Maximum allowed significant differences
```
The algorithm identifies line shifts by analyzing the neighborhood of each difference pixel. If more than 80% of pixels in a cluster have ≤2 neighbors, it's classified as a line shift rather than a structural difference.
This intelligent comparison ensures tests don't fail due to minor rendering differences while still catching actual visual bugs.
This intelligent comparison ensures tests don't fail due to minor rendering differences while still catching actual visual bugs.

It's important to note that the improved algorithm described above allows tests with acceptable platform-specific variations to pass correctly. Tests that previously failed due to minor rendering differences (like anti-aliasing variations or subtle text rendering differences) will now pass as they should, while still detecting actual rendering bugs.
For example, a test showing text rendering that previously failed on CI (despite looking correct visually) will now pass with the improved algorithm, as it can distinguish between meaningful differences and acceptable platform-specific rendering variations. This makes the test suite more reliable and reduces false failures that require manual investigation.

SOME BEST PRACTISES FOR WRITING VISUAL TESTS:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can use a markdown subheading for this to fit stylistically with the rest of the document?

Suggested change
SOME BEST PRACTISES FOR WRITING VISUAL TESTS:
### Some best practices for writing visual tests:

Copy link
Author

Choose a reason for hiding this comment

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

Right. Will do


When creating visual tests for p5.js, following these practices will help ensure reliable and efficient tests:

* Keep canvas sizes small - Use dimensions close to 50x50 pixels whenever possible. The test system resizes images for efficiency before comparison, and smaller canvases result in faster tests, especially on CI environments.
* Focus on visible details - At small canvas sizes, intricate details may be hard to distinguish. Design your test sketches to clearly demonstrate the feature being tested with elements that are visible at the reduced size.
* Use multiple screenshots per test - Instead of cramming many variants into a single screenshot, call screenshot() multiple times within a test:
```js
visualTest('stroke weight variations', function(p5, screenshot) {
p5.createCanvas(50, 50);

// Test thin stroke
p5.background(200);
p5.stroke(0);
p5.strokeWeight(1);
p5.line(10, 25, 40, 25);
screenshot('thin-line');
Copy link
Contributor

@davepagurek davepagurek Mar 27, 2025

Choose a reason for hiding this comment

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

I think screenshot doesn't do anything with arguments, maybe this and the other screenshot call could be done with a comment instead? e.g.

Suggested change
screenshot('thin-line');
screenshot(); // Screenshot with thin lines

Copy link
Author

Choose a reason for hiding this comment

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

Sure, got it.


// Test thick stroke
p5.background(200);
p5.strokeWeight(5);
p5.line(10, 25, 40, 25);
screenshot('thick-line');
});
```