/
index.test.js
55 lines (43 loc) · 1.59 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
const fixturesDir = join(__dirname, '..', 'fixtures')
describe('Fallback Modules', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('Crypto Application', () => {
let stdout
const appDir = join(fixturesDir, 'with-crypto')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should not include crypto', async () => {
if (process.env.NEXT_PRIVATE_SKIP_SIZE_TESTS) {
return
}
;({ stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
console.log(stdout)
const parsePageSize = (page) =>
stdout.match(
new RegExp(` ${page} .*?((?:\\d|\\.){1,} (?:\\w{1,})) `)
)[1]
const parsePageFirstLoad = (page) =>
stdout.match(
new RegExp(
` ${page} .*?(?:(?:\\d|\\.){1,}) .*? ((?:\\d|\\.){1,} (?:\\w{1,}))`
)
)[1]
const indexSize = parsePageSize('/')
const indexFirstLoad = parsePageFirstLoad('/')
// expect(parseFloat(indexSize)).toBeLessThanOrEqual(3.1)
// expect(parseFloat(indexSize)).toBeGreaterThanOrEqual(2)
expect(indexSize.endsWith('kB')).toBe(true)
// expect(parseFloat(indexFirstLoad)).toBeLessThanOrEqual(67.9)
// expect(parseFloat(indexFirstLoad)).toBeGreaterThanOrEqual(60)
expect(indexFirstLoad.endsWith('kB')).toBe(true)
})
})
})
})