(testCase)
| 42 | tmpdir.refresh(); |
| 43 | |
| 44 | function doWatchTest(testCase) { |
| 45 | let interval; |
| 46 | const pathToWatch = testCase[testCase.field]; |
| 47 | const watcher = fs.watch(pathToWatch); |
| 48 | watcher.on('error', (err) => { |
| 49 | if (interval) { |
| 50 | clearInterval(interval); |
| 51 | interval = null; |
| 52 | } |
| 53 | assert.fail(err); |
| 54 | }); |
| 55 | watcher.on('close', common.mustCall(() => { |
| 56 | watcher.close(); // Closing a closed watcher should be a noop |
| 57 | })); |
| 58 | watcher.on('change', common.mustCall(function(eventType, argFilename) { |
| 59 | if (interval) { |
| 60 | clearInterval(interval); |
| 61 | interval = null; |
| 62 | } |
| 63 | if (common.isMacOS) |
| 64 | assert.strictEqual(['rename', 'change'].includes(eventType), true); |
| 65 | else |
| 66 | assert.strictEqual(eventType, 'change'); |
| 67 | assert.strictEqual(argFilename, testCase.fileName); |
| 68 | |
| 69 | watcher.close(); |
| 70 | |
| 71 | // We document that watchers cannot be used anymore when it's closed, |
| 72 | // here we turn the methods into noops instead of throwing |
| 73 | watcher.close(); // Closing a closed watcher should be a noop |
| 74 | })); |
| 75 | |
| 76 | // Long content so it's actually flushed. toUpperCase so there's real change. |
| 77 | const content2 = Date.now() + testCase.fileName.toUpperCase().repeat(1e4); |
| 78 | interval = setInterval(() => { |
| 79 | fs.writeFileSync(testCase.filePath, ''); |
| 80 | fs.writeFileSync(testCase.filePath, content2); |
| 81 | }, 100); |
| 82 | } |
| 83 | |
| 84 | for (const testCase of cases) { |
| 85 | if (testCase.shouldSkip) continue; |
no test coverage detected