mirror of https://github.com/actions/toolkit
Add tests
parent
780a5985b4
commit
a526749ce9
|
@ -1,49 +1,93 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import * as core from '../src/lib'
|
import * as core from '../src/core';
|
||||||
|
import * as os from 'os';
|
||||||
|
|
||||||
describe('@actions/core', () => {
|
describe('@actions/core', () => {
|
||||||
it('tests exportVariable', () => {
|
beforeAll(() => {
|
||||||
// TODO
|
// Set inputs
|
||||||
|
process.env['INPUT_MY_INPUT'] = 'val';
|
||||||
|
process.env['INPUT_MISSING'] = '';
|
||||||
|
process.env['INPUT_SPECIAL_CHARS_\'\t\"\\'] = '\'\t\"\\ repsonse ';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tests getInput', () => {
|
it('getInput gets non-required input', () => {
|
||||||
// TODO
|
expect(core.getInput('my input')).toBe('val');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tests setFailure', () => {
|
it('getInput gets required input', () => {
|
||||||
// TODO
|
expect(core.getInput('my input', {required: true})).toBe('val');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tests error', () => {
|
it('getInput throws on missing required input', () => {
|
||||||
// TODO
|
expect(() => core.getInput('missing', {required: true})).toThrow('Failed to find input missing');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tests warning', () => {
|
it('getInput doesnt throw on missing non-required input', () => {
|
||||||
// TODO
|
expect(core.getInput('missing', {required: false})).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tests debug', () => {
|
it('getInput is case insensitive', () => {
|
||||||
// TODO
|
expect(core.getInput('My InPuT')).toBe('val');
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getInput handles special characters', () => {
|
||||||
|
expect(core.getInput('special chars_\'\t\"\\')).toBe('\'\t\"\\ repsonse');
|
||||||
|
});
|
||||||
|
|
||||||
// it('exits successfully', () => {
|
it('setNeutral sets the correct exit code', () => {
|
||||||
// jest.spyOn(process, 'exit').mockImplementation()
|
core.setFailed('Failure message');
|
||||||
// core.fail('testing fail');
|
expect(process.exitCode).toBe(1);
|
||||||
// exit.success()
|
});
|
||||||
// expect(process.exit).toHaveBeenCalledWith(0)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('exits as a failure', () => {
|
it('setFailure sets the correct exit code and failure message', () => {
|
||||||
// jest.spyOn(process, 'exit').mockImplementation()
|
// Override stdout and append to output so that we capture the command that is sent
|
||||||
// exit.failure()
|
let output = '';
|
||||||
// expect(process.exit).toHaveBeenCalledWith(1)
|
process.stdout.write = (p1: string | Buffer | Uint8Array, p2?: string | ((err?: Error) => void), p3?: (err?: Error) => void): boolean => {
|
||||||
// })
|
output += p1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// it('exits neutrally', () => {
|
core.setFailed('Failure message');
|
||||||
// jest.spyOn(process, 'exit').mockImplementation()
|
expect(process.exitCode).toBe(1);
|
||||||
// exit.neutral()
|
expect(output).toBe('##[error]Failure message' + os.EOL);
|
||||||
// expect(process.exit).toHaveBeenCalledWith(78)
|
});
|
||||||
// })
|
|
||||||
|
it('error sets the correct error message', () => {
|
||||||
|
// Override stdout and append to output so that we capture the command that is sent
|
||||||
|
let output = '';
|
||||||
|
process.stdout.write = (p1: string | Buffer | Uint8Array, p2?: string | ((err?: Error) => void), p3?: (err?: Error) => void): boolean => {
|
||||||
|
output += p1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.error('Error message');
|
||||||
|
expect(output).toBe('##[error]Error message' + os.EOL);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('warning sets the correct message', () => {
|
||||||
|
// Override stdout and append to output so that we capture the command that is sent
|
||||||
|
let output = '';
|
||||||
|
process.stdout.write = (p1: string | Buffer | Uint8Array, p2?: string | ((err?: Error) => void), p3?: (err?: Error) => void): boolean => {
|
||||||
|
output += p1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.warning('Warning');
|
||||||
|
expect(output).toBe('##[warning]Warning' + os.EOL);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('debug sets the correct message', () => {
|
||||||
|
// Override stdout and append to output so that we capture the command that is sent
|
||||||
|
let output = '';
|
||||||
|
process.stdout.write = (p1: string | Buffer | Uint8Array, p2?: string | ((err?: Error) => void), p3?: (err?: Error) => void): boolean => {
|
||||||
|
output += p1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug('Debug');
|
||||||
|
expect(output).toBe('##[debug]Debug' + os.EOL);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO - test escaping for all commands
|
||||||
|
});
|
Loading…
Reference in New Issue