Skip to content

Commit 179802f

Browse files
committed
test: tweak
1 parent 4d55e63 commit 179802f

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

packages/plugin-rsc/e2e/fixture.ts

Lines changed: 10 additions & 13 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,20 +214,17 @@ export async function setupInlineFixture(options: {
214214
// write additional files
215215
if (options.files) {
216216
for (let [filename, contents] of Object.entries(options.files)) {
217-
// custom fs command
218-
if (contents.startsWith('fs:cp:')) {
219-
const src = contents.slice('fs:cp:'.length)
220-
const srcPath = path.resolve(options.src, src)
221-
if (!fs.existsSync(srcPath)) {
222-
throw new Error(`Source file does not exist: ${srcPath}`)
223-
}
224-
fs.cpSync(srcPath, path.join(options.dest, filename), {
225-
recursive: true,
226-
})
217+
// custom command
218+
if (typeof contents === 'object' && 'cp' in contents) {
219+
const srcFile = path.join(options.dest, contents.cp)
220+
const destFile = path.join(options.dest, filename)
221+
fs.mkdirSync(path.dirname(srcFile), { recursive: true })
222+
fs.mkdirSync(path.dirname(destFile), { recursive: true })
223+
fs.cpSync(srcFile, destFile, { recursive: true })
227224
continue
228225
}
229-
// write new file
230-
let filepath = path.join(options.dest, filename)
226+
// write a file
227+
const filepath = path.join(options.dest, filename)
231228
fs.mkdirSync(path.dirname(filepath), { recursive: true })
232229
// strip indent
233230
contents = contents.replace(/^\n*/, '').replace(/\s*$/, '\n')

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test.describe(() => {
9292
src: 'examples/starter',
9393
dest: root,
9494
files: {
95-
'vite.config.base.ts': 'fs:cp:vite.config.ts',
95+
'vite.config.base.ts': { cp: 'vite.config.ts' },
9696
'vite.config.ts': /* js */ `
9797
import rsc from '@vitejs/plugin-rsc'
9898
import react from '@vitejs/plugin-react'
@@ -145,7 +145,7 @@ test.describe(() => {
145145
src: 'examples/starter',
146146
dest: root,
147147
files: {
148-
'vite.config.base.ts': 'fs:cp:vite.config.ts',
148+
'vite.config.base.ts': { cp: 'vite.config.ts' },
149149
'vite.config.ts': /* js */ `
150150
import { defineConfig, mergeConfig } from 'vite'
151151
import baseConfig from './vite.config.base.ts'
@@ -185,7 +185,7 @@ test.describe(() => {
185185
src: 'examples/starter',
186186
dest: root,
187187
files: {
188-
'vite.config.base.ts': 'fs:cp:vite.config.ts',
188+
'vite.config.base.ts': { cp: 'vite.config.ts' },
189189
'vite.config.ts': /* js */ `
190190
import { defineConfig, mergeConfig, createRunnableDevEnvironment } from 'vite'
191191
import baseConfig from './vite.config.base.ts'

0 commit comments

Comments
 (0)