({
fileToUpdate,
file,
action = 'update',
fileToCreate,
isolation,
useRunApi = false,
cwd = tmpdir.path,
runnerCwd,
})
| 70 | } |
| 71 | |
| 72 | async function testRunnerWatch({ |
| 73 | fileToUpdate, |
| 74 | file, |
| 75 | action = 'update', |
| 76 | fileToCreate, |
| 77 | isolation, |
| 78 | useRunApi = false, |
| 79 | cwd = tmpdir.path, |
| 80 | runnerCwd, |
| 81 | }) { |
| 82 | const ran1 = Promise.withResolvers(); |
| 83 | const ran2 = Promise.withResolvers(); |
| 84 | |
| 85 | let args; |
| 86 | if (useRunApi) { |
| 87 | // Use the fixture that calls run() API |
| 88 | const runner = fixtures.path('test-runner-watch.mjs'); |
| 89 | args = [runner]; |
| 90 | if (file) args.push('--file', file); |
| 91 | if (runnerCwd) args.push('--cwd', runnerCwd); |
| 92 | if (isolation) args.push('--isolation', isolation); |
| 93 | } else { |
| 94 | // Use CLI --watch --test flags |
| 95 | args = ['--watch', '--test', '--test-reporter=spec', |
| 96 | isolation ? `--test-isolation=${isolation}` : '', |
| 97 | file ? fixturePaths[file] : undefined].filter(Boolean); |
| 98 | } |
| 99 | |
| 100 | const child = spawn(process.execPath, args, |
| 101 | { encoding: 'utf8', stdio: 'pipe', cwd }); |
| 102 | let stdout = ''; |
| 103 | let currentRun = ''; |
| 104 | const runs = []; |
| 105 | |
| 106 | child.stdout.on('data', (data) => { |
| 107 | stdout += data.toString(); |
| 108 | currentRun += data.toString(); |
| 109 | const testRuns = stdout.match(/^\S+ duration_ms\s\d+/gm); |
| 110 | if (testRuns?.length >= 1) ran1.resolve(); |
| 111 | if (testRuns?.length >= 2) ran2.resolve(); |
| 112 | }); |
| 113 | |
| 114 | const testUpdate = async () => { |
| 115 | await ran1.promise; |
| 116 | runs.push(currentRun); |
| 117 | currentRun = ''; |
| 118 | const content = fixtureContent[fileToUpdate]; |
| 119 | const path = fixturePaths[fileToUpdate]; |
| 120 | |
| 121 | await performFileOperation( |
| 122 | () => writeFileSync(path, content), |
| 123 | useRunApi, |
| 124 | ); |
| 125 | await ran2.promise; |
| 126 | |
| 127 | runs.push(currentRun); |
| 128 | child.kill(); |
| 129 | await once(child, 'exit'); |
no test coverage detected
searching dependent graphs…