From bf8fe61b3377ae93693bb48f1701570139f07dbb Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 4 Apr 2023 13:34:29 +0100 Subject: [PATCH] test: use kb size snapshot (#20083) --- test/bundle.test.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/bundle.test.ts b/test/bundle.test.ts index a1add503e5..e29efc0ab7 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -26,7 +26,7 @@ describe.skipIf(isWindows || process.env.ECOSYSTEM_CI)('minimal nuxt application it('default client bundle size', async () => { stats.client = await analyzeSizes('**/*.js', publicDir) - expect(stats.client.totalBytes).toBeLessThan(106650) + expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"104k"') expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(` [ "_nuxt/_plugin-vue_export-helper.js", @@ -40,10 +40,10 @@ describe.skipIf(isWindows || process.env.ECOSYSTEM_CI)('minimal nuxt application it('default server bundle size', async () => { stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect(stats.server.totalBytes).toBeLessThan(93300) + expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"91k"') const modules = await analyzeSizes('node_modules/**/*', serverDir) - expect(modules.totalBytes).toBeLessThan(2694900) + expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2632k"') const packages = modules.files .filter(m => m.endsWith('package.json')) @@ -104,3 +104,7 @@ async function analyzeSizes (pattern: string | string[], rootDir: string) { } return { files, totalBytes } } + +function roundToKilobytes (bytes: number) { + return (Math.round(bytes / 1024) + 'k') +}