forked from vercel/next.js
/
index.test.js
82 lines (72 loc) · 1.95 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* eslint-env jest */
import fs from 'fs-extra'
import { join } from 'path'
import cheerio from 'cheerio'
import {
renderViaHTTP,
findPort,
launchApp,
killApp,
nextBuild,
check,
} from 'next-test-utils'
const appDir = join(__dirname, '..')
let appPort
let app
async function get$(path, query) {
const html = await renderViaHTTP(appPort, path, query)
return cheerio.load(html)
}
describe('TypeScript Features', () => {
describe('default behavior', () => {
let output = ''
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout(msg) {
output += msg || ''
},
onStderr(msg) {
output += msg || ''
},
})
})
afterAll(() => killApp(app))
it('should render the page', async () => {
const $ = await get$('/hello')
expect($('body').text()).toMatch(/World/)
})
it('should have correct module not found error', async () => {
const basicPage = join(appDir, 'pages/hello.js')
const contents = await fs.readFile(basicPage, 'utf8')
await fs.writeFile(
basicPage,
contents.replace('components/world', 'components/worldd')
)
await renderViaHTTP(appPort, '/hello')
const found = await check(
() => output,
/Module not found: Can't resolve 'components\/worldd'/,
false
)
await fs.writeFile(basicPage, contents)
expect(found).toBe(true)
})
})
describe('should build', () => {
beforeAll(async () => {
await nextBuild(appDir)
})
it('should trace correctly', async () => {
const helloTrace = await fs.readJSON(
join(appDir, '.next/server/pages/hello.js.nft.json')
)
expect(
helloTrace.files.some((file) => file.includes('components/world.js'))
).toBe(true)
expect(
helloTrace.files.some((file) => file.includes('react/index.js'))
).toBe(true)
})
})
})