-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Analyze Bundle Size > bundle size snapshots > e7a375265d7bbc05627f6431e3306dc1a25a91f0.client 1`] = `436139`; | ||
|
||
exports[`Analyze Bundle Size > bundle size snapshots > e7a375265d7bbc05627f6431e3306dc1a25a91f0.nitro 1`] = `3917094`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { fileURLToPath } from 'node:url' | ||
import { promisify } from 'node:util' | ||
import { createHash } from 'node:crypto' | ||
import { createReadStream } from 'node:fs' | ||
import { finished } from 'node:stream/promises' | ||
import { join } from 'node:path' | ||
import { describe, expect, it } from 'vitest' | ||
import { setup, useTestContext } from '@nuxt/test-utils' | ||
import folderSizeCallback from 'fast-folder-size' | ||
|
||
const folderSize = promisify(folderSizeCallback) | ||
|
||
describe('Analyze Bundle Size', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)), | ||
server: false, | ||
}) | ||
|
||
it('bundle size snapshots', async () => { | ||
const ctx = useTestContext() | ||
const { buildDir } = ctx.nuxt!.options | ||
|
||
const lockFile = fileURLToPath(new URL('../pnpm-lock.yaml', import.meta.url)) | ||
const lockHash = await createFileHash(lockFile) | ||
|
||
const clientBundle = await folderSize(join(buildDir, 'dist/client')) | ||
const nitroBundle = await folderSize(join(buildDir, 'output')) | ||
|
||
expect(clientBundle).toMatchSnapshot(`${lockHash}.client`) | ||
expect(nitroBundle).toMatchSnapshot(`${lockHash}.nitro`) | ||
}) | ||
}) | ||
|
||
async function createFileHash(path: string) { | ||
const hash = createHash('sha1') | ||
const stream = createReadStream(path) | ||
stream.pipe(hash) | ||
await finished(stream) | ||
return hash.digest('hex') | ||
} |