perf(docker): бандл API, brotli-статика, wget-healthcheck, лимиты ресурсов, вендорные чанки web
This commit is contained in:
1 parent
1d7ea35a23
commit
8298454c63
10 files changed
+244
-20
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
// @ts-expect-error — .mjs без типов
|
||||
import { checkBudget } from '../../../scripts/ci/web-budget.mjs'
|
||||
|
||||
function dist(files: Record<string, string>): string {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'web-budget-'))
|
||||
for (const [name, body] of Object.entries(files)) {
|
||||
writeFileSync(join(dir, name), body)
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
describe('web-budget', () => {
|
||||
it('в бюджете → без ошибок', () => {
|
||||
const dir = dist({ 'index-abc.js': 'a'.repeat(100), 'x-1.js': 'b'.repeat(100) })
|
||||
const { errors, sizes } = checkBudget(dir, { entryGz: 1000, totalGz: 2000 })
|
||||
expect(errors).toEqual([])
|
||||
expect(sizes.entryGz).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('превышение entry и total → ошибки', () => {
|
||||
const noise = Array.from({ length: 5000 }, (_, i) => `v${i}=${Math.random()}`).join(';')
|
||||
const dir = dist({ 'index-abc.js': noise })
|
||||
const { errors } = checkBudget(dir, { entryGz: 10, totalGz: 10 })
|
||||
expect(errors).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('нет entry-чанка → ошибка', () => {
|
||||
const dir = dist({ 'other.js': 'x' })
|
||||
expect(checkBudget(dir).errors[0]).toMatch(/entry chunk/)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user