-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathdynamic-routes.spec.ts
149 lines (148 loc) · 6.98 KB
/
dynamic-routes.spec.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* eslint-disable max-lines-per-function */
describe('Static Routing', () => {
it('renders correct page via SSR on a static route', () => {
cy.request({ url: '/getServerSideProps/static/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'ssr')
expect(res.body).to.contain('Sleepy Hollow')
})
})
it('serves correct static file on a static route', () => {
cy.request({ url: '/getStaticProps/static/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.not.have.property('x-nf-render-mode')
expect(res.body).to.contain('Dancing with the Stars')
})
})
it('renders correct page via ODB on a static route', () => {
cy.request({ url: '/getStaticProps/with-revalidate/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=1')
expect(res.body).to.contain('Dancing with the Stars')
})
})
})
describe('Dynamic Routing', () => {
it('renders correct page via SSR on a dynamic route', () => {
cy.request({ url: '/getServerSideProps/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'ssr')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders correct page via SSR on a dynamic catch-all route', () => {
cy.request({ url: '/getServerSideProps/all/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'ssr')
expect(res.body).to.contain('Under the Dome')
})
})
it('serves correct static file on a prerendered dynamic route with fallback: false', () => {
cy.request({ url: '/getStaticProps/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.not.have.property('x-nf-render-mode')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders custom 404 on a non-prerendered dynamic route with fallback: false', () => {
cy.request({ url: '/getStaticProps/3/', headers: { 'x-nf-debug-logging': '1' }, failOnStatusCode: false }).then(
(res) => {
expect(res.status).to.eq(404)
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
expect(res.body).to.contain('Custom 404')
},
)
})
it('serves correct static file on a prerendered dynamic route with fallback: true', () => {
cy.request({ url: '/getStaticProps/withFallback/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.not.have.property('x-nf-render-mode')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders fallback page via ODB on a non-prerendered dynamic route with fallback: true', () => {
cy.request({ url: '/getStaticProps/withFallback/3/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
expect(res.status).to.eq(200)
// expect 'odb' until https://github.com/netlify/pillar-runtime/issues/438 is fixed
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
// expect 'Bitten' until the above is fixed and we can test for fallback 'Loading...' message
expect(res.body).to.contain('Bitten')
})
})
it('serves correct static file on a prerendered dynamic route with fallback: blocking', () => {
cy.request({ url: '/getStaticProps/withFallbackBlocking/1/', headers: { 'x-nf-debug-logging': '1' } }).then(
(res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.not.have.property('x-nf-render-mode')
expect(res.body).to.contain('Under the Dome')
},
)
})
it('renders correct page via ODB on a non-prerendered dynamic route with fallback: blocking', () => {
cy.request({ url: '/getStaticProps/withFallbackBlocking/3/', headers: { 'x-nf-debug-logging': '1' } }).then(
(res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
expect(res.body).to.contain('Bitten')
},
)
})
it('renders correct page via ODB on a prerendered dynamic route with revalidate and fallback: false', () => {
cy.request({ url: '/getStaticProps/withRevalidate/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders custom 404 on a non-prerendered dynamic route with revalidate and fallback: false', () => {
cy.request({
url: '/getStaticProps/withRevalidate/3/',
headers: { 'x-nf-debug-logging': '1' },
failOnStatusCode: false,
}).then((res) => {
expect(res.status).to.eq(404)
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
expect(res.body).to.contain('Custom 404')
})
})
it('renders correct page via ODB on a prerendered dynamic route with revalidate and fallback: true', () => {
cy.request({ url: '/getStaticProps/withRevalidate/withFallback/1/', headers: { 'x-nf-debug-logging': '1' } }).then(
(res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Under the Dome')
},
)
})
it('renders fallback page via ODB on a non-prerendered dynamic route with revalidate and fallback: true', () => {
cy.request({ url: '/getStaticProps/withRevalidate/withFallback/3/', headers: { 'x-nf-debug-logging': '1' } }).then(
(res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
// expect 'Bitten' until https://github.com/netlify/pillar-runtime/issues/438 is fixed
expect(res.body).to.contain('Bitten')
},
)
})
it('renders correct page via ODB on a prerendered dynamic route with revalidate and fallback: blocking', () => {
cy.request({
url: '/getStaticProps/withRevalidate/withFallbackBlocking/1/',
headers: { 'x-nf-debug-logging': '1' },
}).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders correct page via ODB on a non-prerendered dynamic route with revalidate and fallback: blocking', () => {
cy.request({
url: '/getStaticProps/withRevalidate/withFallbackBlocking/3/',
headers: { 'x-nf-debug-logging': '1' },
}).then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Bitten')
})
})
})
/* eslint-enable max-lines-per-function */