FredrikNoren / ungit

The easiest way to use git. On any platform. Anywhere.
MIT License
10.45k stars 640 forks source link

Clear git-promise timeout when git command was successful #1357

Closed campersau closed 4 years ago

campersau commented 4 years ago

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.

ylecuyer commented 4 years ago

Nice finding. Maybe we can add a test for it? Just checking that clearTimeout is called wdyt?

campersau commented 4 years ago

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;
        }
    });
});