mirror of
https://github.com/crazy-max/ghaction-import-gpg.git
synced 2024-12-01 09:21:03 -05:00
33 lines
1,016 B
TypeScript
33 lines
1,016 B
TypeScript
|
import * as os from 'os';
|
||
|
|
||
|
import * as context from '../src/context';
|
||
|
|
||
|
describe('setOutput', () => {
|
||
|
beforeEach(() => {
|
||
|
process.stdout.write = jest.fn();
|
||
|
});
|
||
|
|
||
|
it('setOutput produces the correct command', () => {
|
||
|
context.setOutput('some output', 'some value');
|
||
|
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
|
||
|
});
|
||
|
|
||
|
it('setOutput handles bools', () => {
|
||
|
context.setOutput('some output', false);
|
||
|
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
|
||
|
});
|
||
|
|
||
|
it('setOutput handles numbers', () => {
|
||
|
context.setOutput('some output', 1.01);
|
||
|
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
// Assert that process.stdout.write calls called only with the given arguments.
|
||
|
function assertWriteCalls(calls: string[]): void {
|
||
|
expect(process.stdout.write).toHaveBeenCalledTimes(calls.length);
|
||
|
for (let i = 0; i < calls.length; i++) {
|
||
|
expect(process.stdout.write).toHaveBeenNthCalledWith(i + 1, calls[i]);
|
||
|
}
|
||
|
}
|