Skip to content

Commit

Permalink
fix: Don't hang when git is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
dividedmind authored and dustinbyrne committed Feb 22, 2023
1 parent 517ca64 commit d2faa86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/telemetry/telemetry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import sinon, { SinonSpy } from 'sinon';
import Conf from 'conf';
import Telemetry, { Git } from './telemetry';
import Telemetry, { Git, GitState } from './telemetry';
import { name as appName, version } from './package.json';
import child_process, { ChildProcess } from 'node:child_process';
import { nextTick } from 'node:process';

const invalidExpiration = () => Date.now() - 1000 * 60 * 60;

Expand Down Expand Up @@ -178,5 +180,17 @@ describe('telemetry', () => {
expect(await Git.contributors(sinceDaysAgo)).toEqual(firstResult);
}
});

describe('state', () => {
it('returns NotInstalled on error', () => {
jest.spyOn(child_process, 'spawn').mockImplementation(() => {
const cp = new ChildProcess();
nextTick(() => cp.emit('error', new Error('test error')));
return cp;
});

return expect(Git.state()).resolves.toEqual(GitState.NotInstalled);
});
});
});
});
2 changes: 1 addition & 1 deletion packages/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class GitProperties {
return resolve(GitState.Ok);
}
});
commandProcess.on('error', () => GitState.NotInstalled);
commandProcess.on('error', () => resolve(GitState.NotInstalled));
} catch {
resolve(GitState.NotInstalled);
}
Expand Down

0 comments on commit d2faa86

Please sign in to comment.