Skip to content

Commit 37db9b6

Browse files
committed
test: improve flaky macos test on file changes
1 parent 82f478c commit 37db9b6

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/test/integration/package-json.test.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,30 @@ describe('package-json', () => {
7575
['hello.test.js', [['math', [['addition'], ['failing'], ['subtraction']]]]],
7676
]);
7777

78-
const onChange = onceScanComplete(c);
78+
// especially on MacOS we often get a wrong / early file change detected causing a scan
79+
// that's why we retry multiple times here.
80+
for (let retry = 0; retry < 3; retry++) {
81+
const configPath = path.join(workspaceFolder, 'package.json');
82+
const original = await fs.readFile(configPath, 'utf-8');
83+
let updated = original.replace('**/*.test.js', '*.test.js');
7984

80-
const configPath = path.join(workspaceFolder, 'package.json');
81-
const original = await fs.readFile(configPath, 'utf-8');
82-
let updated = original.replace('**/*.test.js', '*.test.js');
85+
// the vscode file watcher is set up async and does not always catch the change, keep changing the file
86+
let ok: boolean | void = false;
87+
while (!ok) {
88+
updated += '\n';
89+
const onChange = onceScanComplete(c);
90+
await fs.writeFile(configPath, updated);
91+
ok = await Promise.race([onChange.then(() => true), setTimeout(1000)]);
92+
}
8393

84-
// the vscode file watcher is set up async and does not always catch the change, keep changing the file
85-
let ok: boolean | void = false;
86-
while (!ok) {
87-
updated += '\n';
88-
await fs.writeFile(configPath, updated);
89-
ok = await Promise.race([onChange.then(() => true), setTimeout(1000)]);
94+
try {
95+
expectTestTree(c, [
96+
['hello.test.js', [['math', [['addition'], ['failing'], ['subtraction']]]]],
97+
]);
98+
return;
99+
} catch (e) {
100+
// ignore
101+
}
90102
}
91103

92104
expectTestTree(c, [

0 commit comments

Comments
 (0)