diff --git a/test/build/bundle_size.json b/test/build/bundle_size.json new file mode 100644 index 0000000000..260e18c031 --- /dev/null +++ b/test/build/bundle_size.json @@ -0,0 +1 @@ +1011249 diff --git a/test/build/min.test.ts b/test/build/min.test.ts index 8ebff5ae6a..0212ef4fa2 100644 --- a/test/build/min.test.ts +++ b/test/build/min.test.ts @@ -1,6 +1,8 @@ import {describe, test, expect} from 'vitest'; import fs from 'fs'; +import path from 'path'; import packageJson from '../../package.json' assert {type: 'json'}; +import bundleSize from './bundle_size.json' assert {type: 'json'}; const minBundle = fs.readFileSync('dist/maplibre-gl.js', 'utf8'); @@ -37,10 +39,14 @@ describe('test min build', () => { // need to make sure not a big bug that resulted in a big loss. const decreaseQuota = 4096; - // feel free to update this value after you've checked that it has changed on purpose :-) - const expectedBytes = 1011249; + let expectedBytes = bundleSize; - expect(actualBytes, `Consider changing expectedBytes to: ${actualBytes}`).toBeLessThan(expectedBytes + increaseQuota); + if (process.env.UPDATE) { + expectedBytes = actualBytes; + fs.writeFileSync(path.resolve(__dirname, './bundle_size.json'), `${expectedBytes}\n`); + } + + expect(actualBytes, `Consider changing bundle_size.json to ${actualBytes}: UPDATE=true npm run test-build -- min.test.ts`).toBeLessThan(expectedBytes + increaseQuota); expect(actualBytes).toBeGreaterThan(expectedBytes - decreaseQuota); }); });