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

Function runTests

test/e2e/middleware-custom-matchers/test/index.test.ts:33–185  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31 afterAll(() => next.destroy())
32
33 const runTests = () => {
34 it('should match missing header correctly', async () => {
35 const res = await fetchViaHTTP(next.url, '/missing-match-1')
36 expect(res.headers.get('x-from-middleware')).toBeDefined()
37
38 const res2 = await fetchViaHTTP(next.url, '/missing-match-1', undefined, {
39 headers: {
40 hello: 'world',
41 },
42 })
43 expect(res2.headers.get('x-from-middleware')).toBeFalsy()
44
45 const res3 = await fetchViaHTTP(next.url, '/')
46 expect(res3.headers.get('x-from-middleware')).toBeDefined()
47
48 const res4 = await fetchViaHTTP(next.url, '/', undefined, {
49 headers: {
50 purpose: 'prefetch',
51 },
52 })
53 expect(res4.headers.get('x-from-middleware')).toBeFalsy()
54 })
55
56 it('should match missing query correctly', async () => {
57 const res = await fetchViaHTTP(next.url, '/missing-match-2')
58 expect(res.headers.get('x-from-middleware')).toBeDefined()
59
60 const res2 = await fetchViaHTTP(next.url, '/missing-match-2', {
61 test: 'value',
62 })
63 expect(res2.headers.get('x-from-middleware')).toBeFalsy()
64 })
65
66 it('should match source path', async () => {
67 const res = await fetchViaHTTP(next.url, '/source-match')
68 expect(res.status).toBe(200)
69 expect(res.headers.get('x-from-middleware')).toBeDefined()
70 })
71
72 it('should match has header', async () => {
73 const res = await fetchViaHTTP(next.url, '/has-match-1', undefined, {
74 headers: {
75 'x-my-header': 'hello world!!',
76 },
77 })
78 expect(res.status).toBe(200)
79 expect(res.headers.get('x-from-middleware')).toBeDefined()
80
81 const res2 = await fetchViaHTTP(next.url, '/has-match-1')
82 expect(res2.status).toBe(404)
83 })
84
85 it('should match has query', async () => {
86 const res = await fetchViaHTTP(next.url, '/has-match-2', {
87 'my-query': 'hellooo',
88 })
89 expect(res.status).toBe(200)
90 expect(res.headers.get('x-from-middleware')).toBeDefined()

Callers 1

index.test.tsFile · 0.70

Calls 12

fetchViaHTTPFunction · 0.90
webdriverFunction · 0.85
evalMethod · 0.80
clickMethod · 0.80
elementByIdMethod · 0.80
addCookieMethod · 0.80
itifFunction · 0.70
getMethod · 0.65
textMethod · 0.65
refreshMethod · 0.65
itFunction · 0.50
expectFunction · 0.50

Tested by

no test coverage detected