2022-03-15 02:56:21 -04:00
|
|
|
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
|
2021-05-09 05:15:20 -04:00
|
|
|
import * as os from 'os';
|
|
|
|
import * as context from '../src/context';
|
|
|
|
|
|
|
|
describe('setOutput', () => {
|
|
|
|
beforeEach(() => {
|
2022-03-15 02:56:21 -04:00
|
|
|
process.stdout.write = jest.fn() as typeof process.stdout.write;
|
2021-05-09 05:15:20 -04:00
|
|
|
});
|
|
|
|
|
2022-03-15 02:56:21 -04:00
|
|
|
// eslint-disable-next-line jest/expect-expect
|
2021-05-09 05:15:20 -04:00
|
|
|
it('setOutput produces the correct command', () => {
|
|
|
|
context.setOutput('some output', 'some value');
|
|
|
|
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
|
|
|
|
});
|
|
|
|
|
2022-03-15 02:56:21 -04:00
|
|
|
// eslint-disable-next-line jest/expect-expect
|
2021-05-09 05:15:20 -04:00
|
|
|
it('setOutput handles bools', () => {
|
|
|
|
context.setOutput('some output', false);
|
|
|
|
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
|
|
|
|
});
|
|
|
|
|
2022-03-15 02:56:21 -04:00
|
|
|
// eslint-disable-next-line jest/expect-expect
|
2021-05-09 05:15:20 -04:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|