Skip to content

Commit 9091b98

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

File tree

3 files changed

+90
-49
lines changed

3 files changed

+90
-49
lines changed

package-lock.json

Lines changed: 66 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
"devDependencies": {
149149
"@eslint/js": "^9.19.0",
150150
"@jridgewell/trace-mapping": "^0.3.25",
151-
"@types/chai": "^4.3.17",
151+
"@types/chai": "^4.3.20",
152152
"@types/eslint__js": "^8.42.3",
153153
"@types/estree": "^1.0.6",
154154
"@types/extract-zip": "^2.0.1",
@@ -170,7 +170,7 @@
170170
"acorn": "^8.14.0",
171171
"acorn-loose": "^8.4.0",
172172
"ansi-colors": "^4.1.3",
173-
"chai": "^5.1.2",
173+
"chai": "^4.5.0",
174174
"cross-env": "^7.0.3",
175175
"data-uri-to-buffer": "^6.0.2",
176176
"enhanced-resolve": "^5.18.0",

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)