Skip to content

Commit 8bf0400

Browse files
committed
fix: update tests
1 parent def9c7e commit 8bf0400

File tree

3 files changed

+94
-26
lines changed

3 files changed

+94
-26
lines changed

src/templates/getHandler.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const makeHandler =
4646
const cacheFile = path.join(cacheDir, filePath)
4747

4848
if (existsSync(cacheFile)) {
49-
console.log('returning from cache', cacheFile)
5049
return readfileOrig(cacheFile, options)
5150
}
5251

@@ -80,7 +79,6 @@ const makeHandler =
8079
if (file.startsWith(pageRoot)) {
8180
const filePath = file.slice(pageRoot.length + 1)
8281
const cacheFile = path.join(cacheDir, filePath)
83-
console.log('writing', cacheFile)
8482
await promises.mkdir(path.dirname(cacheFile), { recursive: true })
8583
return writeFileOrig(cacheFile, data, options)
8684
}
@@ -92,7 +90,6 @@ const makeHandler =
9290
if (dir.startsWith(pageRoot)) {
9391
const filePath = dir.slice(pageRoot.length + 1)
9492
const cachePath = path.join(cacheDir, filePath)
95-
console.log('creating', cachePath)
9693
return mkdirOrig(cachePath, options)
9794
}
9895

@@ -174,6 +171,7 @@ const makeHandler =
174171
// Sending SWR headers causes undefined behaviour with the Netlify CDN
175172
const cacheHeader = multiValueHeaders['cache-control']?.[0]
176173
if (cacheHeader?.includes('stale-while-revalidate')) {
174+
console.log({ cacheHeader })
177175
multiValueHeaders['cache-control'] = ['public, max-age=0, must-revalidate']
178176
}
179177
multiValueHeaders['x-render-mode'] = [mode]

test/__snapshots__/index.js.snap

