-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add case for handling invalid element
- Loading branch information
Showing
8 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
test/development/app-dir/invalid-element-type/app/browser/browser-only.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,11 @@ | ||
'use client' | ||
|
||
import Foo from '../foo' | ||
|
||
export default function BrowserOnly() { | ||
return ( | ||
<div> | ||
<Foo /> | ||
</div> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
test/development/app-dir/invalid-element-type/app/browser/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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use client' | ||
|
||
import dynamic from 'next/dynamic' | ||
|
||
const BrowserOnly = dynamic(() => import('./browser-only'), { | ||
ssr: false, | ||
}) | ||
|
||
export default function Page() { | ||
return <BrowserOnly /> | ||
} |
Empty file.
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,8 @@ | ||
import { ReactNode } from 'react' | ||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/development/app-dir/invalid-element-type/app/rsc/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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Foo from '../foo' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
<Foo /> | ||
</div> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
test/development/app-dir/invalid-element-type/app/ssr/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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use client' | ||
|
||
import Foo from '../foo' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
<Foo /> | ||
</div> | ||
) | ||
} |
147 changes: 147 additions & 0 deletions
147
test/development/app-dir/invalid-element-type/invalid-element-type.test.ts
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,147 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { assertHasRedbox, getRedboxSource } from 'next-test-utils' | ||
|
||
async function getStackFramesContent(browser) { | ||
const stackFrameElements = await browser.elementsByCss( | ||
'[data-nextjs-call-stack-frame]' | ||
) | ||
const stackFramesContent = ( | ||
await Promise.all( | ||
stackFrameElements.map(async (frame) => { | ||
const functionNameEl = await frame.$('[data-nextjs-frame-expanded]') | ||
const sourceEl = await frame.$('[data-has-source]') | ||
const functionName = functionNameEl | ||
? await functionNameEl.innerText() | ||
: '' | ||
const source = sourceEl ? await sourceEl.innerText() : '' | ||
|
||
if (!functionName) { | ||
return '' | ||
} | ||
return `at ${functionName} (${source})` | ||
}) | ||
) | ||
) | ||
.filter(Boolean) | ||
.join('\n') | ||
|
||
return stackFramesContent | ||
} | ||
|
||
describe('app-dir - invalid-element-type', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should catch invalid element from on client-only component', async () => { | ||
const browser = await next.browser('/browser') | ||
|
||
await assertHasRedbox(browser) | ||
const source = await getRedboxSource(browser) | ||
|
||
const stackFramesContent = await getStackFramesContent(browser) | ||
if (process.env.TURBOPACK) { | ||
expect(stackFramesContent).toMatchInlineSnapshot( | ||
`"at Page (app/browser/page.js (10:10))"` | ||
) | ||
expect(source).toMatchInlineSnapshot(` | ||
"app/browser/browser-only.js (8:7) @ BrowserOnly | ||
6 | return ( | ||
7 | <div> | ||
> 8 | <Foo /> | ||
| ^ | ||
9 | </div> | ||
10 | ) | ||
11 | }" | ||
`) | ||
} else { | ||
expect(stackFramesContent).toMatchInlineSnapshot( | ||
`"at BrowserOnly (app/browser/page.js (10:11))"` | ||
) | ||
expect(source).toMatchInlineSnapshot(` | ||
"app/browser/browser-only.js (8:8) @ Foo | ||
6 | return ( | ||
7 | <div> | ||
> 8 | <Foo /> | ||
| ^ | ||
9 | </div> | ||
10 | ) | ||
11 | }" | ||
`) | ||
} | ||
}) | ||
|
||
it('should catch invalid element from on rsc component', async () => { | ||
const browser = await next.browser('/rsc') | ||
|
||
await assertHasRedbox(browser) | ||
const stackFramesContent = await getStackFramesContent(browser) | ||
const source = await getRedboxSource(browser) | ||
|
||
if (process.env.TURBOPACK) { | ||
expect(stackFramesContent).toMatchInlineSnapshot(`""`) | ||
expect(source).toMatchInlineSnapshot(` | ||
"app/rsc/page.js (6:7) @ Page | ||
4 | return ( | ||
5 | <div> | ||
> 6 | <Foo /> | ||
| ^ | ||
7 | </div> | ||
8 | ) | ||
9 | }" | ||
`) | ||
} else { | ||
expect(stackFramesContent).toMatchInlineSnapshot(`""`) | ||
expect(source).toMatchInlineSnapshot(` | ||
"app/rsc/page.js (6:8) @ Foo | ||
4 | return ( | ||
5 | <div> | ||
> 6 | <Foo /> | ||
| ^ | ||
7 | </div> | ||
8 | ) | ||
9 | }" | ||
`) | ||
} | ||
}) | ||
|
||
it('should catch invalid element from on ssr client component', async () => { | ||
const browser = await next.browser('/ssr') | ||
|
||
await assertHasRedbox(browser) | ||
|
||
const stackFramesContent = await getStackFramesContent(browser) | ||
const source = await getRedboxSource(browser) | ||
if (process.env.TURBOPACK) { | ||
expect(stackFramesContent).toMatchInlineSnapshot(`""`) | ||
expect(source).toMatchInlineSnapshot(` | ||
"app/ssr/page.js (8:7) @ Page | ||
6 | return ( | ||
7 | <div> | ||
> 8 | <Foo /> | ||
| ^ | ||
9 | </div> | ||
10 | ) | ||
11 | }" | ||
`) | ||
} else { | ||
expect(stackFramesContent).toMatchInlineSnapshot(`""`) | ||
expect(source).toMatchInlineSnapshot(` | ||
"app/ssr/page.js (8:8) @ Foo | ||
6 | return ( | ||
7 | <div> | ||
> 8 | <Foo /> | ||
| ^ | ||
9 | </div> | ||
10 | ) | ||
11 | }" | ||
`) | ||
} | ||
}) | ||
}) |
10 changes: 10 additions & 0 deletions
10
test/development/app-dir/invalid-element-type/next.config.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,10 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
experimental: { | ||
reactOwnerStack: true, | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |