Unverified Commit c2f1062b authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Deflake root-optional-revalidate (#85584)

parent 73613d9d
...@@ -13,7 +13,10 @@ export async function getStaticPaths() { ...@@ -13,7 +13,10 @@ export async function getStaticPaths() {
} }
} }
export async function getStaticProps({ params }) { export async function getStaticProps({ params, revalidateReason }) {
console.log(
`getStaticProps({ revalidateReason: ${JSON.stringify(revalidateReason)} })`
)
return { return {
props: { props: {
params, params,
......
/* eslint-env jest */ import type { ChildProcess } from 'child_process'
import { join } from 'path' import { join } from 'path'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { import {
...@@ -9,11 +8,12 @@ import { ...@@ -9,11 +8,12 @@ import {
nextStart, nextStart,
renderViaHTTP, renderViaHTTP,
waitFor, waitFor,
retry,
} from 'next-test-utils' } from 'next-test-utils'
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
let app let app: ChildProcess | undefined
let appPort let appPort: number | undefined
const getProps = async (path) => { const getProps = async (path) => {
const html = await renderViaHTTP(appPort, path) const html = await renderViaHTTP(appPort, path)
...@@ -26,36 +26,54 @@ const runTests = () => { ...@@ -26,36 +26,54 @@ const runTests = () => {
const props = await getProps('/') const props = await getProps('/')
expect(props.params).toEqual({}) expect(props.params).toEqual({})
let cliOutput = ''
app.stdout.on('data', (chunk) => (cliOutput += chunk.toString()))
await waitFor(1000) await waitFor(1000)
await getProps('/') await getProps('/')
expect(cliOutput).toEqual('getStaticProps({ revalidateReason: "stale" })\n')
const newProps = await getProps('/') // Rendering takes time before the new cache entry is filled
expect(newProps.params).toEqual({}) await retry(async () => {
expect(props.random).not.toBe(newProps.random) const newProps = await getProps('/')
expect(newProps.params).toEqual({})
expect(props.random).not.toBe(newProps.random)
})
}) })
it('should render /a correctly', async () => { it('should render /a correctly', async () => {
const props = await getProps('/a') const props = await getProps('/a')
expect(props.params).toEqual({ slug: ['a'] }) expect(props.params).toEqual({ slug: ['a'] })
let cliOutput = ''
app.stdout.on('data', (chunk) => (cliOutput += chunk.toString()))
await waitFor(1000) await waitFor(1000)
await getProps('/a') await getProps('/a')
expect(cliOutput).toEqual('getStaticProps({ revalidateReason: "stale" })\n')
const newProps = await getProps('/a') // Rendering takes time before the new cache entry is filled
expect(newProps.params).toEqual({ slug: ['a'] }) await retry(async () => {
expect(props.random).not.toBe(newProps.random) const newProps = await getProps('/a')
expect(newProps.params).toEqual({ slug: ['a'] })
expect(props.random).not.toBe(newProps.random)
})
}) })
it('should render /hello/world correctly', async () => { it('should render /hello/world correctly', async () => {
const props = await getProps('/hello/world') const props = await getProps('/hello/world')
expect(props.params).toEqual({ slug: ['hello', 'world'] }) expect(props.params).toEqual({ slug: ['hello', 'world'] })
let cliOutput = ''
app.stdout.on('data', (chunk) => (cliOutput += chunk.toString()))
await waitFor(1000) await waitFor(1000)
await getProps('/hello/world') await getProps('/hello/world')
expect(cliOutput).toEqual('getStaticProps({ revalidateReason: "stale" })\n')
const newProps = await getProps('/hello/world') // Rendering takes time before the new cache entry is filled
expect(newProps.params).toEqual({ slug: ['hello', 'world'] }) await retry(async () => {
expect(props.random).not.toBe(newProps.random) const newProps = await getProps('/hello/world')
expect(newProps.params).toEqual({ slug: ['hello', 'world'] })
expect(props.random).not.toBe(newProps.random)
})
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment