1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Fix page loader page normalization issue (#1844)

* Add integration tests for nested componentDidMount

* Fix the page loader normalization issue.

* Fix a typo in the url.
This commit is contained in:
Arunoda Susiripala 2017-05-01 16:26:18 -07:00 committed by GitHub
parent 2e7bc1074d
commit f578089d05
6 changed files with 55 additions and 2 deletions

View file

@ -19,7 +19,8 @@ export default class PageLoader {
throw new Error('Route name should start with a "/"')
}
return route.replace(/index$/, '')
if (route === '/') return route
return route.replace(/index$/, '').replace(/\/$/, '')
}
loadPage (route) {

View file

@ -0,0 +1,19 @@
import React, {Component} from 'react'
export default class extends Component {
constructor (props) {
super(props)
this.state = {
mounted: false
}
}
componentDidMount () {
this.setState({mounted: true})
}
render () {
return <p>ComponentDidMount {this.state.mounted ? 'executed on client' : 'not executed'}.</p>
}
}

View file

@ -0,0 +1,2 @@
import CDM from '../../lib/cdm'
export default CDM

View file

@ -0,0 +1,2 @@
import CDM from '../lib/cdm'
export default CDM

View file

@ -321,5 +321,31 @@ export default (context, render) => {
browser.close()
})
})
describe('with different types of urls', () => {
it('on normal page', async () => {
const browser = await webdriver(context.appPort, '/with-cdm')
const text = await browser.elementByCss('p').text()
expect(text).toBe('ComponentDidMount executed on client.')
browser.close()
})
it('on dir/index page ', async () => {
const browser = await webdriver(context.appPort, '/nested-cdm/index')
const text = await browser.elementByCss('p').text()
expect(text).toBe('ComponentDidMount executed on client.')
browser.close()
})
it('on dir/ page ', async () => {
const browser = await webdriver(context.appPort, '/nested-cdm/')
const text = await browser.elementByCss('p').text()
expect(text).toBe('ComponentDidMount executed on client.')
browser.close()
})
})
})
}

View file

@ -42,6 +42,7 @@ describe('Basic Features', () => {
renderViaHTTP(context.appPort, '/stateful'),
renderViaHTTP(context.appPort, '/stateless'),
renderViaHTTP(context.appPort, '/styled-jsx'),
renderViaHTTP(context.appPort, '/with-cdm'),
renderViaHTTP(context.appPort, '/nav'),
renderViaHTTP(context.appPort, '/nav/about'),
@ -49,7 +50,9 @@ describe('Basic Features', () => {
renderViaHTTP(context.appPort, '/nav/self-reload'),
renderViaHTTP(context.appPort, '/nav/hash-changes'),
renderViaHTTP(context.appPort, '/nav/shallow-routing'),
renderViaHTTP(context.appPort, '/nav/redirect')
renderViaHTTP(context.appPort, '/nav/redirect'),
renderViaHTTP(context.appPort, '/nested-cdm/index')
])
})
afterAll(() => stopApp(context.server))