-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ian Walter
committed
Jan 27, 2019
1 parent
30a58b8
commit 2632a50
Showing
8 changed files
with
4,829 additions
and
0 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,2 @@ | ||
node_modules | ||
dist |
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,16 @@ | ||
import execa from 'execa' | ||
|
||
export default function execaHelper (cli, throwOnStdErr = true) { | ||
return async function withCli (t, run) { | ||
await run(t, async (...params) => { | ||
const result = await execa(cli, params) | ||
|
||
// Throw an error if stderr has content so that the test fails. | ||
if (throwOnStdErr && result.stderr) { | ||
throw new Error(result.stderr) | ||
} | ||
|
||
return result | ||
}) | ||
} | ||
} |
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,34 @@ | ||
{ | ||
"name": "@ianwalter/execa-helper", | ||
"description": "An AVA helper that makes it easier to test CLIs using Execa", | ||
"module": "dist/execa-helper.m.js", | ||
"main": "dist/execa-helper.js", | ||
"scripts": { | ||
"lint": "eslint index.js test.js", | ||
"pretest": "dist", | ||
"test": "ava" | ||
}, | ||
"dependencies": { | ||
"execa": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@ianwalter/dist": "^1.4.0", | ||
"ava": "^1.1.0", | ||
"eslint": "^5.12.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-html": "^5.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^8.0.1", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"meow": "^5.0.0", | ||
"np": "^4.0.2" | ||
}, | ||
"eslintConfig": { | ||
"root": true, | ||
"extends": [ | ||
"eslint:recommended", | ||
"standard" | ||
] | ||
} | ||
} |
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,30 @@ | ||
#!/usr/bin/env node | ||
|
||
const meow = require('meow') | ||
|
||
const cli = meow( | ||
` | ||
Usage | ||
$ cli <options> | ||
Options | ||
--from, -f Author of the greeting | ||
--greeting, -g Output a greeting | ||
Examples | ||
$ cli --from Ian --greeting Hello World! | ||
[Ian]: Hello World! | ||
`, | ||
{ | ||
flags: { | ||
from: { type: 'string', alias: 'f' }, | ||
greeting: { type: 'string', alias: 'g' } | ||
} | ||
} | ||
) | ||
|
||
if (!cli.flags.from) { | ||
console.error('No author specified!') | ||
} | ||
|
||
console.log(`[${cli.flags.from}]: ${cli.flags.greeting}`) |
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,21 @@ | ||
# Snapshot report for `test/test.js` | ||
|
||
The actual snapshot is saved in `test.js.snap`. | ||
|
||
Generated by [AVA](https://ava.li). | ||
|
||
## doesn't throw error when configured | ||
|
||
> Snapshot 1 | ||
'[undefined]: Hello World!' | ||
|
||
> Snapshot 2 | ||
'No author specified!' | ||
|
||
## returns stdout when stderr has no content | ||
|
||
> Snapshot 1 | ||
'[Ian]: Hello World!' |
Binary file not shown.
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,20 @@ | ||
import test from 'ava' | ||
import execaHelper from '..' | ||
|
||
const withCli = execaHelper('./test/cli') | ||
const withNoThrowCli = execaHelper('./test/cli', false) | ||
|
||
test('throws error when stderr has content', withCli, async (t, cli) => { | ||
await t.throwsAsync(async () => cli('--greeting', 'Hello World!')) | ||
}) | ||
|
||
test('returns stdout when stderr has no content', withCli, async (t, cli) => { | ||
const { stdout } = await cli('--from', 'Ian', '--greeting', 'Hello World!') | ||
t.snapshot(stdout) | ||
}) | ||
|
||
test(`doesn't throw error when configured`, withNoThrowCli, async (t, cli) => { | ||
const { stdout, stderr } = await cli('--greeting', 'Hello World!') | ||
t.snapshot(stdout) | ||
t.snapshot(stderr) | ||
}) |
Oops, something went wrong.