Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print error when next dev has conflicting app & page (#41656)
This PR prints an error when the `app` and `pages` directory contain the same route. ## build error <img width="904" alt="image" src="https://user-images.githubusercontent.com/229881/197424839-67dac580-1e1d-4c31-b769-112f2f38b06e.png"> ## dev error <img width="957" alt="image" src="https://user-images.githubusercontent.com/229881/197426784-9b5041d9-b6d0-48d5-8ce5-b759bd9e4438.png"> Co-authored-by: JJ Kasper <jj@jjsweb.site>
- Loading branch information
Showing
6 changed files
with
140 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default function RootLayout({ children }) { | ||
return ( | ||
<html> | ||
<head> | ||
<title>Conflict Test</title> | ||
</head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
2 changes: 1 addition & 1 deletion
2
test/integration/conflicting-app-page-error/app/non-conflict/page.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default function Page(props) { | ||
return <p>another app</p> | ||
return <p>non-conflict app</p> | ||
} |
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 @@ | ||
export default function Page(props) { | ||
return <p>index page</p> | ||
} |
98 changes: 87 additions & 11 deletions
98
test/integration/conflicting-app-page-error/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 |
---|---|---|
@@ -1,24 +1,100 @@ | ||
/* eslint-env jest */ | ||
|
||
import path from 'path' | ||
import { nextBuild } from 'next-test-utils' | ||
import { | ||
killApp, | ||
findPort, | ||
getRedboxHeader, | ||
hasRedbox, | ||
launchApp, | ||
nextBuild, | ||
waitFor, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
|
||
let app | ||
let appPort | ||
const appDir = path.join(__dirname, '..') | ||
let output = '' | ||
|
||
describe('conflict between app file and page file', () => { | ||
it('errors during build', async () => { | ||
const conflicts = ['/hello', '/another'] | ||
const results = await nextBuild(appDir, [], { | ||
stdout: true, | ||
stderr: true, | ||
env: { NEXT_SKIP_APP_REACT_INSTALL: '1' }, | ||
}) | ||
const output = results.stdout + results.stderr | ||
function runTests({ dev }) { | ||
it('should print error for conflicting app/page', async () => { | ||
expect(output).toMatch(/Conflicting app and page files were found/) | ||
|
||
for (const conflict of conflicts) { | ||
for (const conflict of ['/hello', '/another']) { | ||
expect(output).toContain(conflict) | ||
} | ||
expect(output).not.toContain('/index') | ||
expect(output).not.toContain('/non-conflict') | ||
}) | ||
|
||
if (dev) { | ||
it('should show error overlay for /hello', async () => { | ||
const browser = await webdriver(appPort, '/hello') | ||
expect(await hasRedbox(browser, true)).toBe(true) | ||
expect(await getRedboxHeader(browser)).toContain( | ||
'Conflicting app and page file found: "app/hello/page.js" and "pages/hello.js". Please remove one to continue.' | ||
) | ||
}) | ||
|
||
it('should show error overlay for /another', async () => { | ||
const browser = await webdriver(appPort, '/another') | ||
expect(await hasRedbox(browser, true)).toBe(true) | ||
expect(await getRedboxHeader(browser)).toContain( | ||
'Conflicting app and page file found: "app/another/page.js" and "pages/another.js". Please remove one to continue.' | ||
) | ||
}) | ||
|
||
it('should not show error overlay for /', async () => { | ||
const browser = await webdriver(appPort, '/') | ||
expect(await hasRedbox(browser, false)).toBe(false) | ||
expect(await getRedboxHeader(browser)).toBe(null) | ||
expect(await browser.elementByCss('p').text()).toBe('index page') | ||
}) | ||
|
||
it('should not show error overlay for /non-conflict', async () => { | ||
const browser = await webdriver(appPort, '/non-conflict') | ||
expect(await hasRedbox(browser, false)).toBe(false) | ||
expect(await getRedboxHeader(browser)).toBe(null) | ||
expect(await browser.elementByCss('p').text()).toBe('non-conflict app') | ||
}) | ||
} | ||
} | ||
|
||
describe('Conflict between app file and page file', () => { | ||
describe('next dev', () => { | ||
beforeAll(async () => { | ||
output = '' | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort, { | ||
onStdout(msg) { | ||
output += msg || '' | ||
}, | ||
onStderr(msg) { | ||
output += msg || '' | ||
}, | ||
}) | ||
await waitFor(800) | ||
}) | ||
afterAll(() => { | ||
killApp(app) | ||
}) | ||
runTests({ dev: true }) | ||
}) | ||
|
||
describe('next build', () => { | ||
beforeAll(async () => { | ||
output = '' | ||
const { stdout, stderr } = await nextBuild(appDir, [], { | ||
stdout: true, | ||
stderr: true, | ||
env: { NEXT_SKIP_APP_REACT_INSTALL: '1' }, | ||
}) | ||
output = stdout + stderr | ||
}) | ||
afterAll(() => { | ||
killApp(app) | ||
}) | ||
runTests({ dev: false }) | ||
}) | ||
}) |