Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit a879d2c

Browse files
test: limit how long we wait for a file watcher
1 parent d9fdfde commit a879d2c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

spec/helpers.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ export async function copyFileToTempDir(fileToCopyPath, newFileName = null) {
3737
export async function openAndSetProjectDir (fileName, projectDir) {
3838
let editor = await atom.workspace.open(fileName);
3939
atom.project.setPaths([projectDir]);
40-
await atom.project.watcherPromisesByPath[projectDir];
41-
await wait(200);
40+
await race(
41+
atom.project.watcherPromisesByPath[projectDir],
42+
wait(1000)
43+
);
4244
return editor;
4345
}
4446

@@ -53,3 +55,19 @@ export function wait (ms) {
5355
export function setTimeout (...args) {
5456
return _setTimeout(...args);
5557
}
58+
59+
export function race (...promises) {
60+
let count = promises.length;
61+
let rejectedCount = 0;
62+
return new Promise((resolve, reject) => {
63+
for (let promise of promises) {
64+
// Resolve whenever the first one resolves.
65+
promise.then(resolve);
66+
// Reject if they all reject.
67+
promise.catch(() => {
68+
rejectedCount++;
69+
if (rejectedCount === count) { reject(); }
70+
});
71+
}
72+
});
73+
}

0 commit comments

Comments
 (0)