Skip to content

Commit fade954

Browse files
committed
test: move react-compiler tests
1 parent f2a725c commit fade954

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

packages/plugin-rsc/e2e/fixture.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,36 @@ function editFileJson(filepath: string, edit: (s: string) => string) {
193193
)
194194
}
195195

196+
// inspired by
197+
// https://github.com/remix-run/react-router/blob/433872f6ab098eaf946cc6c9cf80abf137420ad2/integration/helpers/vite.ts#L239
198+
// for syntax highlighting of /* js */, use this extension
199+
// https://github.com/mjbvz/vscode-comment-tagged-templates
196200
export async function setupInlineFixture(options: {
197201
src: string
198202
dest: string
199-
}) {}
203+
files?: Record<string, string>
204+
}) {
205+
fs.rmSync(options.dest, { recursive: true, force: true })
206+
fs.mkdirSync(options.dest, { recursive: true })
207+
208+
// copy src
209+
fs.cpSync(options.src, options.dest, {
210+
recursive: true,
211+
filter: (src) => !src.includes('node_modules') && !src.includes('dist'),
212+
})
213+
214+
// write additional files
215+
if (options.files) {
216+
for (const [filename, contents] of Object.entries(options.files)) {
217+
let filepath = path.join(options.dest, filename)
218+
fs.mkdirSync(path.dirname(filepath), { recursive: true })
219+
// strip indent
220+
const indent = contents.match(/^\s*/)?.[0] ?? ''
221+
const strippedContents = contents
222+
.split('\n')
223+
.map((line) => line.replace(new RegExp(`^${indent}`), ''))
224+
.join('\n')
225+
fs.writeFileSync(filepath, strippedContents)
226+
}
227+
}
228+
}

packages/plugin-rsc/e2e/starter.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,50 @@ test.describe('build-no-ssr', () => {
4343
})
4444

4545
test.describe(() => {
46-
const root = 'temp/starter-react-compiler'
46+
const root = 'examples/e2e/temp/starter-react-compiler'
4747

4848
test.beforeAll(async () => {
4949
await setupInlineFixture({
5050
src: 'examples/starter',
5151
dest: root,
52+
files: {
53+
'vite.config.ts': /* js */ `
54+
import rsc from '@vitejs/plugin-rsc'
55+
import react from '@vitejs/plugin-react'
56+
import { defineConfig } from 'vite'
57+
58+
export default defineConfig({
59+
plugins: [
60+
react({
61+
babel: { plugins: ['babel-plugin-react-compiler'] },
62+
}).map((p) => ({
63+
...p,
64+
applyToEnvironment: (e) => e.name === 'client',
65+
})),
66+
rsc({
67+
entries: {
68+
client: './src/framework/entry.browser.tsx',
69+
ssr: './src/framework/entry.ssr.tsx',
70+
rsc: './src/framework/entry.rsc.tsx',
71+
}
72+
}),
73+
],
74+
})
75+
`,
76+
},
5277
})
5378
})
5479

5580
test.describe('dev-react-compiler', () => {
5681
const f = useFixture({ root, mode: 'dev' })
5782
defineTest(f)
83+
84+
test('verify react compiler', async ({ page }) => {
85+
await page.goto(f.url())
86+
await waitForHydration_(page)
87+
const res = await page.request.get(f.url('src/client.tsx'))
88+
expect(await res.text()).toContain('react.memo_cache_sentinel')
89+
})
5890
})
5991

6092
test.describe('build-react-compiler', () => {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@vitejs/plugin-rsc-examples-e2e-temp",
3+
"private": true,
4+
"type": "module",
5+
"devDependencies": {
6+
"@vitejs/plugin-rsc": "latest",
7+
"@vitejs/plugin-react": "latest",
8+
"babel-plugin-react-compiler": "19.1.0-rc.2"
9+
}
10+
}

pnpm-lock.yaml

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)