-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(next): react compiler test cases
- Loading branch information
Showing
5 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["next/babel"] | ||
} |
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,13 @@ | ||
'use client' | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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,25 @@ | ||
'use client' | ||
|
||
export default function Page() { | ||
let heading: any = null | ||
// eslint-disable-next-line no-eval | ||
const $_ = eval('$') | ||
if (Array.isArray($_)) { | ||
// console.log("useMemoCache", $_); | ||
heading = ( | ||
<h1 className="text-9xl"> | ||
{/* @ts-ignore */} | ||
React compiler is enabled with <strong>{$_.length}</strong> memo slots | ||
</h1> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<div> | ||
{heading} | ||
<p>hello world</p> | ||
</div> | ||
</> | ||
) | ||
} |
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,12 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
experimental: { | ||
// Forces nextjs to use experimental react which has the useMemoCache hook. | ||
ppr: true, | ||
reactCompiler: true, | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
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,27 @@ | ||
import { nextTestSetup, FileRef } from 'e2e-utils' | ||
import { join } from 'path' | ||
|
||
describe.each( | ||
['default', process.env.TURBOPACK ? undefined : 'babelrc'].filter(Boolean) | ||
)('react-compiler %s', (variant) => { | ||
const { next } = nextTestSetup({ | ||
files: | ||
variant === 'babelrc' | ||
? __dirname | ||
: { | ||
app: new FileRef(join(__dirname, 'app')), | ||
'next.config.js': new FileRef(join(__dirname, 'next.config.js')), | ||
}, | ||
|
||
dependencies: { | ||
'babel-plugin-react-compiler': '0.0.0-experimental-4690415-20240515', | ||
}, | ||
}) | ||
|
||
it('should render', async () => { | ||
const $ = await next.render$('/') | ||
expect($('h1').text()).toMatch( | ||
/React compiler is enabled with .+ memo slots/ | ||
) | ||
}) | ||
}) |