| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 16d2fd3 commit 2004e25
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,17 +5,17 @@ import path from 'node:path'; | |||
| 5 | 5 | import { execPath } from 'node:process'; | |
| 6 | 6 | import { describe, it } from 'node:test'; | |
| 7 | 7 | import { spawn } from 'node:child_process'; | |
| 8 | - import { writeFileSync, readFileSync } from 'node:fs'; | ||
| 8 | + import { appendFileSync, mkdirSync, writeFileSync } from 'node:fs'; | ||
| 9 | 9 | import { inspect } from 'node:util'; | |
| 10 | 10 | import { pathToFileURL } from 'node:url'; | |
| 11 | 11 | import { createInterface } from 'node:readline'; | |
| 12 | 12 | ||
| 13 | 13 | if (common.isIBMi) | |
| 14 | 14 | common.skip('IBMi does not support `fs.watch()`'); | |
| 15 | 15 | ||
| 16 | - function restart(file, content = readFileSync(file)) { | ||
| 17 | - writeFileSync(file, content); | ||
| 18 | - const timer = setInterval(() => writeFileSync(file, content), common.platformTimeout(250)); | ||
| 16 | + function restart(file) { | ||
| 17 | + appendFileSync(file, '\n'); | ||
| 18 | + const timer = setInterval(() => appendFileSync(file, '\n'), common.platformTimeout(250)); | ||
| 19 | 19 | return () => clearInterval(timer); | |
| 20 | 20 | } | |
| 21 | 21 | ||
@@ -26,6 +26,12 @@ function createTmpFile(content = 'console.log(\'running\');', ext = '.js', basen | |||
| 26 | 26 | return file; | |
| 27 | 27 | } | |
| 28 | 28 | ||
| 29 | + function createTmpDir() { | ||
| 30 | + const dir = path.join(tmpdir.path, `${tmpFiles++}`); | ||
| 31 | + mkdirSync(dir); | ||
| 32 | + return dir; | ||
| 33 | + } | ||
| 34 | + | ||
| 29 | 35 | async function runWriteSucceed({ | |
| 30 | 36 | file, | |
| 31 | 37 | watchedFile, | |
@@ -78,10 +84,10 @@ async function runWriteSucceed({ | |||
| 78 | 84 | } | |
| 79 | 85 | ||
| 80 | 86 | tmpdir.refresh(); | |
| 81 | - const dir = tmpdir.path; | ||
| 82 | 87 | ||
| 83 | 88 | describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_000 }, () => { | |
| 84 | 89 | it('should watch changes to worker - cjs', async () => { | |
| 90 | + const dir = createTmpDir(); | ||
| 85 | 91 | const worker = path.join(dir, 'worker.js'); | |
| 86 | 92 | ||
| 87 | 93 | writeFileSync(worker, ` | |
@@ -109,6 +115,7 @@ const w = new Worker(${JSON.stringify(worker)}); | |||
| 109 | 115 | }); | |
| 110 | 116 | ||
| 111 | 117 | it('should watch changes to worker dependencies - cjs', async () => { | |
| 118 | + const dir = createTmpDir(); | ||
| 112 | 119 | const dep = path.join(dir, 'dep.js'); | |
| 113 | 120 | const worker = path.join(dir, 'worker.js'); | |
| 114 | 121 | ||
@@ -142,6 +149,7 @@ const w = new Worker(${JSON.stringify(worker)}); | |||
| 142 | 149 | }); | |
| 143 | 150 | ||
| 144 | 151 | it('should watch changes to nested worker dependencies - cjs', async () => { | |
| 152 | + const dir = createTmpDir(); | ||
| 145 | 153 | const subDep = path.join(dir, 'sub-dep.js'); | |
| 146 | 154 | const dep = path.join(dir, 'dep.js'); | |
| 147 | 155 | const worker = path.join(dir, 'worker.js'); | |
@@ -181,6 +189,7 @@ const w = new Worker(${JSON.stringify(worker)}); | |||
| 181 | 189 | }); | |
| 182 | 190 | ||
| 183 | 191 | it('should watch changes to worker - esm', async () => { | |
| 192 | + const dir = createTmpDir(); | ||
| 184 | 193 | const worker = path.join(dir, 'worker.mjs'); | |
| 185 | 194 | ||
| 186 | 195 | writeFileSync(worker, ` | |
@@ -208,6 +217,7 @@ new Worker(new URL(${JSON.stringify(pathToFileURL(worker))})); | |||
| 208 | 217 | }); | |
| 209 | 218 | ||
| 210 | 219 | it('should watch changes to worker dependencies - esm', async () => { | |
| 220 | + const dir = createTmpDir(); | ||
| 211 | 221 | const dep = path.join(dir, 'dep.mjs'); | |
| 212 | 222 | const worker = path.join(dir, 'worker.mjs'); | |
| 213 | 223 | ||
@@ -241,6 +251,7 @@ new Worker(new URL(${JSON.stringify(pathToFileURL(worker))})); | |||
| 241 | 251 | }); | |
| 242 | 252 | ||
| 243 | 253 | it('should watch changes to nested worker dependencies - esm', async () => { | |
| 254 | + const dir = createTmpDir(); | ||
| 244 | 255 | const subDep = path.join(dir, 'sub-dep.mjs'); | |
| 245 | 256 | const dep = path.join(dir, 'dep.mjs'); | |
| 246 | 257 | const worker = path.join(dir, 'worker.mjs'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments