Skip to content

Commit

Permalink
Allow smaller files to be more different in siz
Browse files Browse the repository at this point in the history
  • Loading branch information
joehoyle committed Nov 20, 2023
1 parent 5a30523 commit b3f9d61
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/test-filesize/test-filesize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ test( 'Test file sizes', async () => {

// Make sure the image size is within 1% of the old image size. This is because
// file resizing sizes etc across systems and architectures is not 100%
// deterministic.
// deterministic. See https://github.com/lovell/sharp/issues/3783
let increasedPercent = 100 - Math.round( oldFixtures[key] / fixtures[key] * 100 );
let increasedSize = fixtures[key] - oldFixtures[key];

if ( fixtures[key] !== oldFixtures[key] ) {
const diff = Math.abs( 100 - ( oldFixtures[key] / fixtures[key] * 100 ) );
Expand All @@ -104,7 +105,11 @@ test( 'Test file sizes', async () => {
}, ${diff}%.). New ${ filesize( fixtures[key] ) }, old ${ filesize( oldFixtures[key] ) } }`
);
}
expect( increasedPercent ).toBeLessThanOrEqual( 3 );

// If the file has changed by more than 5kb, then we expect it to be within 3% of the old size.
if ( increasedSize > 1024 * 5 ) {
expect( increasedPercent ).toBeLessThanOrEqual( 3 );
}

}
} );

0 comments on commit b3f9d61

Please sign in to comment.