Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add case for React compiler #2487

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions e2e/cases/react/react-compiler-babel/index.test.ts
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();
},
);
12 changes: 12 additions & 0 deletions e2e/cases/react/react-compiler-babel/package.json
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"
}
}
15 changes: 15 additions & 0 deletions e2e/cases/react/react-compiler-babel/rsbuild.config.ts
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'));
},
}),
],
});
19 changes: 19 additions & 0 deletions e2e/cases/react/react-compiler-babel/src/App.jsx
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;
9 changes: 9 additions & 0 deletions e2e/cases/react/react-compiler-babel/src/index.js
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));
}
Loading
Loading