MCPcopy
hub / github.com/vercel/next.js / runTests

Function runTests

test/integration/preview-fallback/test/index.test.ts:29–265  ·  view source on GitHub ↗
(isDev: boolean)

Source from the content-addressed store, hash-verified

27}
28
29function runTests(isDev: boolean) {
30 it('should get preview cookie correctly', async () => {
31 const res = await fetchViaHTTP(appPort, '/api/enable')
32 previewCookie = ''
33
34 expect(res.headers.get('set-cookie')).toMatch(
35 /(__prerender_bypass|__next_preview_data)/
36 )
37
38 res.headers
39 .get('set-cookie')
40 .split(',')
41 .forEach((c) => {
42 const cookies = cookie.parse(c)
43 const isBypass = cookies.__prerender_bypass
44
45 if (isBypass || cookies.__next_preview_data) {
46 if (previewCookie) previewCookie += '; '
47
48 previewCookie += `${
49 isBypass ? '__prerender_bypass' : '__next_preview_data'
50 }=${cookies[isBypass ? '__prerender_bypass' : '__next_preview_data']}`
51 }
52 })
53 })
54
55 it('should not write preview index SSG page to cache', async () => {
56 const html = await renderViaHTTP(appPort, '/')
57 const props = JSON.parse(cheerio.load(html)('#props').text())
58
59 expect(props).toEqual({
60 preview: false,
61 previewData: null,
62 })
63
64 const res = await fetchViaHTTP(appPort, '/', undefined, {
65 headers: {
66 cookie: previewCookie,
67 },
68 })
69
70 const previewHtml = await res.text()
71 const previewProps = JSON.parse(cheerio.load(previewHtml)('#props').text())
72 expect(previewProps).toEqual({
73 preview: true,
74 previewData: {},
75 })
76
77 if (!isDev) {
78 const fsHtml = await fs.readFile(getCacheFile('index.html'))
79 const fsProps = JSON.parse(cheerio.load(fsHtml)('#props').text())
80
81 expect(fsProps).toEqual({
82 preview: false,
83 previewData: null,
84 })
85 }
86 const html2 = await renderViaHTTP(appPort, '/')

Callers 1

index.test.tsFile · 0.70

Calls 15

fetchViaHTTPFunction · 0.90
renderViaHTTPFunction · 0.90
checkFunction · 0.90
getCacheFileFunction · 0.85
webdriverFunction · 0.85
splitMethod · 0.80
elementByCssMethod · 0.80
getMethod · 0.65
textMethod · 0.65
loadMethod · 0.65
itFunction · 0.50
expectFunction · 0.50

Tested by

no test coverage detected