-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathcommons.test.ts
More file actions
30 lines (24 loc) · 939 Bytes
/
commons.test.ts
File metadata and controls
30 lines (24 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as exec from '@actions/exec';
import { describe, expect, it, vi } from 'vitest';
import * as commons from '../commons.js';
vi.mock(import('lodash/memoize.js'), () => ({
default: (x: any) => x
}) as any);
const mockedExecOutput = vi.spyOn(exec, 'getExecOutput');
describe(commons.checkDirForChanges, () => {
function mockChanges(value: boolean) {
mockedExecOutput.mockResolvedValueOnce({
exitCode: value ? 1 : 0, stdout: '', stderr: ''
});
}
it('should return true if git diff exits with non zero code', async () => {
mockChanges(true);
await expect(commons.checkDirForChanges('/')).resolves.toEqual(true);
expect(mockedExecOutput).toHaveBeenCalledOnce();
});
it('should return false if git diff exits with 0', async () => {
mockChanges(false);
await expect(commons.checkDirForChanges('/')).resolves.toEqual(false);
expect(mockedExecOutput).toHaveBeenCalledOnce();
});
});