| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,15 @@ const testDir = tmpdir.path; | |||
| 42 | 42 | ||
| 43 | 43 | tmpdir.refresh(); | |
| 44 | 44 | ||
| 45 | + // Because macOS (and possibly other operating systems) can return a watcher | ||
| 46 | + // before it is actually watching, we need to repeat the operation to avoid | ||
| 47 | + // a race condition. | ||
| 48 | + function repeat(fn) { | ||
| 49 | + setImmediate(fn); | ||
| 50 | + const interval = setInterval(fn, 5000); | ||
| 51 | + return interval; | ||
| 52 | + } | ||
| 53 | + | ||
| 45 | 54 | { | |
| 46 | 55 | const filepath = path.join(testDir, 'watch.txt'); | |
| 47 | 56 | ||
@@ -54,12 +63,11 @@ tmpdir.refresh(); | |||
| 54 | 63 | if (expectFilePath) { | |
| 55 | 64 | assert.strictEqual(filename, 'watch.txt'); | |
| 56 | 65 | } | |
| 66 | + clearInterval(interval); | ||
| 57 | 67 | watcher.close(); | |
| 58 | 68 | })); | |
| 59 | 69 | ||
| 60 | - setImmediate(function() { | ||
| 61 | - fs.writeFileSync(filepath, 'world'); | ||
| 62 | - }); | ||
| 70 | + const interval = repeat(() => { fs.writeFileSync(filepath, 'world'); }); | ||
| 63 | 71 | } | |
| 64 | 72 | ||
| 65 | 73 | { | |
@@ -76,12 +84,11 @@ tmpdir.refresh(); | |||
| 76 | 84 | if (expectFilePath) { | |
| 77 | 85 | assert.strictEqual(filename, 'hasOwnProperty'); | |
| 78 | 86 | } | |
| 87 | + clearInterval(interval); | ||
| 79 | 88 | watcher.close(); | |
| 80 | 89 | })); | |
| 81 | 90 | ||
| 82 | - setImmediate(function() { | ||
| 83 | - fs.writeFileSync(filepathAbs, 'pardner'); | ||
| 84 | - }); | ||
| 91 | + const interval = repeat(() => { fs.writeFileSync(filepathAbs, 'pardner'); }); | ||
| 85 | 92 | } | |
| 86 | 93 | ||
| 87 | 94 | { | |
@@ -97,14 +104,15 @@ tmpdir.refresh(); | |||
| 97 | 104 | } else { | |
| 98 | 105 | assert.strictEqual(filename, null); | |
| 99 | 106 | } | |
| 107 | + clearInterval(interval); | ||
| 100 | 108 | watcher.close(); | |
| 101 | 109 | })); | |
| 102 | 110 | ||
| 103 | - setImmediate(function() { | ||
| 111 | + const interval = repeat(() => { | ||
| 112 | + fs.rmSync(filepath, { force: true }); | ||
| 104 | 113 | const fd = fs.openSync(filepath, 'w'); | |
| 105 | 114 | fs.closeSync(fd); | |
| 106 | 115 | }); | |
| 107 | - | ||
| 108 | 116 | } | |
| 109 | 117 | ||
| 110 | 118 | // https://github.com/joyent/node/issues/2293 - non-persistent watcher should | |
| Back | FazBrowse Home | New Git URL |
0 commit comments