(content: TestFsStructure[string])
| 413 | } |
| 414 | |
| 415 | function getGeneratedFileContent(content: TestFsStructure[string]) { |
| 416 | if (typeof content === 'string') { |
| 417 | return content |
| 418 | } |
| 419 | if (typeof content === 'function') { |
| 420 | const code = `await (${stripIndent(String(content))})()` |
| 421 | return code |
| 422 | } |
| 423 | if (Array.isArray(content) && typeof content[1] === 'object' && ('exports' in content[1] || 'imports' in content[1])) { |
| 424 | const imports = Object.entries(content[1].imports || []) |
| 425 | const code = ` |
| 426 | ${imports.map(([path, is]) => `import { ${is.join(', ')} } from '${path}'`)} |
| 427 | const results = await (${stripIndent(String(content[0]))})({ ${imports.flatMap(([_, is]) => is).join(', ')} }) |
| 428 | ${(content[1].exports || []).map(e => `export const ${e} = results["${e}"]`)} |
| 429 | ` |
| 430 | return code |
| 431 | } |
| 432 | if ('test' in content && content.test?.browser?.enabled && content.test?.browser?.provider?.name) { |
| 433 | const name = content.test.browser.provider.name |
| 434 | return ` |
| 435 | import { ${name} } from '@vitest/browser-${name}' |
| 436 | const config = ${JSON.stringify(content)} |
| 437 | config.test.browser.provider = ${name}(${JSON.stringify(content.test.browser.provider.options || {})}) |
| 438 | export default config |
| 439 | ` |
| 440 | } |
| 441 | return `export default ${JSON.stringify(content)}` |
| 442 | } |
| 443 | |
| 444 | export function useFS<T extends TestFsStructure>(root: string, structure: T, ensureConfig = true, task?: TestContext['task']) { |
| 445 | const files = new Set<string>() |
no test coverage detected