Skip to content

Commit d9cb926

Browse files
authored
test(rsc): support fs:cp command in setupInlineFixture (#621)
1 parent 758dc73 commit d9cb926

File tree

3 files changed

+37
-42
lines changed

3 files changed

+37
-42
lines changed

packages/plugin-rsc/CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Best for testing specific edge cases or isolated features. See `e2e/ssr-thenable
3636
# Build packages
3737
pnpm dev # pnpm -C packages/plugin-rsc dev
3838

39+
# Type check
40+
pnpm -C packages/plugin-rsc tsc-dev
41+
3942
# Run examples
4043
pnpm -C packages/plugin-rsc/examples/basic dev # build / preview
4144
pnpm -C packages/plugin-rsc/examples/starter dev # build / preview

packages/plugin-rsc/e2e/fixture.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function editFileJson(filepath: string, edit: (s: string) => string) {
200200
export async function setupInlineFixture(options: {
201201
src: string
202202
dest: string
203-
files?: Record<string, string>
203+
files?: Record<string, string | { cp: string }>
204204
}) {
205205
fs.rmSync(options.dest, { recursive: true, force: true })
206206
fs.mkdirSync(options.dest, { recursive: true })
@@ -214,16 +214,24 @@ export async function setupInlineFixture(options: {
214214
// write additional files
215215
if (options.files) {
216216
for (let [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
217+
const destFile = path.join(options.dest, filename)
218+
fs.mkdirSync(path.dirname(destFile), { recursive: true })
219+
220+
// custom command
221+
if (typeof contents === 'object' && 'cp' in contents) {
222+
const srcFile = path.join(options.dest, contents.cp)
223+
fs.copyFileSync(srcFile, destFile)
224+
continue
225+
}
226+
227+
// write a new file
220228
contents = contents.replace(/^\n*/, '').replace(/\s*$/, '\n')
221229
const indent = contents.match(/^\s*/)?.[0] ?? ''
222230
const strippedContents = contents
223231
.split('\n')
224232
.map((line) => line.replace(new RegExp(`^${indent}`), ''))
225233
.join('\n')
226-
fs.writeFileSync(filepath, strippedContents)
234+
fs.writeFileSync(destFile, strippedContents)
227235
}
228236
}
229237
}

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

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,28 @@ test.describe(() => {
9292
src: 'examples/starter',
9393
dest: root,
9494
files: {
95+
'vite.config.base.ts': { cp: 'vite.config.ts' },
9596
'vite.config.ts': /* js */ `
9697
import rsc from '@vitejs/plugin-rsc'
9798
import react from '@vitejs/plugin-react'
98-
import { defineConfig } from 'vite'
99+
import { defineConfig, mergeConfig } from 'vite'
100+
import baseConfig from './vite.config.base.ts'
101+
102+
delete baseConfig.plugins
99103
100-
export default defineConfig({
104+
const overrideConfig = defineConfig({
101105
plugins: [
102106
react({
103107
babel: { plugins: ['babel-plugin-react-compiler'] },
104108
}).map((p) => ({
105109
...p,
106110
applyToEnvironment: (e) => e.name === 'client',
107111
})),
108-
rsc({
109-
entries: {
110-
client: './src/framework/entry.browser.tsx',
111-
ssr: './src/framework/entry.ssr.tsx',
112-
rsc: './src/framework/entry.rsc.tsx',
113-
}
114-
}),
112+
rsc(),
115113
],
116114
})
115+
116+
export default mergeConfig(baseConfig, overrideConfig)
117117
`,
118118
},
119119
})
@@ -145,24 +145,16 @@ test.describe(() => {
145145
src: 'examples/starter',
146146
dest: root,
147147
files: {
148+
'vite.config.base.ts': { cp: 'vite.config.ts' },
148149
'vite.config.ts': /* js */ `
149-
import rsc from '@vitejs/plugin-rsc'
150-
import react from '@vitejs/plugin-react'
151-
import { defineConfig } from 'vite'
150+
import { defineConfig, mergeConfig } from 'vite'
151+
import baseConfig from './vite.config.base.ts'
152152
153-
export default defineConfig({
153+
const overrideConfig = defineConfig({
154154
base: '/custom-base/',
155-
plugins: [
156-
react(),
157-
rsc({
158-
entries: {
159-
client: './src/framework/entry.browser.tsx',
160-
ssr: './src/framework/entry.ssr.tsx',
161-
rsc: './src/framework/entry.rsc.tsx',
162-
}
163-
}),
164-
],
165155
})
156+
157+
export default mergeConfig(baseConfig, overrideConfig)
166158
`,
167159
},
168160
})
@@ -193,22 +185,12 @@ test.describe(() => {
193185
src: 'examples/starter',
194186
dest: root,
195187
files: {
188+
'vite.config.base.ts': { cp: 'vite.config.ts' },
196189
'vite.config.ts': /* js */ `
197-
import rsc from '@vitejs/plugin-rsc'
198-
import react from '@vitejs/plugin-react'
199-
import { defineConfig, createRunnableDevEnvironment } from 'vite'
190+
import { defineConfig, mergeConfig, createRunnableDevEnvironment } from 'vite'
191+
import baseConfig from './vite.config.base.ts'
200192
201-
export default defineConfig({
202-
plugins: [
203-
react(),
204-
rsc({
205-
entries: {
206-
client: './src/framework/entry.browser.tsx',
207-
ssr: './src/framework/entry.ssr.tsx',
208-
rsc: './src/framework/entry.rsc.tsx',
209-
}
210-
}),
211-
],
193+
const overrideConfig = defineConfig({
212194
environments: {
213195
ssr: {
214196
dev: {
@@ -234,6 +216,8 @@ test.describe(() => {
234216
},
235217
},
236218
})
219+
220+
export default mergeConfig(baseConfig, overrideConfig)
237221
`,
238222
},
239223
})

0 commit comments

Comments
 (0)