Lines changed: 91 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ Array [
7676
"en/getStaticProps/2.json",
7777
"en/getStaticProps/static.html",
7878
"en/getStaticProps/static.json",
79-
"en/getStaticProps/with-revalidate.html",
80-
"en/getStaticProps/with-revalidate.json",
8179
"en/getStaticProps/withFallback/3.html",
8280
"en/getStaticProps/withFallback/3.json",
8381
"en/getStaticProps/withFallback/4.html",
@@ -90,30 +88,18 @@ Array [
9088
"en/getStaticProps/withFallbackBlocking/3.json",
9189
"en/getStaticProps/withFallbackBlocking/4.html",
9290
"en/getStaticProps/withFallbackBlocking/4.json",
93-
"en/getStaticProps/withRevalidate/1.html",
94-
"en/getStaticProps/withRevalidate/1.json",
95-
"en/getStaticProps/withRevalidate/2.html",
96-
"en/getStaticProps/withRevalidate/2.json",
97-
"en/getStaticProps/withRevalidate/withFallback/1.html",
98-
"en/getStaticProps/withRevalidate/withFallback/1.json",
99-
"en/getStaticProps/withRevalidate/withFallback/2.html",
100-
"en/getStaticProps/withRevalidate/withFallback/2.json",
10191
"en/image.html",
10292
"en/previewTest.html",
10393
"en/previewTest.json",
10494
"en/static.html",
10595
"es/getStaticProps/static.html",
10696
"es/getStaticProps/static.json",
107-
"es/getStaticProps/with-revalidate.html",
108-
"es/getStaticProps/with-revalidate.json",
10997
"es/image.html",
11098
"es/previewTest.html",
11199
"es/previewTest.json",
112100
"es/static.html",
113101
"fr/getStaticProps/static.html",
114102
"fr/getStaticProps/static.json",
115-
"fr/getStaticProps/with-revalidate.html",
116-
"fr/getStaticProps/with-revalidate.json",
117103
"fr/image.html",
118104
"fr/previewTest.html",
119105
"fr/previewTest.json",
@@ -215,17 +201,91 @@ Array [
215201
"to": "/.netlify/functions/___netlify-handler",
216202
},
217203
Object {
218-
"from": "/getStaticProps/withFallback/:slug/*",
204+
"force": true,
205+
"from": "/_next/data/build-id/getStaticProps/with-revalidate.json",
219206
"status": 200,
220-
"to": "/.netlify/builders/___netlify-odb-handler",
207+
"to": "/.netlify/functions/___netlify-handler",
221208
},
222209
Object {
223-
"from": "/_next/data/build-id/getStaticProps/withFallback/:slug/*",
210+
"force": true,
211+
"from": "/getStaticProps/with-revalidate",
224212
"status": 200,
225-
"to": "/.netlify/builders/___netlify-odb-handler",
213+
"to": "/.netlify/functions/___netlify-handler",
226214
},
227215
Object {
228-
"from": "/getStaticProps/withFallback/:id",
216+
"force": true,
217+
"from": "/_next/data/build-id/getStaticProps/with-revalidate.json",
218+
"status": 200,
219+
"to": "/.netlify/functions/___netlify-handler",
220+
},
221+
Object {
222+
"force": true,
223+
"from": "/es/getStaticProps/with-revalidate",
224+
"status": 200,
225+
"to": "/.netlify/functions/___netlify-handler",
226+
},
227+
Object {
228+
"force": true,
229+
"from": "/_next/data/build-id/getStaticProps/with-revalidate.json",
230+
"status": 200,
231+
"to": "/.netlify/functions/___netlify-handler",
232+
},
233+
Object {
234+
"force": true,
235+
"from": "/fr/getStaticProps/with-revalidate",
236+
"status": 200,
237+
"to": "/.netlify/functions/___netlify-handler",
238+
},
239+
Object {
240+
"force": true,
241+
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/1.json",
242+
"status": 200,
243+
"to": "/.netlify/functions/___netlify-handler",
244+
},
245+
Object {
246+
"force": true,
247+
"from": "/getStaticProps/withRevalidate/1",
248+
"status": 200,
249+
"to": "/.netlify/functions/___netlify-handler",
250+
},
251+
Object {
252+
"force": true,
253+
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/2.json",
254+
"status": 200,
255+
"to": "/.netlify/functions/___netlify-handler",
256+
},
257+
Object {
258+
"force": true,
259+
"from": "/getStaticProps/withRevalidate/2",
260+
"status": 200,
261+
"to": "/.netlify/functions/___netlify-handler",
262+
},
263+
Object {
264+
"force": true,
265+
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallback/1.json",
266+
"status": 200,
267+
"to": "/.netlify/functions/___netlify-handler",
268+
},
269+
Object {
270+
"force": true,
271+
"from": "/getStaticProps/withRevalidate/withFallback/1",
272+
"status": 200,
273+
"to": "/.netlify/functions/___netlify-handler",
274+
},
275+
Object {
276+
"force": true,
277+
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallback/2.json",
278+
"status": 200,
279+
"to": "/.netlify/functions/___netlify-handler",
280+
},
281+
Object {
282+
"force": true,
283+
"from": "/getStaticProps/withRevalidate/withFallback/2",
284+
"status": 200,
285+
"to": "/.netlify/functions/___netlify-handler",
286+
},
287+
Object {
288+
"from": "/_next/data/build-id/getStaticProps/withFallback/:slug/*",
229289
"status": 200,
230290
"to": "/.netlify/builders/___netlify-odb-handler",
231291
},
@@ -235,7 +295,7 @@ Array [
235295
"to": "/.netlify/builders/___netlify-odb-handler",
236296
},
237297
Object {
238-
"from": "/getStaticProps/withFallbackBlocking/:id",
298+
"from": "/_next/data/build-id/getStaticProps/withRevalidate/withFallback/:id.json",
239299
"status": 200,
240300
"to": "/.netlify/builders/___netlify-odb-handler",
241301
},
@@ -244,13 +304,23 @@ Array [
244304
"status": 200,
245305
"to": "/.netlify/builders/___netlify-odb-handler",
246306
},
307+
Object {
308+
"from": "/getStaticProps/withFallback/:slug/*",
309+
"status": 200,
310+
"to": "/.netlify/builders/___netlify-odb-handler",
311+
},
312+
Object {
313+
"from": "/getStaticProps/withFallback/:id",
314+
"status": 200,
315+
"to": "/.netlify/builders/___netlify-odb-handler",
316+
},
247317
Object {
248318
"from": "/getStaticProps/withRevalidate/withFallback/:id",
249319
"status": 200,
250320
"to": "/.netlify/builders/___netlify-odb-handler",
251321
},
252322
Object {
253-
"from": "/_next/data/build-id/getStaticProps/withRevalidate/withFallback/:id.json",
323+
"from": "/getStaticProps/withFallbackBlocking/:id",
254324
"status": 200,
255325
"to": "/.netlify/builders/___netlify-odb-handler",
256326
},

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ describe('onBuild()', () => {
302302
expect(existsSync(handlerFile)).toBeTruthy()
303303
expect(existsSync(odbHandlerFile)).toBeTruthy()
304304

305-
expect(readFileSync(handlerFile, 'utf8')).toMatch(`(config, "../../..", pageRoot, staticManifest)`)
306-
expect(readFileSync(odbHandlerFile, 'utf8')).toMatch(`(config, "../../..", pageRoot, staticManifest)`)
305+
expect(readFileSync(handlerFile, 'utf8')).toMatch(`(config, "../../..", pageRoot, staticManifest, 'ssr')`)
306+
expect(readFileSync(odbHandlerFile, 'utf8')).toMatch(`(config, "../../..", pageRoot, staticManifest, 'odb')`)
307307
expect(readFileSync(handlerFile, 'utf8')).toMatch(`require("../../../.next/required-server-files.json")`)
308308
expect(readFileSync(odbHandlerFile, 'utf8')).toMatch(`require("../../../.next/required-server-files.json")`)
309309
})

0 commit comments

Comments
 (0)