Skip to content

Commit b229810

Browse files
committed
test: add react-classic-18 playground
1 parent 132e3a6 commit b229810

File tree

7 files changed

+137
-1
lines changed

7 files changed

+137
-1
lines changed

.github/renovate.json5

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
"enabled": false,
1111
},
1212
{
13-
"matchFileNames": ["**/react-18/**", "**/compiler-react-18/**"],
13+
"matchFileNames": [
14+
"**/react-18/**",
15+
"**/react-classic-18/**",
16+
"**/compiler-react-18/**",
17+
],
1418
"ignoreDeps": ["react", "react-dom", "@types/react", "@types/react-dom"],
1519
},
1620
{

playground/react-classic-18/App.jsx

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { useState } from 'react'
2+
3+
function App() {
4+
const [count, setCount] = useState(0)
5+
return (
6+
<div className="App">
7+
<header className="App-header">
8+
<h1>Hello Vite + React</h1>
9+
<p>
10+
<button onClick={() => setCount((count) => count + 1)}>
11+
count is: {count}
12+
</button>
13+
</p>
14+
<p>
15+
Edit <code>App.jsx</code> and save to test HMR updates.
16+
</p>
17+
<a
18+
className="App-link"
19+
href="https://reactjs.org"
20+
target="_blank"
21+
rel="noopener noreferrer"
22+
>
23+
Learn React
24+
</a>
25+
</header>
26+
</div>
27+
)
28+
}
29+
30+
export default App
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { expect, test } from 'vitest'
2+
import { editFile, isServe, page, untilUpdated } from '~utils'
3+
4+
test('should render', async () => {
5+
expect(await page.textContent('h1')).toMatch('Hello Vite + React')
6+
})
7+
8+
test('should update', async () => {
9+
expect(await page.textContent('button')).toMatch('count is: 0')
10+
await page.click('button')
11+
expect(await page.textContent('button')).toMatch('count is: 1')
12+
})
13+
14+
test.runIf(isServe)('should hmr', async () => {
15+
editFile('App.jsx', (code) => code.replace('Vite + React', 'Updated'))
16+
await untilUpdated(() => page.textContent('h1'), 'Hello Updated')
17+
// preserve state
18+
expect(await page.textContent('button')).toMatch('count is: 1')
19+
})
20+
21+
test.runIf(isServe)(
22+
'should have annotated jsx with file location metadata',
23+
async () => {
24+
const meta = await page.evaluate(() => {
25+
const button = document.querySelector('button')
26+
const key = Object.keys(button).find(
27+
(key) => key.indexOf('__reactFiber') === 0,
28+
)
29+
return button[key]._debugSource
30+
})
31+
// If the evaluate call doesn't crash, and the returned metadata has
32+
// the expected fields, we're good.
33+
expect(Object.keys(meta).sort()).toEqual([
34+
'columnNumber',
35+
'fileName',
36+
'lineNumber',
37+
])
38+
},
39+
)
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div id="app"></div>
2+
<script type="module">
3+
import React from 'react'
4+
import ReactDOM from 'react-dom/client'
5+
import App from './App.jsx'
6+
7+
ReactDOM.createRoot(document.getElementById('app')).render(
8+
React.createElement(App),
9+
)
10+
</script>
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@vitejs/test-react-classic-18",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vite build",
8+
"debug": "node --inspect-brk vite",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
"react": "^18.3.1",
13+
"react-dom": "^18.3.1"
14+
},
15+
"devDependencies": {
16+
"@vitejs/plugin-react": "workspace:*"
17+
},
18+
"babel": {
19+
"presets": [
20+
"@babel/preset-env"
21+
]
22+
}
23+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import react from '@vitejs/plugin-react'
2+
import type { UserConfig } from 'vite'
3+
4+
const config: UserConfig = {
5+
server: { port: 8903 /* Should be unique */ },
6+
plugins: [
7+
react({
8+
jsxRuntime: 'classic',
9+
}),
10+
],
11+
build: {
12+
// to make tests faster
13+
minify: false,
14+
},
15+
}
16+
17+
export default config

pnpm-lock.yaml

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)