| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8f611b9 commit 5a976cb
20 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,20 +47,58 @@ function refreshForTestRunnerWatch() { | |||
| 47 | 47 | } | |
| 48 | 48 | } | |
| 49 | 49 | ||
| 50 | + async function performFileOperation(operation, useRunApi, timeout = 1000) { | ||
| 51 | + if (useRunApi) { | ||
| 52 | + const interval = setInterval(() => { | ||
| 53 | + operation(); | ||
| 54 | + clearInterval(interval); | ||
| 55 | + }, common.platformTimeout(timeout)); | ||
| 56 | + } else { | ||
| 57 | + operation(); | ||
| 58 | + await setTimeout(common.platformTimeout(timeout)); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + function assertTestOutput(run, shouldCheckRecursion = false) { | ||
| 63 | + if (shouldCheckRecursion) { | ||
| 64 | + assert.doesNotMatch(run, /run\(\) is being called recursively/); | ||
| 65 | + } | ||
| 66 | + assert.match(run, /tests 1/); | ||
| 67 | + assert.match(run, /pass 1/); | ||
| 68 | + assert.match(run, /fail 0/); | ||
| 69 | + assert.match(run, /cancelled 0/); | ||
| 70 | + } | ||
| 71 | + | ||
| 50 | 72 | async function testRunnerWatch({ | |
| 51 | 73 | fileToUpdate, | |
| 52 | 74 | file, | |
| 53 | 75 | action = 'update', | |
| 54 | 76 | fileToCreate, | |
| 55 | 77 | isolation, | |
| 78 | + useRunApi = false, | ||
| 79 | + cwd = tmpdir.path, | ||
| 80 | + runnerCwd, | ||
| 56 | 81 | }) { | |
| 57 | 82 | const ran1 = Promise.withResolvers(); | |
| 58 | 83 | const ran2 = Promise.withResolvers(); | |
| 59 | - const child = spawn(process.execPath, | ||
| 60 | - ['--watch', '--test', '--test-reporter=spec', | ||
| 61 | - isolation ? `--test-isolation=${isolation}` : '', | ||
| 62 | - file ? fixturePaths[file] : undefined].filter(Boolean), | ||
| 63 | - { encoding: 'utf8', stdio: 'pipe', cwd: tmpdir.path }); | ||
| 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 }); | ||
| 64 | 102 | let stdout = ''; | |
| 65 | 103 | let currentRun = ''; | |
| 66 | 104 | const runs = []; | |
@@ -79,20 +117,28 @@ async function testRunnerWatch({ | |||
| 79 | 117 | currentRun = ''; | |
| 80 | 118 | const content = fixtureContent[fileToUpdate]; | |
| 81 | 119 | const path = fixturePaths[fileToUpdate]; | |
| 82 | - writeFileSync(path, content); | ||
| 83 | - await setTimeout(common.platformTimeout(1000)); | ||
| 84 | - await ran2.promise; | ||
| 120 | + | ||
| 121 | + if (useRunApi) { | ||
| 122 | + const interval = setInterval( | ||
| 123 | + () => writeFileSync(path, content), | ||
| 124 | + common.platformTimeout(1000), | ||
| 125 | + ); | ||
| 126 | + await ran2.promise; | ||
| 127 | + clearInterval(interval); | ||
| 128 | + } else { | ||
| 129 | + writeFileSync(path, content); | ||
| 130 | + await setTimeout(common.platformTimeout(1000)); | ||
| 131 | + await ran2.promise; | ||
| 132 | + } | ||
| 133 | + | ||
| 85 | 134 | runs.push(currentRun); | |
| 86 | 135 | child.kill(); | |
| 87 | 136 | await once(child, 'exit'); | |
| 88 | 137 | ||
| 89 | 138 | assert.strictEqual(runs.length, 2); | |
| 90 | 139 | ||
| 91 | 140 | for (const run of runs) { | |
| 92 | - assert.match(run, /tests 1/); | ||
| 93 | - assert.match(run, /pass 1/); | ||
| 94 | - assert.match(run, /fail 0/); | ||
| 95 | - assert.match(run, /cancelled 0/); | ||
| 141 | + assertTestOutput(run, useRunApi); | ||
| 96 | 142 | } | |
| 97 | 143 | }; | |
| 98 | 144 | ||
@@ -102,31 +148,53 @@ async function testRunnerWatch({ | |||
| 102 | 148 | currentRun = ''; | |
| 103 | 149 | const fileToRenamePath = tmpdir.resolve(fileToUpdate); | |
| 104 | 150 | const newFileNamePath = tmpdir.resolve(`test-renamed-${fileToUpdate}`); | |
| 105 | - renameSync(fileToRenamePath, newFileNamePath); | ||
| 106 | - await setTimeout(common.platformTimeout(1000)); | ||
| 151 | + | ||
| 152 | + await performFileOperation( | ||
| 153 | + () => renameSync(fileToRenamePath, newFileNamePath), | ||
| 154 | + useRunApi, | ||
| 155 | + ); | ||
| 107 | 156 | await ran2.promise; | |
| 157 | + | ||
| 108 | 158 | runs.push(currentRun); | |
| 109 | 159 | child.kill(); | |
| 110 | 160 | await once(child, 'exit'); | |
| 111 | 161 | ||
| 112 | 162 | assert.strictEqual(runs.length, 2); | |
| 113 | 163 | ||
| 114 | - for (const run of runs) { | ||
| 115 | - assert.match(run, /tests 1/); | ||
| 116 | - assert.match(run, /pass 1/); | ||
| 117 | - assert.match(run, /fail 0/); | ||
| 118 | - assert.match(run, /cancelled 0/); | ||
| 164 | + const [firstRun, secondRun] = runs; | ||
| 165 | + assertTestOutput(firstRun, useRunApi); | ||
| 166 | + | ||
| 167 | + if (action === 'rename2') { | ||
| 168 | + assert.match(secondRun, /MODULE_NOT_FOUND/); | ||
| 169 | + return; | ||
| 119 | 170 | } | |
| 171 | + | ||
| 172 | + assertTestOutput(secondRun, useRunApi); | ||
| 120 | 173 | }; | |
| 121 | 174 | ||
| 122 | 175 | const testDelete = async () => { | |
| 123 | 176 | await ran1.promise; | |
| 124 | 177 | runs.push(currentRun); | |
| 125 | 178 | currentRun = ''; | |
| 126 | 179 | const fileToDeletePath = tmpdir.resolve(fileToUpdate); | |
| 127 | - unlinkSync(fileToDeletePath); | ||
| 128 | - await setTimeout(common.platformTimeout(2000)); | ||
| 129 | - ran2.resolve(); | ||
| 180 | + | ||
| 181 | + if (useRunApi) { | ||
| 182 | + const { existsSync } = require('node:fs'); | ||
| 183 | + const interval = setInterval(() => { | ||
| 184 | + if (existsSync(fileToDeletePath)) { | ||
| 185 | + unlinkSync(fileToDeletePath); | ||
| 186 | + } else { | ||
| 187 | + ran2.resolve(); | ||
| 188 | + clearInterval(interval); | ||
| 189 | + } | ||
| 190 | + }, common.platformTimeout(1000)); | ||
| 191 | + await ran2.promise; | ||
| 192 | + } else { | ||
| 193 | + unlinkSync(fileToDeletePath); | ||
| 194 | + await setTimeout(common.platformTimeout(2000)); | ||
| 195 | + ran2.resolve(); | ||
| 196 | + } | ||
| 197 | + | ||
| 130 | 198 | runs.push(currentRun); | |
| 131 | 199 | child.kill(); | |
| 132 | 200 | await once(child, 'exit'); | |
@@ -143,25 +211,29 @@ async function testRunnerWatch({ | |||
| 143 | 211 | runs.push(currentRun); | |
| 144 | 212 | currentRun = ''; | |
| 145 | 213 | const newFilePath = tmpdir.resolve(fileToCreate); | |
| 146 | - writeFileSync(newFilePath, 'module.exports = {};'); | ||
| 147 | - await setTimeout(common.platformTimeout(1000)); | ||
| 214 | + | ||
| 215 | + await performFileOperation( | ||
| 216 | + () => writeFileSync(newFilePath, 'module.exports = {};'), | ||
| 217 | + useRunApi, | ||
| 218 | + ); | ||
| 148 | 219 | await ran2.promise; | |
| 220 | + | ||
| 149 | 221 | runs.push(currentRun); | |
| 150 | 222 | child.kill(); | |
| 151 | 223 | await once(child, 'exit'); | |
| 152 | 224 | ||
| 153 | 225 | for (const run of runs) { | |
| 154 | - assert.match(run, /tests 1/); | ||
| 155 | - assert.match(run, /pass 1/); | ||
| 156 | - assert.match(run, /fail 0/); | ||
| 157 | - assert.match(run, /cancelled 0/); | ||
| 226 | + assertTestOutput(run, false); | ||
| 158 | 227 | } | |
| 159 | 228 | }; | |
| 160 | 229 | ||
| 161 | 230 | action === 'update' && await testUpdate(); | |
| 162 | 231 | action === 'rename' && await testRename(); | |
| 232 | + action === 'rename2' && await testRename(); | ||
| 163 | 233 | action === 'delete' && await testDelete(); | |
| 164 | 234 | action === 'create' && await testCreate(); | |
| 235 | + | ||
| 236 | + return runs; | ||
| 165 | 237 | } | |
| 166 | 238 | ||
| 167 | 239 | ||
@@ -170,4 +242,6 @@ module.exports = { | |||
| 170 | 242 | skipIfNoWatchModeSignals, | |
| 171 | 243 | testRunnerWatch, | |
| 172 | 244 | refreshForTestRunnerWatch, | |
| 245 | + fixtureContent, | ||
| 246 | + fixturePaths, | ||
| 173 | 247 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,8 +24,6 @@ test-snapshot-incompatible: SKIP | |||
| 24 | 24 | test-inspector-network-fetch: PASS, FLAKY | |
| 25 | 25 | # https://github.com/nodejs/node/issues/54808 | |
| 26 | 26 | test-async-context-frame: PASS, FLAKY | |
| 27 | - # https://github.com/nodejs/node/issues/54534 | ||
| 28 | - test-runner-run-watch: PASS, FLAKY | ||
| 29 | 27 | # https://github.com/nodejs/node/issues/59636 | |
| 30 | 28 | test-fs-cp-sync-error-on-exist: SKIP | |
| 31 | 29 | test-fs-cp-sync-symlink-points-to-dest-error: SKIP | |
@@ -43,8 +41,6 @@ test-without-async-context-frame: PASS, FLAKY | |||
| 43 | 41 | test-performance-function: PASS, FLAKY | |
| 44 | 42 | # https://github.com/nodejs/node/issues/54346 | |
| 45 | 43 | test-esm-loader-hooks-inspect-wait: PASS, FLAKY | |
| 46 | - # https://github.com/nodejs/node/issues/54534 | ||
| 47 | - test-runner-run-watch: PASS, FLAKY | ||
| 48 | 44 | ||
| 49 | 45 | [$system==linux && $arch==s390x] | |
| 50 | 46 | # https://github.com/nodejs/node/issues/58353 | |
@@ -54,8 +50,6 @@ test-http2-debug: PASS, FLAKY | |||
| 54 | 50 | # https://github.com/nodejs/node/issues/42741 | |
| 55 | 51 | test-http-server-headers-timeout-keepalive: PASS,FLAKY | |
| 56 | 52 | test-http-server-request-timeout-keepalive: PASS,FLAKY | |
| 57 | - # https://github.com/nodejs/node/issues/54534 | ||
| 58 | - test-runner-run-watch: PASS, FLAKY | ||
| 59 | 53 | # https://github.com/nodejs/node/issues/60050 | |
| 60 | 54 | test-cluster-dgram-1: SKIP | |
| 61 | 55 | ||
@@ -85,8 +79,6 @@ test-esm-loader-hooks-inspect-wait: PASS, FLAKY | |||
| 85 | 79 | test-fs-promises-watch-iterator: SKIP | |
| 86 | 80 | # https://github.com/nodejs/node/issues/50050 | |
| 87 | 81 | test-tick-processor-arguments: SKIP | |
| 88 | - # https://github.com/nodejs/node/issues/54534 | ||
| 89 | - test-runner-run-watch: PASS, FLAKY | ||
| 90 | 82 | ||
| 91 | 83 | [$system==freebsd] | |
| 92 | 84 | # https://github.com/nodejs/node/issues/54346 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments