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() {
}
}
export async function getStaticProps({ params }) {
export async function getStaticProps({ params, revalidateReason }) {
console.log(
`getStaticProps({ revalidateReason: ${JSON.stringify(revalidateReason)} })`
)
return {
props: {
params,
......
/* eslint-env jest */
import type { ChildProcess } from 'child_process'
import { join } from 'path'
import cheerio from 'cheerio'
import {
......@@ -9,11 +8,12 @@ import {
nextStart,
renderViaHTTP,
waitFor,
retry,
} from 'next-test-utils'
const appDir = join(__dirname, '../')
let app
let appPort
let app: ChildProcess | undefined
let appPort: number | undefined
const getProps = async (path) => {
const html = await renderViaHTTP(appPort, path)
......@@ -26,36 +26,54 @@ const runTests = () => {
const props = await getProps('/')
expect(props.params).toEqual({})
let cliOutput = ''
app.stdout.on('data', (chunk) => (cliOutput += chunk.toString()))
await waitFor(1000)
await getProps('/')
expect(cliOutput).toEqual('getStaticProps({ revalidateReason: "stale" })\n')
const newProps = await getProps('/')
expect(newProps.params).toEqual({})
expect(props.random).not.toBe(newProps.random)
// Rendering takes time before the new cache entry is filled
await retry(async () => {
const newProps = await getProps('/')
expect(newProps.params).toEqual({})
expect(props.random).not.toBe(newProps.random)
})
})
it('should render /a correctly', async () => {
const props = await getProps('/a')
expect(props.params).toEqual({ slug: ['a'] })
let cliOutput = ''
app.stdout.on('data', (chunk) => (cliOutput += chunk.toString()))
await waitFor(1000)
await getProps('/a')
expect(cliOutput).toEqual('getStaticProps({ revalidateReason: "stale" })\n')
const newProps = await getProps('/a')
expect(newProps.params).toEqual({ slug: ['a'] })
expect(props.random).not.toBe(newProps.random)
// Rendering takes time before the new cache entry is filled
await retry(async () => {
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 () => {
const props = await getProps('/hello/world')
expect(props.params).toEqual({ slug: ['hello', 'world'] })
let cliOutput = ''
app.stdout.on('data', (chunk) => (cliOutput += chunk.toString()))
await waitFor(1000)
await getProps('/hello/world')
expect(cliOutput).toEqual('getStaticProps({ revalidateReason: "stale" })\n')
const newProps = await getProps('/hello/world')
expect(newProps.params).toEqual({ slug: ['hello', 'world'] })
expect(props.random).not.toBe(newProps.random)
// Rendering takes time before the new cache entry is filled
await retry(async () => {
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