Attempt to streamline dev lifecycle (git hooks) (#357)

* fix: misalignments in dev lifecycle

* fix: dist no longer added to staged

* fix: misalignments in dev lifecycle

* chore: multi-platform hooks and tests

* chore: multi-platform hooks and tests

* chore: add intention for colors

* chore: update lint-staged to fix color

* chore: update dist files

* feat: move to lefthook (remove husky and lint-staged)

* feat: move to lefthook (remove husky and lint-staged)

* fix: test aftereach

* fix: test aftereach

* fix: early restore call

* feat: jest fails if something gets logged to console

* chore: add todos of misplaced code

* chore: update dist files

* chore: move jest file
This commit is contained in:
Webber Takken
2022-03-28 01:23:32 +02:00
committed by GitHub
parent 9440c54d51
commit f1c154a23c
17 changed files with 4785 additions and 4873 deletions

View File

@@ -1,57 +1,46 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import System from './system';
jest.spyOn(core, 'debug').mockImplementation(() => {});
const info = jest.spyOn(core, 'info').mockImplementation(() => {});
jest.spyOn(core, 'warning').mockImplementation(() => {});
jest.spyOn(core, 'error').mockImplementation(() => {});
const execSpy = jest.spyOn(exec, 'exec').mockImplementation(async () => 0);
afterEach(() => {
jest.clearAllMocks();
});
afterEach(() => jest.clearAllMocks());
describe('System', () => {
describe('run', () => {
it('runs a command successfully', async () => {
await expect(System.run('true')).resolves.not.toBeNull();
});
describe('units', () => {
it('passes the command to command line', async () => {
await expect(System.run('echo test')).resolves.not.toBeNull();
await expect(execSpy).toHaveBeenLastCalledWith('echo test', expect.anything(), expect.anything());
});
it('outputs results', async () => {
await expect(System.run('echo test')).resolves.toStrictEqual('test\n');
});
it('throws on when error code is not 0', async () => {
execSpy.mockImplementationOnce(async () => 1);
await expect(System.run('false')).rejects.toThrowError();
});
it('throws on when error code is not 0', async () => {
await expect(System.run('false')).rejects.toThrowError();
});
it('throws when no command is given', async () => {
await expect(System.run('')).rejects.toThrowError();
});
it('throws when no arguments are given', async () => {
await expect(System.run('')).rejects.toThrowError();
});
it('throws when command consists only of spaces', async () => {
await expect(System.run(' \t\n')).rejects.toThrowError();
});
it('outputs info', async () => {
await expect(System.run('echo test')).resolves.not.toBeNull();
expect(info).toHaveBeenLastCalledWith('test\n');
});
it('outputs info', async () => {
execSpy.mockImplementationOnce(async (input, _, options) => {
options?.listeners?.stdout?.(Buffer.from(input, 'utf8'));
return 0;
});
it('outputs info only once', async () => {
await expect(System.run('echo 1')).resolves.not.toBeNull();
expect(info).toHaveBeenCalledTimes(1);
expect(info).toHaveBeenLastCalledWith('1\n');
info.mockClear();
await expect(System.run('echo 2')).resolves.not.toBeNull();
await expect(System.run('echo 3')).resolves.not.toBeNull();
expect(info).toHaveBeenCalledTimes(2);
expect(info).toHaveBeenLastCalledWith('3\n');
});
it('allows pipes using buffer', async () => {
await expect(
System.run('sh', undefined, {
input: Buffer.from('git tag --list --merged HEAD | grep v[0-9]* | wc -l'),
// eslint-disable-next-line github/no-then
}).then((result) => Number(result)),
).resolves.not.toBeNaN();
await expect(System.run('foo-bar')).resolves.not.toBeNull();
expect(info).toHaveBeenCalledTimes(1);
expect(info).toHaveBeenLastCalledWith('foo-bar');
});
});
});
});