mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-05-06 22:18:06 +08:00
Be more lenient in accepting command inputs (#405)
* Be more lenient in accepting command inputs
This commit is contained in:
@@ -112,6 +112,21 @@ describe('@actions/core/src/command', () => {
|
||||
`::some-command prop1=value 1,prop2=value 2,prop3=value 3::${os.EOL}`
|
||||
])
|
||||
})
|
||||
|
||||
it('should handle issueing commands for non-string objects', () => {
|
||||
command.issueCommand(
|
||||
'some-command',
|
||||
{
|
||||
prop1: ({test: 'object'} as unknown) as string,
|
||||
prop2: (123 as unknown) as string,
|
||||
prop3: (true as unknown) as string
|
||||
},
|
||||
({test: 'object'} as unknown) as string
|
||||
)
|
||||
assertWriteCalls([
|
||||
`::some-command prop1={"test"%3A"object"},prop2=123,prop3=true::{"test":"object"}${os.EOL}`
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
// Assert that process.stdout.write calls called only with the given arguments.
|
||||
|
||||
@@ -54,6 +54,16 @@ describe('@actions/core', () => {
|
||||
assertWriteCalls([`::set-env name=my var2::var val%0D%0A${os.EOL}`])
|
||||
})
|
||||
|
||||
it('exportVariable handles boolean inputs', () => {
|
||||
core.exportVariable('my var', true)
|
||||
assertWriteCalls([`::set-env name=my var::true${os.EOL}`])
|
||||
})
|
||||
|
||||
it('exportVariable handles number inputs', () => {
|
||||
core.exportVariable('my var', 5)
|
||||
assertWriteCalls([`::set-env name=my var::5${os.EOL}`])
|
||||
})
|
||||
|
||||
it('setSecret produces the correct command', () => {
|
||||
core.setSecret('secret val')
|
||||
assertWriteCalls([`::add-mask::secret val${os.EOL}`])
|
||||
@@ -104,18 +114,35 @@ describe('@actions/core', () => {
|
||||
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`])
|
||||
})
|
||||
|
||||
it('setFailure sets the correct exit code and failure message', () => {
|
||||
it('setOutput handles bools', () => {
|
||||
core.setOutput('some output', false)
|
||||
assertWriteCalls([`::set-output name=some output::false${os.EOL}`])
|
||||
})
|
||||
|
||||
it('setOutput handles numbers', () => {
|
||||
core.setOutput('some output', 1.01)
|
||||
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`])
|
||||
})
|
||||
|
||||
it('setFailed sets the correct exit code and failure message', () => {
|
||||
core.setFailed('Failure message')
|
||||
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
||||
assertWriteCalls([`::error::Failure message${os.EOL}`])
|
||||
})
|
||||
|
||||
it('setFailure escapes the failure message', () => {
|
||||
it('setFailed escapes the failure message', () => {
|
||||
core.setFailed('Failure \r\n\nmessage\r')
|
||||
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
||||
assertWriteCalls([`::error::Failure %0D%0A%0Amessage%0D${os.EOL}`])
|
||||
})
|
||||
|
||||
it('setFailed handles Error', () => {
|
||||
const message = 'this is my error message'
|
||||
core.setFailed(new Error(message))
|
||||
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
||||
assertWriteCalls([`::error::Error: ${message}${os.EOL}`])
|
||||
})
|
||||
|
||||
it('error sets the correct error message', () => {
|
||||
core.error('Error message')
|
||||
assertWriteCalls([`::error::Error message${os.EOL}`])
|
||||
@@ -126,6 +153,12 @@ describe('@actions/core', () => {
|
||||
assertWriteCalls([`::error::Error message%0D%0A%0A${os.EOL}`])
|
||||
})
|
||||
|
||||
it('error handles an error object', () => {
|
||||
const message = 'this is my error message'
|
||||
core.error(new Error(message))
|
||||
assertWriteCalls([`::error::Error: ${message}${os.EOL}`])
|
||||
})
|
||||
|
||||
it('warning sets the correct message', () => {
|
||||
core.warning('Warning')
|
||||
assertWriteCalls([`::warning::Warning${os.EOL}`])
|
||||
@@ -136,6 +169,12 @@ describe('@actions/core', () => {
|
||||
assertWriteCalls([`::warning::%0D%0Awarning%0A${os.EOL}`])
|
||||
})
|
||||
|
||||
it('warning handles an error object', () => {
|
||||
const message = 'this is my error message'
|
||||
core.warning(new Error(message))
|
||||
assertWriteCalls([`::warning::Error: ${message}${os.EOL}`])
|
||||
})
|
||||
|
||||
it('startGroup starts a new group', () => {
|
||||
core.startGroup('my-group')
|
||||
assertWriteCalls([`::group::my-group${os.EOL}`])
|
||||
@@ -174,6 +213,16 @@ describe('@actions/core', () => {
|
||||
assertWriteCalls([`::save-state name=state_1::some value${os.EOL}`])
|
||||
})
|
||||
|
||||
it('saveState handles numbers', () => {
|
||||
core.saveState('state_1', 1)
|
||||
assertWriteCalls([`::save-state name=state_1::1${os.EOL}`])
|
||||
})
|
||||
|
||||
it('saveState handles bools', () => {
|
||||
core.saveState('state_1', true)
|
||||
assertWriteCalls([`::save-state name=state_1::true${os.EOL}`])
|
||||
})
|
||||
|
||||
it('getState gets wrapper action state', () => {
|
||||
expect(core.getState('TEST_1')).toBe('state_val')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user