From f4822f09a045f3d51aa6589660fab6c8ef0de6e5 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Sat, 28 Nov 2020 20:46:16 -0800 Subject: [PATCH] test: increase CLI test coverage (#189) --- .mocharc.json | 2 +- README.md | 2 +- test/zcli.ts | 55 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/.mocharc.json b/.mocharc.json index 1f491ba..789d08b 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,6 +1,6 @@ { "check-leaks": true, - "timeout": 10000, + "timeout": 20000, "throw-deprecation": true, "enable-source-maps": true } diff --git a/README.md b/README.md index b567cb1..391de9e 100644 --- a/README.md +++ b/README.md @@ -249,4 +249,4 @@ complex(); ## License -[MIT](LICENSE) +[MIT](LICENSE.md) diff --git a/test/zcli.ts b/test/zcli.ts index 720ce2d..aeec0f3 100644 --- a/test/zcli.ts +++ b/test/zcli.ts @@ -3,11 +3,62 @@ import * as execa from 'execa'; import {assert} from 'chai'; describe('cli', () => { - it('should link and run a basic command', async () => { + before(async () => { await execa('npm', ['link']); + }); + + it('should show output for failures', async () => { const res = await execa('npx', ['linkinator', 'test/fixtures/basic'], { reject: false, }); assert.include(res.stderr, 'ERROR: Detected 1 broken links'); - }).timeout(60000); + }); + + it('should pass successful markdown scan', async () => { + const res = await execa('npx', [ + 'linkinator', + '--markdown', + 'test/fixtures/markdown/README.md', + ]); + assert.include(res.stdout, 'Successfully scanned'); + }); + + it('should show help if no params are provided', async () => { + const res = await execa('npx', ['linkinator'], { + reject: false, + }); + assert.include(res.stdout, '$ linkinator LOCATION [ --arguments ]'); + }); + + it('should flag skipped links', async () => { + const res = await execa('npx', [ + 'linkinator', + '--markdown', + '--skip', + 'LICENSE.md', + 'test/fixtures/markdown/README.md', + ]); + assert.include(res.stdout, '[SKP]'); + }); + + it('should provide CSV if asked nicely', async () => { + const res = await execa('npx', [ + 'linkinator', + '--markdown', + '--format', + 'csv', + 'test/fixtures/markdown/README.md', + ]); + assert.include(res.stdout, '/README.md,200,OK,'); + }); + + it('should not show links if --silent', async () => { + const res = await execa('npx', [ + 'linkinator', + '--markdown', + '--silent', + 'test/fixtures/markdown/README.md', + ]); + assert.strictEqual(res.stdout.indexOf('['), -1); + }); });