docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a simple screenshot validation tool that compares two PNG screenshots and reports whether they differ.
You need to implement a function that:
The comparison should be sensitive enough to detect meaningful visual differences while being practical for screenshot testing scenarios.
/**
* Compares two image buffers and returns the count of differing pixels.
*
* @param {Uint8Array|Uint8ClampedArray|Buffer} img1 - First image buffer (RGBA format)
* @param {Uint8Array|Uint8ClampedArray|Buffer} img2 - Second image buffer (RGBA format)
* @param {number} width - Width of both images in pixels
* @param {number} height - Height of both images in pixels
* @param {Object} options - Comparison options
* @param {Uint8Array|Uint8ClampedArray|Buffer|null} options.output - Optional output buffer for diff image
* @param {number} options.threshold - Sensitivity threshold (0-1), default 0.1
* @returns {number} Count of pixels that differ between the two images
*/
function compareImages(img1, img2, width, height, options = {}) {
// Implementation here
}
module.exports = { compareImages };Provides pixel-level image comparison functionality.