-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for ISR case that always return same body
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/fixtures/page-router/netlify/functions/read-static-props-blobs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getDeployStore } from '@netlify/blobs' | ||
import { Context } from '@netlify/functions' | ||
|
||
function numberOrNull(value: string | null) { | ||
if (!value) { | ||
return null | ||
} | ||
|
||
const maybeNumber = parseInt(value) | ||
return isNaN(maybeNumber) ? null : maybeNumber | ||
} | ||
|
||
// intentionally using Netlify Function to not hit Next.js server handler function instance | ||
// to avoid potentially resuming suspended execution | ||
export default async function handler(_request: Request, context: Context) { | ||
const slug = context.params['slug'] | ||
|
||
const store = getDeployStore({ name: 'get-static-props-tracker', consistency: 'strong' }) | ||
|
||
const [start, end] = await Promise.all([store.get(`${slug}-start`), store.get(`${slug}-end`)]) | ||
|
||
return Response.json({ slug, start: numberOrNull(start), end: numberOrNull(end) }) | ||
} | ||
|
||
export const config = { | ||
path: '/read-static-props-blobs/:slug', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tests/fixtures/page-router/pages/always-the-same-body/[slug].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { getDeployStore } from '@netlify/blobs' | ||
|
||
const Show = ({ slug }) => { | ||
// ensure that the content is stable to trigger 304 responses | ||
return <pre>{slug}</pre> | ||
} | ||
|
||
/** @type {import('next').getStaticPaths} */ | ||
export async function getStaticPaths() { | ||
return { | ||
paths: [], | ||
fallback: 'blocking', | ||
} | ||
} | ||
|
||
/** @type {import('next').GetStaticProps} */ | ||
export async function getStaticProps({ params }) { | ||
const store = getDeployStore({ name: 'get-static-props-tracker', consistency: 'strong' }) | ||
|
||
const start = Date.now() | ||
|
||
console.log(`[timestamp] ${params.slug} getStaticProps start`) | ||
|
||
const storeStartPromise = store.set(`${params.slug}-start`, start).then(() => { | ||
console.log(`[timestamp] ${params.slug} getStaticProps start stored`) | ||
}) | ||
|
||
// simulate a long running operation | ||
await new Promise((resolve) => setTimeout(resolve, 5000)) | ||
|
||
const storeEndPromise = store.set(`${params.slug}-end`, Date.now()).then(() => { | ||
console.log(`[timestamp] ${params.slug} getStaticProps end stored`) | ||
}) | ||
|
||
console.log( | ||
`[timestamp] ${params.slug} getStaticProps end (duration: ${(Date.now() - start) / 1000}s)`, | ||
) | ||
|
||
await Promise.all([storeStartPromise, storeEndPromise]) | ||
|
||
// ensure that the data is stable and always the same to trigger 304 responses | ||
return { | ||
props: { | ||
slug: params.slug, | ||
}, | ||
revalidate: 5, | ||
} | ||
} | ||
|
||
export default Show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async function handler(req, res) { | ||
await new Promise((resolve) => setTimeout(resolve, 5000)) | ||
|
||
res.json({ message: 'ok' }) | ||
} |