docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a screenshot comparison utility that efficiently validates image matches and conditionally generates visual diff outputs based on comparison results.
Your utility should support two distinct comparison modes:
The utility should implement a function compareScreenshots(img1, img2, width, height, options) that:
generateDiff boolean flagmismatchCount: number of mismatched pixelsdiffBuffer: visual diff buffer (only if generateDiff is true, otherwise null)The function should optimize performance by avoiding diff generation when not needed.
generateDiff: false, it returns mismatchCount: 0 and diffBuffer: null @testgenerateDiff: false, it returns a positive mismatchCount and diffBuffer: null @testgenerateDiff: true, it returns mismatchCount: 0 and a valid diffBuffer with grayscale output @testgenerateDiff: true, it returns a positive mismatchCount and a diffBuffer highlighting differences @test/**
* Compare two screenshot images with optional diff generation
*
* @param {Buffer|Uint8Array} img1 - First image buffer (RGBA format)
* @param {Buffer|Uint8Array} img2 - Second image buffer (RGBA format)
* @param {number} width - Image width in pixels
* @param {number} height - Image height in pixels
* @param {Object} options - Comparison options
* @param {boolean} options.generateDiff - Whether to generate visual diff output
* @returns {Object} Result object with mismatchCount and diffBuffer
*/
function compareScreenshots(img1, img2, width, height, options) {
// IMPLEMENTATION HERE
}
module.exports = { compareScreenshots };Provides pixel-level image comparison functionality.