Closed campersau closed 4 years ago
Nice finding. Maybe we can add a test for it? Just checking that clearTimeout is called wdyt?
I could add a test like this but hacking global variables for that feels a bit dirty and may have sideeffets when other code also uses it.
const expect = require('expect.js');
const git = require('../source/git-promise');
describe('git-promise', () => {
it('should clear git timeout when successful', async () => {
let clearTimeoutCallCount = 0;
const originalClearTimeout = clearTimeout;
clearTimeout = (arg) => {
clearTimeoutCallCount++;
originalClearTimeout(arg);
}
try {
await git(['version']);
expect(clearTimeoutCallCount).to.equal(1);
} finally {
clearTimeout = originalClearTimeout;
}
});
});
While trying to migrate from grunt to script files, I noticed that the mocha unittest weren't existing right away. I tracked the problem down with
wtfnode
to our git-promise timeout (introduced in https://github.com/FredrikNoren/ungit/pull/1192) which wasn't cancelled if the git call was successful and didn't timed out.