/
rsc-errors.test.ts
97 lines (87 loc) · 3.39 KB
/
rsc-errors.test.ts
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { check } from 'next-test-utils'
import { createNextDescribe } from 'e2e-utils'
if (!(globalThis as any).isNextDev) {
it('should skip tests for next-start', () => {})
} else {
createNextDescribe(
'app dir - rsc errors',
{
files: __dirname,
skipDeployment: true,
},
({ next }) => {
it('should throw an error when getServerSideProps is used', async () => {
const pageFile = 'app/client-with-errors/get-server-side-props/page.js'
const content = await next.readFile(pageFile)
const uncomment = content.replace(
'// export function getServerSideProps',
'export function getServerSideProps'
)
await next.patchFile(pageFile, uncomment)
const res = await next.fetch(
'/client-with-errors/get-server-side-props'
)
await next.patchFile(pageFile, content)
await check(async () => {
const { status } = await next.fetch(
'/client-with-errors/get-server-side-props'
)
return status
}, /200/)
expect(res.status).toBe(500)
expect(await res.text()).toContain(
'"getServerSideProps\\" is not supported in app/'
)
})
it('should throw an error when getStaticProps is used', async () => {
const pageFile = 'app/client-with-errors/get-static-props/page.js'
const content = await next.readFile(pageFile)
const uncomment = content.replace(
'// export function getStaticProps',
'export function getStaticProps'
)
await next.patchFile(pageFile, uncomment)
const res = await next.fetch('/client-with-errors/get-static-props')
await next.patchFile(pageFile, content)
await check(async () => {
const { status } = await next.fetch(
'/client-with-errors/get-static-props'
)
return status
}, /200/)
expect(res.status).toBe(500)
expect(await res.text()).toContain(
'"getStaticProps\\" is not supported in app/'
)
})
it('should error for styled-jsx imports on server side', async () => {
const html = await next.render('/server-with-errors/styled-jsx')
expect(html).toContain(
'This module cannot be imported from a Server Component module. It should only be used from a Client Component.'
)
})
it('should error when page component export is not valid', async () => {
const html = await next.render('/server-with-errors/page-export')
expect(html).toContain(
'The default export is not a React Component in page:'
)
})
it('should throw an error when "use client" is on the top level but after other expressions', async () => {
const pageFile = 'app/swc/use-client/page.js'
const content = await next.readFile(pageFile)
const uncomment = content.replace("// 'use client'", "'use client'")
await next.patchFile(pageFile, uncomment)
const res = await next.fetch('/swc/use-client')
await next.patchFile(pageFile, content)
await check(async () => {
const { status } = await next.fetch('/swc/use-client')
return status
}, /200/)
expect(res.status).toBe(500)
expect(await res.text()).toContain(
'directive must be placed before other expressions'
)
})
}
)
}