-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into hotfix/wp5-alias-only
- Loading branch information
Showing
4 changed files
with
189 additions
and
11 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
24 changes: 24 additions & 0 deletions
24
test/integration/root-optional-revalidate/pages/[[...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,24 @@ | ||
export default function Home(props) { | ||
return <pre id="props">{JSON.stringify(props)}</pre> | ||
} | ||
|
||
export async function getStaticPaths() { | ||
return { | ||
paths: [ | ||
{ params: { slug: false } }, | ||
{ params: { slug: ['a'] } }, | ||
{ params: { slug: ['hello', 'world'] } }, | ||
], | ||
fallback: false, | ||
} | ||
} | ||
|
||
export async function getStaticProps({ params }) { | ||
return { | ||
props: { | ||
params, | ||
random: Math.random(), | ||
}, | ||
revalidate: 1, | ||
} | ||
} |
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 @@ | ||
const path = require('path') | ||
const http = require('http') | ||
|
||
const server = http.createServer(async (req, res) => { | ||
const render = async (page) => { | ||
const mod = require(`./${path.join('.next/serverless/pages/', page)}`) | ||
try { | ||
return await (mod.render || mod.default || mod)(req, res) | ||
} catch (err) { | ||
res.statusCode = 500 | ||
return res.end('internal error') | ||
} | ||
} | ||
|
||
try { | ||
await render('/[[...slug]].js') | ||
} catch (err) { | ||
console.error('failed to render', err) | ||
res.statusCode = 500 | ||
res.end('Internal Error') | ||
} | ||
}) | ||
|
||
const port = process.env.PORT || 3000 | ||
server.listen(port, () => { | ||
console.log('ready on', port) | ||
}) |
115 changes: 115 additions & 0 deletions
115
test/integration/root-optional-revalidate/test/index.test.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,115 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import cheerio from 'cheerio' | ||
import { | ||
killApp, | ||
findPort, | ||
File, | ||
nextBuild, | ||
nextStart, | ||
initNextServerScript, | ||
renderViaHTTP, | ||
waitFor, | ||
} from 'next-test-utils' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const appDir = join(__dirname, '../') | ||
const nextConfig = new File(join(appDir, 'next.config.js')) | ||
let app | ||
let appPort | ||
|
||
const getProps = async (path, expected) => { | ||
const html = await renderViaHTTP(appPort, path) | ||
const $ = cheerio.load(html) | ||
return JSON.parse($('#props').text()) | ||
} | ||
|
||
const runTests = (rawServerless = false) => { | ||
it('should render / correctly', async () => { | ||
const props = await getProps('/', { params: {} }) | ||
expect(props.params).toEqual({}) | ||
|
||
await waitFor(1000) | ||
await getProps('/') | ||
|
||
const newProps = await getProps('/', { params: {} }) | ||
expect(newProps.params).toEqual({}) | ||
expect(props.random).not.toBe(newProps.random) | ||
}) | ||
|
||
if (rawServerless) { | ||
it('should render /index correctly', async () => { | ||
const props = await getProps('/index') | ||
expect(props.params).toEqual({}) | ||
|
||
await waitFor(1000) | ||
await getProps('/index') | ||
|
||
const newProps = await getProps('/index') | ||
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'] }) | ||
|
||
await waitFor(1000) | ||
await getProps('/a') | ||
|
||
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'] }) | ||
|
||
await waitFor(1000) | ||
await getProps('/hello/world') | ||
|
||
const newProps = await getProps('/hello/world') | ||
expect(newProps.params).toEqual({ slug: ['hello', 'world'] }) | ||
expect(props.random).not.toBe(newProps.random) | ||
}) | ||
} | ||
|
||
describe('Root Optional Catch-all Revalidate', () => { | ||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('raw serverless mode', () => { | ||
beforeAll(async () => { | ||
nextConfig.write(` | ||
module.exports = { | ||
target: 'experimental-serverless-trace' | ||
} | ||
`) | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
|
||
app = await initNextServerScript(join(appDir, 'server.js'), /ready on/i, { | ||
...process.env, | ||
PORT: appPort, | ||
}) | ||
}) | ||
afterAll(async () => { | ||
nextConfig.delete() | ||
await killApp(app) | ||
}) | ||
|
||
runTests(true) | ||
}) | ||
}) |