Skip to content

Commit

Permalink
Make sure Mocha exits after tests finish/fail/timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Feb 8, 2021
1 parent 53a6f7c commit 668711a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"preinstall": "cd ../.. && npm i && npm run build",
"test": "mocha --expose-gc tests.js"
"test": "mocha --exit --expose-gc tests.js"
},
"dependencies": {
"@apollo/client": "file:../../dist",
Expand Down
8 changes: 7 additions & 1 deletion scripts/memory/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ const {
} = require("@apollo/client/core");

function itAsync(message, testFn) {
const start = Date.now();
let timeout;
(function pollGC() {
gc(); // enabled by --expose-gc
timeout = setTimeout(pollGC, 100);
// Passing --exit to mocha should cause the process to exit after
// tests pass/fail/timeout, but (in case that fails) we also set a
// hard limit of 10 seconds for GC polling.
if (Date.now() < start + 10000) {
timeout = setTimeout(pollGC, 100);
}
})();
return it(message, () => new Promise(testFn).finally(() => {
clearTimeout(timeout);
Expand Down

0 comments on commit 668711a

Please sign in to comment.