1
0
Fork 0

Dont stamp over stdout (#29)

pull/31/head
Danny McCormick 2019-07-11 15:02:45 -04:00 committed by GitHub
parent c4a488fc74
commit d293c20cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 16 deletions

View File

@ -12,14 +12,19 @@ import * as io from '@actions/io'
const IS_WINDOWS = process.platform === 'win32' const IS_WINDOWS = process.platform === 'win32'
let outstream: stream.Writable
let errstream: stream.Writable
describe('@actions/exec', () => { describe('@actions/exec', () => {
beforeAll(() => { beforeAll(() => {
io.mkdirP(getTestTemp()) io.mkdirP(getTestTemp())
outstream = fs.createWriteStream(path.join(getTestTemp(), 'my.log'))
errstream = fs.createWriteStream(path.join(getTestTemp(), 'myerr.log'))
}) })
beforeEach(() => { beforeEach(() => {
process.stdout.write = jest.fn() outstream.write = jest.fn()
process.stderr.write = jest.fn() errstream.write = jest.fn()
}) })
it('Runs exec successfully with arguments split out', async () => { it('Runs exec successfully with arguments split out', async () => {
@ -45,12 +50,12 @@ describe('@actions/exec', () => {
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(process.stdout.write).toBeCalledWith( expect(outstream.write).toBeCalledWith(
`[command]${toolpath} /c echo hello${os.EOL}` `[command]${toolpath} /c echo hello${os.EOL}`
) )
expect(process.stdout.write).toBeCalledWith(new Buffer(`hello${os.EOL}`)) expect(outstream.write).toBeCalledWith(new Buffer(`hello${os.EOL}`))
} else { } else {
expect(process.stdout.write).toBeCalledWith( expect(outstream.write).toBeCalledWith(
`[command]${toolpath} -l -a${os.EOL}` `[command]${toolpath} -l -a${os.EOL}`
) )
} }
@ -75,12 +80,12 @@ describe('@actions/exec', () => {
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(process.stdout.write).toBeCalledWith( expect(outstream.write).toBeCalledWith(
`[command]${toolpath} /c echo hello${os.EOL}` `[command]${toolpath} /c echo hello${os.EOL}`
) )
expect(process.stdout.write).toBeCalledWith(new Buffer(`hello${os.EOL}`)) expect(outstream.write).toBeCalledWith(new Buffer(`hello${os.EOL}`))
} else { } else {
expect(process.stdout.write).toBeCalledWith( expect(outstream.write).toBeCalledWith(
`[command]${toolpath} -l -a${os.EOL}` `[command]${toolpath} -l -a${os.EOL}`
) )
} }
@ -105,12 +110,12 @@ describe('@actions/exec', () => {
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(process.stdout.write).toBeCalledWith( expect(outstream.write).toBeCalledWith(
`[command]${toolpath} /c echo hello${os.EOL}` `[command]${toolpath} /c echo hello${os.EOL}`
) )
expect(process.stdout.write).toBeCalledWith(new Buffer(`hello${os.EOL}`)) expect(outstream.write).toBeCalledWith(new Buffer(`hello${os.EOL}`))
} else { } else {
expect(process.stdout.write).toBeCalledWith( expect(outstream.write).toBeCalledWith(
`[command]${toolpath} -l -a${os.EOL}` `[command]${toolpath} -l -a${os.EOL}`
) )
} }
@ -140,11 +145,11 @@ describe('@actions/exec', () => {
expect(failed).toBe(true) expect(failed).toBe(true)
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(process.stdout.write).toBeCalledWith( expect(outstream.write).toBeCalledWith(
`[command]${toolpath} /c non-existent${os.EOL}` `[command]${toolpath} /c non-existent${os.EOL}`
) )
} else { } else {
expect(process.stdout.write).toBeCalledWith( expect(outstream.write).toBeCalledWith(
`[command]${toolpath} -l non-existent${os.EOL}` `[command]${toolpath} -l non-existent${os.EOL}`
) )
} }
@ -167,7 +172,7 @@ describe('@actions/exec', () => {
) )
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
expect(process.stdout.write).toBeCalledWith( expect(outstream.write).toBeCalledWith(
new Buffer('this is output to stderr') new Buffer('this is output to stderr')
) )
}) })
@ -191,7 +196,7 @@ describe('@actions/exec', () => {
}) })
expect(failed).toBe(true) expect(failed).toBe(true)
expect(process.stderr.write).toBeCalledWith( expect(errstream.write).toBeCalledWith(
new Buffer('this is output to stderr') new Buffer('this is output to stderr')
) )
}) })
@ -677,7 +682,9 @@ function getExecOptions(): im.ExecOptions {
env: {}, env: {},
silent: false, silent: false,
failOnStdErr: false, failOnStdErr: false,
ignoreReturnCode: false ignoreReturnCode: false,
outStream: outstream,
errStream: errstream
} }
} }