Skip to content

Commit e20761f

Browse files
committed
improved watch-mode test
this should avoid CI test failures due to what seems like a race condition on slow CPUs - though it also speed up tests in general by avoiding unnecessary delays in the process, updated dependencies and fixed linting
1 parent 3a5960e commit e20761f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test": "npm-run-all lint --parallel test:unit test:cli",
2121
"test:cli": "./test/cli/run",
2222
"test:unit": "mocha test/unit/test_*.js",
23-
"lint": "eslint --cache --ext .js --ext .jsx *.js bin samples && echo ✓"
23+
"lint": "eslint --cache --ext .js --ext .jsx *.js bin/* samples && echo ✓"
2424
},
2525
"engines": {
2626
"node": ">=6"
@@ -33,7 +33,7 @@
3333
"rollup-plugin-node-resolve": "^3.0.3"
3434
},
3535
"devDependencies": {
36-
"eslint-config-fnd-jsx": "^1.1.0",
36+
"eslint-config-fnd-jsx": "^1.3.0",
3737
"faucet-pipeline-esnext": "file:pkg/faucet-pipeline-esnext",
3838
"faucet-pipeline-jsx": "file:pkg/faucet-pipeline-jsx",
3939
"faucet-pipeline-typescript": "file:pkg/faucet-pipeline-typescript",

test/unit/test_watch.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("watcher", () => {
1818
watcher.terminate();
1919
});
2020

21-
it("responds to file changes in watch mode", done => {
21+
it("responds to file changes in watch mode", function(done) {
2222
let config = [{
2323
source: entryPoint.relative,
2424
target: "./dist/bundle.js"
@@ -55,11 +55,21 @@ console.log(\`[…] $\{util}\`); // eslint-disable-line no-console
5555
setTimeout(_ => {
5656
fs.writeFileSync(entryPoint.absolute, src + 'console.log("…");');
5757
}, 50);
58-
// check result
59-
setTimeout(_ => { // FIXME: hacky
60-
assetManager.assertWrites(expectedBundles);
58+
// check result by polling
59+
let timer = 0;
60+
let interval = 50;
61+
let threshold = this.timeout() - 2 * interval;
62+
let check = _ => {
63+
timer += interval;
64+
if(timer > threshold ||
65+
assetManager._writes.length === expectedBundles.length) {
66+
assetManager.assertWrites(expectedBundles);
67+
conclude();
68+
return;
69+
}
6170

62-
conclude();
63-
}, 500);
71+
setTimeout(check, interval); // retry
72+
};
73+
setTimeout(check, interval);
6474
});
6575
});

0 commit comments

Comments
 (0)