-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove trailing comma from commands (#263)
- Loading branch information
1 parent
f798972
commit 568f12c
Showing
3 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as command from '../src/command' | ||
import * as os from 'os' | ||
|
||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
|
||
let originalWriteFunction: (str: string) => boolean | ||
|
||
describe('@actions/core/src/command', () => { | ||
beforeAll(() => { | ||
originalWriteFunction = process.stdout.write | ||
}) | ||
|
||
beforeEach(() => { | ||
process.stdout.write = jest.fn() | ||
}) | ||
|
||
afterEach(() => {}) | ||
|
||
afterAll(() => { | ||
process.stdout.write = (originalWriteFunction as unknown) as ( | ||
str: string | ||
) => boolean | ||
}) | ||
|
||
it('command only', () => { | ||
command.issueCommand('some-command', {}, '') | ||
assertWriteCalls([`::some-command::${os.EOL}`]) | ||
}) | ||
|
||
it('command with message', () => { | ||
command.issueCommand('some-command', {}, 'some message') | ||
assertWriteCalls([`::some-command::some message${os.EOL}`]) | ||
}) | ||
|
||
it('command with message and properties', () => { | ||
command.issueCommand( | ||
'some-command', | ||
{prop1: 'value 1', prop2: 'value 2'}, | ||
'some message' | ||
) | ||
assertWriteCalls([ | ||
`::some-command prop1=value 1,prop2=value 2::some message${os.EOL}` | ||
]) | ||
}) | ||
|
||
it('command with one property', () => { | ||
command.issueCommand('some-command', {prop1: 'value 1'}, '') | ||
assertWriteCalls([`::some-command prop1=value 1::${os.EOL}`]) | ||
}) | ||
|
||
it('command with two properties', () => { | ||
command.issueCommand( | ||
'some-command', | ||
{prop1: 'value 1', prop2: 'value 2'}, | ||
'' | ||
) | ||
assertWriteCalls([`::some-command prop1=value 1,prop2=value 2::${os.EOL}`]) | ||
}) | ||
|
||
it('command with three properties', () => { | ||
command.issueCommand( | ||
'some-command', | ||
{prop1: 'value 1', prop2: 'value 2', prop3: 'value 3'}, | ||
'' | ||
) | ||
assertWriteCalls([ | ||
`::some-command prop1=value 1,prop2=value 2,prop3=value 3::${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]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters