MCPcopy
hub / github.com/vitest-dev/vitest / runDynamicFileCJS

Function runDynamicFileCJS

test/coverage-test/fixtures/src/dynamic-files.ts:36–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34}
35
36export async function runDynamicFileCJS() {
37 const filename = fileURLToPath(new URL('./dynamic-file-cjs.ignore.cjs', import.meta.url))
38
39 if (existsSync(filename)) {
40 rmSync(filename)
41 }
42 onTestFinished(() => {
43 if(existsSync(filename)) {
44 rmSync(filename)
45 }
46 })
47
48 writeFileSync(filename, `
49// File created by coverage/fixtures/src/dynamic-files.ts
50module.exports.run = function run() {
51 return "Import works"
52}
53function uncovered() {}
54 `.trim(), 'utf-8')
55
56 const { run } = createRequire(import.meta.url)(filename)
57
58 if (run() !== 'Import works') {
59 throw new Error(`Failed to run ${filename}`)
60 }
61
62 return "Done"
63}

Callers 1

Calls 1

runFunction · 0.70

Tested by

no test coverage detected