import { mockgit } from './helpers.js'; import { gitRevParse } from '@percy/env/utils'; describe('gitRevParse', () => { it('passes the revision to git as a single argument', () => { let git = mockgit().and.returnValue('COMMIT_SHA:resolved-sha'); expect(gitRevParse('abc def')).toEqual('resolved-sha'); expect(git).toHaveBeenCalledWith('rev-parse', 'abc def'); }); it('does not pass empty or option-like revisions to git', () => { let git = mockgit(); expect(gitRevParse('')).toEqual(''); expect(gitRevParse(undefined)).toEqual(''); expect(gitRevParse('--abcdef')).toEqual(''); expect(git).not.toHaveBeenCalled(); }); it('returns an empty string when git checks are skipped', () => { let git = mockgit(); process.env.PERCY_SKIP_GIT_CHECK = 'true'; try { expect(gitRevParse('abcdef')).toEqual(''); expect(git).not.toHaveBeenCalled(); } finally { delete process.env.PERCY_SKIP_GIT_CHECK; } }); });