Skip to content

Commit

Permalink
feat: pass options to execa, close #27
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Apr 20, 2018
1 parent 8220e1d commit 09cbca8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# execa-wrap

> Wraps execa and makes output suitable for snapshot testing
> Wraps [execa][execa] and makes output suitable for snapshot testing
[![NPM][npm-icon] ][npm-url]

Expand Down Expand Up @@ -70,6 +70,17 @@ execaWrap('failing-command', ['its', 'arguments'])
})
```

You can pass other options to [execa][execa], for example environment variables

```js
const execaWrap = require('execa-wrap')
execaWrap('failing-command', ['its', 'arguments'], {
env: {
FOO: 'foo'
}
})
```

### Filtering properties

If you are not interested in every returned property, you can filter and get only some
Expand Down Expand Up @@ -141,3 +152,4 @@ OTHER DEALINGS IN THE SOFTWARE.
[standard-url]: http://standardjs.com/
[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg
[renovate-app]: https://renovateapp.com/
[execa]: https://github.com/sindresorhus/execa
20 changes: 20 additions & 0 deletions __snapshots__/execa-wrap-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,23 @@ exports['single field filter 1'] = `
-------
`

exports['passed FOO environment variable 1'] = `
command: node -e console.log(process.env.FOO)
code: 0
failed: false
killed: false
signal: null
timedOut: false
stdout:
-------
foo
-------
stderr:
-------
-------
`
8 changes: 8 additions & 0 deletions src/execa-wrap-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ if (os.platform() !== 'win32') {
snapshot.bind(null, 'single field filter')
)
})

it('can filter several fields', () => {
return execaWrap('ls', ['src'], { filter: ['cmd', 'stdout'] }).then(
snapshot.bind(null, 'fields filter')
)
})

it('can pass environment variables', () =>
execaWrap('node', ['-e', 'console.log(process.env.FOO)'], {
env: {
FOO: 'foo'
}
}).then(snapshot.bind(null, 'passed FOO environment variable')))
})
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const makeText = (options = {}) => execResult => {
}

function execWrapper (cmd, args, options = {}) {
const child = execa(cmd, args)
const child = execa(cmd, args, options)
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
return child.then(stripFields, stripFields).then(makeText(options))
Expand Down

0 comments on commit 09cbca8

Please sign in to comment.