Commit c3b1f31e authored by JJ Kasper's avatar JJ Kasper Committed by Tim Neutkens

Fix /index/index.js route not emitting the right route in production (#6516)

Also added integration test in production for this

Fixes: #6285
parent 4c35b7e7
...@@ -9,7 +9,9 @@ type PagesMapping = { ...@@ -9,7 +9,9 @@ type PagesMapping = {
export function createPagesMapping(pagePaths: string[], extensions: string[]): PagesMapping { export function createPagesMapping(pagePaths: string[], extensions: string[]): PagesMapping {
const pages: PagesMapping = pagePaths.reduce((result: PagesMapping, pagePath): PagesMapping => { const pages: PagesMapping = pagePaths.reduce((result: PagesMapping, pagePath): PagesMapping => {
const page = `${pagePath.replace(new RegExp(`\\.+(${extensions.join('|')})$`), '').replace(/\\/g, '/')}`.replace(/\/index$/, '') let page = `${pagePath.replace(new RegExp(`\\.+(${extensions.join('|')})$`), '').replace(/\\/g, '/')}`.replace(/\/index$/, '')
page = page === '/index' ? '/' : page
result[page === '' ? '/' : page] = join(PAGES_DIR_ALIAS, pagePath).replace(/\\/g, '/') result[page === '' ? '/' : page] = join(PAGES_DIR_ALIAS, pagePath).replace(/\\/g, '/')
return result return result
}, {}) }, {})
......
setTimeout(() => process.exit(0), 5 * 1000)
module.exports = {}
export default function Index (props) {
return (
<div>Index Page</div>
)
}
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import webdriver from 'next-webdriver'
import {
runNextCommand,
findPort,
waitFor
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 30
describe('Promise in next config', () => {
it('should show warning when multiple tabs are open in the same browser', async () => {
const port = await findPort()
const runPromise = runNextCommand(
['dev', join(__dirname, '..'), '-p', port],
{ stderr: true }
).then(({ stderr }) => {
expect(stderr).toMatch(/Warn: You are opening multiple tabs of the same site in the same browser, this could cause requests to stall/)
})
await waitFor(1000)
const browser = await webdriver(port, '/')
await browser.eval(`window.copy1 = window.open('/', '_blank')`)
await browser.eval(`window.copy2 = window.open('/', '_blank')`)
await waitFor(1000)
await browser.eval(`window.copy1.close()`)
await browser.eval(`window.copy2.close()`)
browser.close()
await runPromise
})
})
import Link from 'next/link'
export default () => (
<div>
<Link href='/'><a>Index Page</a></Link>
<p>Another</p>
</div>
)
...@@ -3,6 +3,6 @@ import Link from 'next/link' ...@@ -3,6 +3,6 @@ import Link from 'next/link'
export default () => ( export default () => (
<div> <div>
<Link href='/about'><a>About Page</a></Link> <Link href='/about'><a>About Page</a></Link>
<p>Hello World</p> <p className='index-page'>Hello World</p>
</div> </div>
) )
...@@ -151,6 +151,17 @@ describe('Production Usage', () => { ...@@ -151,6 +151,17 @@ describe('Production Usage', () => {
expect(text).toBe('About Page') expect(text).toBe('About Page')
browser.close() browser.close()
}) })
it('should navigate to nested index via client side', async () => {
const browser = await webdriver(appPort, '/another')
const text = await browser
.elementByCss('a').click()
.waitForElementByCss('.index-page')
.elementByCss('p').text()
expect(text).toBe('Hello World')
browser.close()
})
}) })
describe('Runtime errors', () => { describe('Runtime errors', () => {
......
...@@ -71,6 +71,10 @@ export function runNextCommand (argv, options = {}) { ...@@ -71,6 +71,10 @@ export function runNextCommand (argv, options = {}) {
console.log(`Running command "next ${argv.join(' ')}"`) console.log(`Running command "next ${argv.join(' ')}"`)
const instance = spawn('node', ['dist/bin/next', ...argv], { ...options.spawnOptions, cwd, stdio: ['ignore', 'pipe', 'pipe'] }) const instance = spawn('node', ['dist/bin/next', ...argv], { ...options.spawnOptions, cwd, stdio: ['ignore', 'pipe', 'pipe'] })
if (typeof options.instance === 'function') {
options.instance(instance)
}
let stderrOutput = '' let stderrOutput = ''
if (options.stderr) { if (options.stderr) {
instance.stderr.on('data', function (chunk) { instance.stderr.on('data', function (chunk) {
......
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