( files: Fs, folderPrefix = 'vercel-node-tests', workPathPrefix = '' )
| 14 | }; |
| 15 | |
| 16 | export async function prepareFilesystem( |
| 17 | files: Fs, |
| 18 | folderPrefix = 'vercel-node-tests', |
| 19 | workPathPrefix = '' |
| 20 | ): Promise<Filesystem> { |
| 21 | const directory = join(tmpdir(), `${folderPrefix}-${Date.now()}`); |
| 22 | const workPath = workPathPrefix ? join(directory, workPathPrefix) : directory; |
| 23 | await fs.mkdir(workPath, { recursive: true }); |
| 24 | const fileRefs: Files = {}; |
| 25 | for (const [key, value] of Object.entries(files)) { |
| 26 | const fullPath = join(workPath, key); |
| 27 | await fs.mkdir(dirname(fullPath), { recursive: true }); |
| 28 | if (typeof value === 'string' || value instanceof Buffer) { |
| 29 | await fs.writeFile(join(workPath, key), value); |
| 30 | } else if (typeof value.copy === 'string') { |
| 31 | await fs.copyFile(join(workPath, value.copy), join(workPath, key)); |
| 32 | } |
| 33 | fileRefs[key] = await FileFsRef.fromFsPath({ |
| 34 | fsPath: join(workPath, key), |
| 35 | }); |
| 36 | } |
| 37 | return { |
| 38 | workPath, |
| 39 | repoRootPath: directory, |
| 40 | files: fileRefs, |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | export async function prepareFixtureFilesystem( |
| 45 | fixtureName: string, |
no test coverage detected