Skip to content

Commit 707f35b

Browse files
authored
test(rsc): split starter tests into multiple files (#629)
1 parent 24ddea4 commit 707f35b

File tree

10 files changed

+511
-485
lines changed

10 files changed

+511
-485
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { test } from '@playwright/test'
2+
import { setupInlineFixture, useFixture } from './fixture'
3+
import { defineStarterTest } from './starter'
4+
5+
test.describe(() => {
6+
const root = 'examples/e2e/temp/base'
7+
8+
test.beforeAll(async () => {
9+
await setupInlineFixture({
10+
src: 'examples/starter',
11+
dest: root,
12+
files: {
13+
'vite.config.base.ts': { cp: 'vite.config.ts' },
14+
'vite.config.ts': /* js */ `
15+
import { defineConfig, mergeConfig } from 'vite'
16+
import baseConfig from './vite.config.base.ts'
17+
18+
const overrideConfig = defineConfig({
19+
base: '/custom-base/',
20+
})
21+
22+
export default mergeConfig(baseConfig, overrideConfig)
23+
`,
24+
},
25+
})
26+
})
27+
28+
test.describe('dev-base', () => {
29+
const f = useFixture({ root, mode: 'dev' })
30+
defineStarterTest({
31+
...f,
32+
url: (url) => new URL(url ?? './', f.url('./custom-base/')).href,
33+
})
34+
})
35+
36+
test.describe('build-base', () => {
37+
const f = useFixture({ root, mode: 'build' })
38+
defineStarterTest({
39+
...f,
40+
url: (url) => new URL(url ?? './', f.url('./custom-base/')).href,
41+
})
42+
})
43+
})

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { createHash } from 'node:crypto'
22
import { readFileSync } from 'node:fs'
33
import { type Page, expect, test } from '@playwright/test'
4-
import { type Fixture, setupIsolatedFixture, useFixture } from './fixture'
4+
import { type Fixture, useFixture } from './fixture'
55
import {
66
expectNoPageError,
77
expectNoReload,
88
testNoJs,
99
waitForHydration,
1010
} from './helper'
11-
import path from 'node:path'
12-
import os from 'node:os'
1311

1412
test.describe('dev-default', () => {
1513
const f = useFixture({ root: 'examples/basic', mode: 'dev' })
@@ -48,31 +46,6 @@ test.describe('build-default', () => {
4846
defineTest(f)
4947
})
5048

51-
test.describe(() => {
52-
// disabled by default
53-
if (process.env.TEST_ISOLATED !== 'true') return
54-
55-
// use RUNNER_TEMP on Github Actions
56-
// https://github.com/actions/toolkit/issues/518
57-
const tmpRoot = path.join(
58-
process.env['RUNNER_TEMP'] || os.tmpdir(),
59-
'test-vite-rsc',
60-
)
61-
test.beforeAll(async () => {
62-
await setupIsolatedFixture({ src: 'examples/basic', dest: tmpRoot })
63-
})
64-
65-
test.describe('dev-isolated', () => {
66-
const f = useFixture({ root: tmpRoot, mode: 'dev' })
67-
defineTest(f)
68-
})
69-
70-
test.describe('build-isolated', () => {
71-
const f = useFixture({ root: tmpRoot, mode: 'build' })
72-
defineTest(f)
73-
})
74-
})
75-
7649
function defineTest(f: Fixture) {
7750
test('basic', async ({ page }) => {
7851
using _ = expectNoPageError(page)

packages/plugin-rsc/e2e/fixture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export async function setupIsolatedFixture(options: {
162162
const packagesDir = path.join(import.meta.dirname, '..', '..')
163163
const overrides = {
164164
'@vitejs/plugin-rsc': `file:${path.join(packagesDir, 'plugin-rsc')}`,
165+
'@vitejs/plugin-react': `file:${path.join(packagesDir, 'plugin-react')}`,
165166
}
166167
editFileJson(path.join(options.dest, 'package.json'), (pkg: any) => {
167168
Object.assign(((pkg.pnpm ??= {}).overrides ??= {}), overrides)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { test } from '@playwright/test'
2+
import { setupIsolatedFixture, useFixture } from './fixture'
3+
import { defineStarterTest } from './starter'
4+
import path from 'node:path'
5+
import os from 'node:os'
6+
7+
test.describe(() => {
8+
// use RUNNER_TEMP on Github Actions
9+
// https://github.com/actions/toolkit/issues/518
10+
const tmpRoot = path.join(
11+
process.env['RUNNER_TEMP'] || os.tmpdir(),
12+
'test-vite-rsc',
13+
)
14+
test.beforeAll(async () => {
15+
await setupIsolatedFixture({ src: 'examples/starter', dest: tmpRoot })
16+
})
17+
18+
test.describe('dev-isolated', () => {
19+
const f = useFixture({ root: tmpRoot, mode: 'dev' })
20+
defineStarterTest(f)
21+
})
22+
23+
test.describe('build-isolated', () => {
24+
const f = useFixture({ root: tmpRoot, mode: 'build' })
25+
defineStarterTest(f)
26+
})
27+
})
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { test } from '@playwright/test'
2+
import { setupInlineFixture, useFixture } from './fixture'
3+
import { defineStarterTest } from './starter'
4+
5+
test.describe(() => {
6+
const root = 'examples/e2e/temp/module-runner-hmr-false'
7+
8+
test.beforeAll(async () => {
9+
await setupInlineFixture({
10+
src: 'examples/starter',
11+
dest: root,
12+
files: {
13+
'vite.config.base.ts': { cp: 'vite.config.ts' },
14+
'vite.config.ts': /* js */ `
15+
import { defineConfig, mergeConfig, createRunnableDevEnvironment } from 'vite'
16+
import baseConfig from './vite.config.base.ts'
17+
18+
const overrideConfig = defineConfig({
19+
environments: {
20+
ssr: {
21+
dev: {
22+
createEnvironment(name, config) {
23+
return createRunnableDevEnvironment(name, config, {
24+
runnerOptions: {
25+
hmr: false,
26+
},
27+
})
28+
},
29+
},
30+
},
31+
rsc: {
32+
dev: {
33+
createEnvironment(name, config) {
34+
return createRunnableDevEnvironment(name, config, {
35+
runnerOptions: {
36+
hmr: false,
37+
},
38+
})
39+
},
40+
},
41+
},
42+
},
43+
})
44+
45+
export default mergeConfig(baseConfig, overrideConfig)
46+
`,
47+
},
48+
})
49+
})
50+
51+
test.describe('dev-module-runner-hmr-false', () => {
52+
const f = useFixture({ root, mode: 'dev' })
53+
defineStarterTest(f)
54+
})
55+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect, test } from '@playwright/test'
2+
import { useFixture } from './fixture'
3+
import { defineStarterTest } from './starter'
4+
import path from 'node:path'
5+
import fs from 'node:fs'
6+
7+
test.describe('dev-no-ssr', () => {
8+
const f = useFixture({ root: 'examples/no-ssr', mode: 'dev' })
9+
defineStarterTest(f, 'no-ssr')
10+
})
11+
12+
test.describe('build-no-ssr', () => {
13+
const f = useFixture({ root: 'examples/no-ssr', mode: 'build' })
14+
defineStarterTest(f, 'no-ssr')
15+
16+
test('no ssr build', () => {
17+
expect(fs.existsSync(path.join(f.root, 'dist/ssr'))).toBe(false)
18+
})
19+
})
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { expect, test } from '@playwright/test'
2+
import { setupInlineFixture, useFixture } from './fixture'
3+
import { defineStarterTest } from './starter'
4+
import { waitForHydration } from './helper'
5+
6+
test.describe(() => {
7+
const root = 'examples/e2e/temp/react-compiler'
8+
9+
test.beforeAll(async () => {
10+
await setupInlineFixture({
11+
src: 'examples/starter',
12+
dest: root,
13+
files: {
14+
'vite.config.base.ts': { cp: 'vite.config.ts' },
15+
'vite.config.ts': /* js */ `
16+
import rsc from '@vitejs/plugin-rsc'
17+
import react from '@vitejs/plugin-react'
18+
import { defineConfig, mergeConfig } from 'vite'
19+
import baseConfig from './vite.config.base.ts'
20+
21+
delete baseConfig.plugins
22+
23+
const overrideConfig = defineConfig({
24+
plugins: [
25+
react({
26+
babel: { plugins: ['babel-plugin-react-compiler'] },
27+
}).map((p) => ({
28+
...p,
29+
applyToEnvironment: (e) => e.name === 'client',
30+
})),
31+
rsc(),
32+
],
33+
})
34+
35+
export default mergeConfig(baseConfig, overrideConfig)
36+
`,
37+
},
38+
})
39+
})
40+
41+
test.describe('dev-react-compiler', () => {
42+
const f = useFixture({ root, mode: 'dev' })
43+
defineStarterTest(f)
44+
45+
test('verify react compiler', async ({ page }) => {
46+
await page.goto(f.url())
47+
await waitForHydration(page)
48+
const res = await page.request.get(f.url('src/client.tsx'))
49+
expect(await res.text()).toContain('react.memo_cache_sentinel')
50+
})
51+
})
52+
53+
test.describe('build-react-compiler', () => {
54+
const f = useFixture({ root, mode: 'build' })
55+
defineStarterTest(f)
56+
})
57+
})

0 commit comments

Comments
 (0)