mirror of https://github.com/actions/toolkit
parent
05e39f551d
commit
c4b6011310
|
@ -286,6 +286,52 @@ describe('@actions/exec', () => {
|
|||
expect(stderrCalled).toBeTruthy()
|
||||
})
|
||||
|
||||
it('Handles stdin shell', async () => {
|
||||
let command: string
|
||||
if (IS_WINDOWS) {
|
||||
command = 'wait-for-input.cmd'
|
||||
} else {
|
||||
command = 'wait-for-input.sh'
|
||||
}
|
||||
|
||||
const waitForInput: string = path.join(__dirname, 'scripts', command)
|
||||
|
||||
const _testExecOptions = getExecOptions()
|
||||
|
||||
_testExecOptions.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
expect(data).toEqual(Buffer.from(`this is my input${os.EOL}`))
|
||||
}
|
||||
}
|
||||
|
||||
_testExecOptions.input = Buffer.from('this is my input')
|
||||
|
||||
const exitCode = await exec.exec(`"${waitForInput}"`, [], _testExecOptions)
|
||||
expect(exitCode).toBe(0)
|
||||
})
|
||||
|
||||
it('Handles stdin js', async () => {
|
||||
const waitForInput: string = path.join(
|
||||
__dirname,
|
||||
'scripts',
|
||||
'wait-for-input.js'
|
||||
)
|
||||
|
||||
const _testExecOptions = getExecOptions()
|
||||
|
||||
_testExecOptions.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
expect(data).toEqual(Buffer.from(`this is my input`))
|
||||
}
|
||||
}
|
||||
|
||||
_testExecOptions.input = Buffer.from('this is my input')
|
||||
|
||||
const nodePath = await io.which('node', true)
|
||||
const exitCode = await exec.exec(nodePath, [waitForInput], _testExecOptions)
|
||||
expect(exitCode).toBe(0)
|
||||
})
|
||||
|
||||
it('Handles child process holding streams open', async function() {
|
||||
const semaphorePath = path.join(
|
||||
getTestTemp(),
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
@echo off
|
||||
set /p var=
|
||||
echo %var%
|
|
@ -0,0 +1,3 @@
|
|||
var fs = require('fs')
|
||||
var data = fs.readFileSync(0, 'utf-8')
|
||||
process.stdout.write(data)
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
read var
|
||||
echo $var
|
|
@ -30,6 +30,9 @@ export interface ExecOptions {
|
|||
/** optional. How long in ms to wait for STDIO streams to close after the exit event of the process before terminating. defaults to 10000 */
|
||||
delay?: number
|
||||
|
||||
/** optional. input to write to the process on STDIN. */
|
||||
input?: Buffer
|
||||
|
||||
/** optional. Listeners for output. Callback functions that will be called on these events */
|
||||
listeners?: {
|
||||
stdout?: (data: Buffer) => void
|
||||
|
|
|
@ -524,6 +524,14 @@ export class ToolRunner extends events.EventEmitter {
|
|||
resolve(exitCode)
|
||||
}
|
||||
})
|
||||
|
||||
if (this.options.input) {
|
||||
if (!cp.stdin) {
|
||||
throw new Error('child process missing stdin')
|
||||
}
|
||||
|
||||
cp.stdin.end(this.options.input)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue