UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

70 lines 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const git_1 = require("../../src/utils/git"); const { mockedExecSync } = vitest_1.vi.hoisted(() => { return { mockedExecSync: vitest_1.vi.fn() }; }); vitest_1.vi.mock('child_process', async () => { return { default: {}, ...(await vitest_1.vi.importActual('child_process')), execSync: mockedExecSync, }; }); (0, vitest_1.beforeEach)(() => { vitest_1.vi.clearAllMocks(); }); (0, vitest_1.describe)('isInGitRepo', () => { (0, vitest_1.it)('returns true if the git command process exits with 0', () => { mockedExecSync.mockImplementationOnce(() => { return 'true'; }); (0, vitest_1.expect)((0, git_1.isInGitRepo)({ cwd: undefined })).toBe(true); }); (0, vitest_1.it)('returns false if the git command process exits with non-zero', () => { mockedExecSync.mockImplementationOnce(() => { throw new Error('Command failed'); }); (0, vitest_1.expect)((0, git_1.isInGitRepo)({ cwd: undefined })).toBe(false); }); (0, vitest_1.it)('forwards cwd if provided', () => { mockedExecSync.mockImplementationOnce(() => { return 'true'; }); (0, git_1.isInGitRepo)({ cwd: '/path/to/dir' }); (0, vitest_1.expect)(mockedExecSync).toHaveBeenCalledWith('git rev-parse --is-inside-work-tree', { stdio: 'ignore', cwd: '/path/to/dir', }); }); }); (0, vitest_1.describe)('getUncommittedOrUntrackedFiles', () => { (0, vitest_1.it)('returns a list of uncommitted or untracked files', () => { mockedExecSync.mockImplementationOnce(() => { return (' M file1.txt\n' + '?? file2.txt\n' + '?? file3.txt\n' + '?? file4.txt\n'); }); (0, vitest_1.expect)((0, git_1.getUncommittedOrUntrackedFiles)()).toEqual([ '- file1.txt', '- file2.txt', '- file3.txt', '- file4.txt', ]); }); (0, vitest_1.it)('returns an empty list if there are no uncommitted or untracked files', () => { mockedExecSync.mockImplementationOnce(() => { return ''; }); (0, vitest_1.expect)((0, git_1.getUncommittedOrUntrackedFiles)()).toEqual([]); }); (0, vitest_1.it)('returns an empty list if the git command fails', () => { mockedExecSync.mockImplementationOnce(() => { throw new Error('Command failed'); }); (0, vitest_1.expect)((0, git_1.getUncommittedOrUntrackedFiles)()).toEqual([]); }); }); //# sourceMappingURL=git.test.js.map