-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): add case for React compiler (#2487)
- Loading branch information
1 parent
784456a
commit ad58d68
Showing
6 changed files
with
228 additions
and
4 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,42 @@ | ||
import { build, dev, gotoPage, rspackOnlyTest } from '@e2e/helper'; | ||
import { expect } from '@playwright/test'; | ||
|
||
rspackOnlyTest( | ||
'should render basic React component in development correctly', | ||
async ({ page }) => { | ||
const rsbuild = await dev({ | ||
cwd: __dirname, | ||
}); | ||
|
||
await gotoPage(page, rsbuild); | ||
|
||
const button = page.locator('#button'); | ||
await expect(button).toHaveText('count: 0'); | ||
button.click(); | ||
await expect(button).toHaveText('count: 1'); | ||
|
||
rsbuild.close(); | ||
}, | ||
); | ||
|
||
rspackOnlyTest( | ||
'should render basic React component in production correctly', | ||
async ({ page }) => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
runServer: true, | ||
}); | ||
|
||
await gotoPage(page, rsbuild); | ||
|
||
const button = page.locator('#button'); | ||
await expect(button).toHaveText('count: 0'); | ||
button.click(); | ||
await expect(button).toHaveText('count: 1'); | ||
|
||
const index = await rsbuild.getIndexFile(); | ||
expect(index.content).toContain('memo_cache_sentinel'); | ||
|
||
rsbuild.close(); | ||
}, | ||
); |
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 @@ | ||
{ | ||
"name": "@e2e/react-compiler-babel", | ||
"version": "1.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"react": "19.0.0-rc-6d3110b4d9-20240531", | ||
"react-dom": "19.0.0-rc-6d3110b4d9-20240531" | ||
}, | ||
"devDependencies": { | ||
"babel-plugin-react-compiler": "0.0.0-experimental-938cd9a-20240601" | ||
} | ||
} |
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,15 @@ | ||
import { defineConfig } from '@rsbuild/core'; | ||
import { pluginBabel } from '@rsbuild/plugin-babel'; | ||
import { pluginReact } from '@rsbuild/plugin-react'; | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
pluginReact(), | ||
pluginBabel({ | ||
include: /\.(?:jsx|tsx)$/, | ||
babelLoaderOptions(opts) { | ||
opts.plugins?.unshift(require.resolve('babel-plugin-react-compiler')); | ||
}, | ||
}), | ||
], | ||
}); |
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,19 @@ | ||
import { useState } from 'react'; | ||
|
||
const App = () => { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<> | ||
<button id="button" type="button" onClick={() => setCount(count + 1)}> | ||
count: {count} | ||
</button> | ||
<div className="content"> | ||
<h1>Rsbuild with React</h1> | ||
<p>Start building amazing things with Rsbuild.</p> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
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 React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import App from './App'; | ||
|
||
const container = document.getElementById('root'); | ||
if (container) { | ||
const root = createRoot(container); | ||
root.render(React.createElement(App)); | ||
} |
Oops, something went wrong.