From 72fb3e491c4bda83ea3a1622081ae2ad47246691 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Thu, 8 Nov 2018 16:31:20 +0100 Subject: [PATCH] feat(prompt-cli): add test #51 --- @commitlint/prompt-cli/cli.test.js | 25 +++++++++++++++++++++++++ @commitlint/prompt-cli/package.json | 8 ++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 @commitlint/prompt-cli/cli.test.js diff --git a/@commitlint/prompt-cli/cli.test.js b/@commitlint/prompt-cli/cli.test.js new file mode 100644 index 0000000000..34c27b3e4e --- /dev/null +++ b/@commitlint/prompt-cli/cli.test.js @@ -0,0 +1,25 @@ +import path from 'path'; +import {git} from '@commitlint/test'; +import test from 'ava'; +import execa from 'execa'; +import stream from 'string-to-stream'; + +const bin = path.join(__dirname, './cli.js'); + +const cli = (args, options) => { + return (input = '') => { + const c = execa(bin, args, { + capture: ['stdout'], + cwd: options.cwd, + env: options.env + }); + stream(input).pipe(c.stdin); + return c.catch(err => err); + }; +}; + +test('should print warning if stage is empty', async t => { + const cwd = await git.bootstrap(); + const actual = await cli([], {cwd})('foo: bar'); + t.true(actual.stdout.includes('Nothing to commit.')); +}); diff --git a/@commitlint/prompt-cli/package.json b/@commitlint/prompt-cli/package.json index ac5fe5fd12..272d3ff6cc 100644 --- a/@commitlint/prompt-cli/package.json +++ b/@commitlint/prompt-cli/package.json @@ -13,7 +13,8 @@ "commit": "$npm_package_bin_commit", "deps": "dep-check", "pkg": "pkg-check --skip-main", - "lint": "xo" + "lint": "xo", + "test": "ava -c 4 --verbose" }, "xo": false, "repository": { @@ -36,7 +37,10 @@ }, "dependencies": { "@commitlint/prompt": "^7.2.0", + "@commitlint/test": "^7.1.2", + "ava": "^0.25.0", "execa": "0.9.0", - "meow": "3.7.0" + "meow": "3.7.0", + "string-to-stream": "^1.1.1" } }