Add tests for System model
This commit is contained in:
@@ -19,7 +19,7 @@ class System {
|
||||
},
|
||||
};
|
||||
|
||||
const exitCode = await exec(command, arguments_, { ...options, listeners });
|
||||
const exitCode = await exec(command, arguments_, { silent: true, listeners, ...options });
|
||||
|
||||
if (debug !== '') {
|
||||
core.debug(debug);
|
||||
|
||||
45
src/model/system.test.js
Normal file
45
src/model/system.test.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import * as core from '@actions/core';
|
||||
import System from './system';
|
||||
|
||||
const info = jest.spyOn(core, 'info').mockImplementation(() => {});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('System', () => {
|
||||
describe('run', () => {
|
||||
it('runs a command successfully', async () => {
|
||||
await expect(System.run('true')).resolves.not.toBeNull();
|
||||
});
|
||||
|
||||
it('outputs results', async () => {
|
||||
await expect(System.run('echo test')).resolves.toStrictEqual('test\n');
|
||||
});
|
||||
|
||||
it('throws on when error code is not 0', async () => {
|
||||
await expect(System.run('false')).rejects.toThrowError();
|
||||
});
|
||||
|
||||
it('throws when no arguments are given', async () => {
|
||||
await expect(System.run()).rejects.toThrowError();
|
||||
});
|
||||
|
||||
it('outputs info', async () => {
|
||||
await expect(System.run('echo test')).resolves.not.toBeNull();
|
||||
expect(info).toHaveBeenLastCalledWith('test\n');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user