-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inconsistent handling for /index (#11643)
* Fix inconsistent handling for /index * Add more test cases * Add pages/index/index.js test Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
- Loading branch information
Showing
14 changed files
with
224 additions
and
6 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
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
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
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
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
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,2 @@ | ||
const page = () => 'hello from index' | ||
export default page |
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,60 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import { join } from 'path' | ||
import { | ||
findPort, | ||
launchApp, | ||
killApp, | ||
nextBuild, | ||
nextStart, | ||
fetchViaHTTP, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
|
||
let app | ||
let appPort | ||
const appDir = join(__dirname, '../') | ||
|
||
const runTests = () => { | ||
it('should handle / correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hello from index') | ||
}) | ||
|
||
it('should handle /index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/index') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hello from index') | ||
}) | ||
|
||
it('should handle /index/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/index/index') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('page could not be found') | ||
}) | ||
} | ||
|
||
describe('Route index handling', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
}) |
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 @@ | ||
export default (req, res) => res.end('hi from sub id') |
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 @@ | ||
export default (req, res) => res.end('hi from sub index') |
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,2 @@ | ||
const page = () => 'hello from index' | ||
export default page |
1 change: 1 addition & 0 deletions
1
test/integration/route-indexes/pages/nested-index/index/index.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 @@ | ||
export default () => 'hello from nested index' |
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,3 @@ | ||
const page = () => 'hello from sub id' | ||
page.getInitialProps = () => ({ hello: 'hi' }) | ||
export default page |
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,3 @@ | ||
const page = () => 'hello from sub index' | ||
page.getInitialProps = () => ({ hello: 'hi' }) | ||
export default page |
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,138 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import { join } from 'path' | ||
import { | ||
findPort, | ||
launchApp, | ||
killApp, | ||
nextBuild, | ||
nextStart, | ||
fetchViaHTTP, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
|
||
let app | ||
let appPort | ||
const appDir = join(__dirname, '../') | ||
|
||
const runTests = () => { | ||
it('should handle / correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hello from index') | ||
}) | ||
|
||
it('should handle /index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/index') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hello from index') | ||
}) | ||
|
||
it('should handle /index/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/index/index') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('page could not be found') | ||
}) | ||
|
||
it('should handle /nested-index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/nested-index') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('page could not be found') | ||
}) | ||
|
||
it('should handle /nested-index/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/nested-index/index') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hello from nested index') | ||
}) | ||
|
||
it('should handle /nested-index/index/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/nested-index/index/index') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('page could not be found') | ||
}) | ||
|
||
it('should handle /sub correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/sub') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hello from sub index') | ||
}) | ||
|
||
it('should handle /sub/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/sub/index') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hello from sub id') | ||
}) | ||
|
||
it('should handle /sub/index/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/sub/index/index') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('page could not be found') | ||
}) | ||
|
||
it('should handle /sub/another correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/sub/another') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hello from sub id') | ||
}) | ||
|
||
it('should handle /sub/another/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/sub/another/index') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('page could not be found') | ||
}) | ||
|
||
it('should handle /api/sub correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/api/sub') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hi from sub index') | ||
}) | ||
|
||
it('should handle /api/sub/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/api/sub/index') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hi from sub id') | ||
}) | ||
|
||
it('should handle /api/sub/index/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/api/sub/index/index') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('page could not be found') | ||
}) | ||
|
||
it('should handle /api/sub/another correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/api/sub/another') | ||
expect(res.status).toBe(200) | ||
expect(await res.text()).toContain('hi from sub id') | ||
}) | ||
|
||
it('should handle /api/sub/another/index correctly', async () => { | ||
const res = await fetchViaHTTP(appPort, '/api/sub/another/index') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('page could not be found') | ||
}) | ||
} | ||
|
||
describe('Route indexes handling', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
}) |