From b5b796bf17042979e862a3dba753eb3e0ecb435f Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Sun, 3 Dec 2023 02:29:13 -0500 Subject: [PATCH 1/2] using flat confetti to make sure scale tests are more stable and repeatable --- test/index.test.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index 2af58ca..4e6ff5a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -377,13 +377,16 @@ test('shoots default scaled confetti', async t => { t.context.buffer = await confettiImage(page, { colors: ['#0000ff'], shapes: ['circle'], - particleCount: 10 + particleCount: 1, + startVelocity: 0, + gravity: 0, + flat: true }); t.context.image = await removeOpacity(t.context.buffer); const pixels = await totalPixels(t.context.image); - t.is(pixels > 100 && pixels < 500, true); + t.is(pixels, 124); }); test('shoots larger scaled confetti', async t => { @@ -393,13 +396,16 @@ test('shoots larger scaled confetti', async t => { colors: ['#0000ff'], shapes: ['circle'], scalar: 10, - particleCount: 10 + particleCount: 1, + startVelocity: 0, + gravity: 0, + flat: true }); t.context.image = await removeOpacity(t.context.buffer); const pixels = await totalPixels(t.context.image); - t.is(pixels > 2000, true); + t.is(pixels, 11476); }); test('shoots confetti to the left', async t => { From f841fa9b0b363c5f5b097ff528eccc576a06eab0 Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Sun, 3 Dec 2023 02:50:42 -0500 Subject: [PATCH 2/2] allowing pixel values to be off by 1% due to rendering differences on operating systems --- test/index.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index 4e6ff5a..ac161d9 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -386,7 +386,8 @@ test('shoots default scaled confetti', async t => { const pixels = await totalPixels(t.context.image); - t.is(pixels, 124); + const expected = 124; + t.true(pixels > expected * .99 && pixels < expected * 1.01, `${pixels}±1% ≠ ${expected}`); }); test('shoots larger scaled confetti', async t => { @@ -405,7 +406,8 @@ test('shoots larger scaled confetti', async t => { const pixels = await totalPixels(t.context.image); - t.is(pixels, 11476); + const expected = 11476; + t.true(pixels > expected * .99 && pixels < expected * 1.01, `${pixels} ± 1% ≠ ${expected}`); }); test('shoots confetti to the left', async t => {