From 11b3bd0d09ac5570639495eb3c2fb7218038560a Mon Sep 17 00:00:00 2001 From: ssube Date: Wed, 13 Nov 2019 23:07:54 -0600 Subject: [PATCH] fix: manually pass argv to yargs --- src/app.ts | 2 +- src/config/args.ts | 3 ++- test/TestApp.ts | 30 ++++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/app.ts b/src/app.ts index 6a2773a..76ed1e5 100644 --- a/src/app.ts +++ b/src/app.ts @@ -14,7 +14,7 @@ export const STATUS_ERROR = 1; export const STATUS_MAX = 255; export async function main(argv: Array): Promise { - const { args, mode } = await parseArgs(argv); + const { args, mode } = await parseArgs(argv.slice(2)); if (mode === MODE.complete) { showCompletionScript(); return STATUS_SUCCESS; diff --git a/src/config/args.ts b/src/config/args.ts index 9ebe394..201cf2f 100644 --- a/src/config/args.ts +++ b/src/config/args.ts @@ -167,7 +167,8 @@ export async function parseArgs(argv: Array): Promise { // @TODO: this should not need a cast but the parser's type omits command options and doesn't expose camelCase // tslint:disable-next-line:no-any - const args = parser.argv as any; + const args = parser.parse(argv) as any; + return { args, mode, diff --git a/test/TestApp.ts b/test/TestApp.ts index b34911c..54e2fd9 100644 --- a/test/TestApp.ts +++ b/test/TestApp.ts @@ -1,11 +1,37 @@ import { expect } from 'chai'; +import mockFs from 'mock-fs'; import { main, STATUS_SUCCESS } from '../src/app'; -import { describeLeaks } from './helpers/async'; +import { describeLeaks, itLeaks } from './helpers/async'; describeLeaks('main app', async () => { - xit('completion should succeed', async () => { + itLeaks('completion should succeed', async () => { const status = await main(['node', 'test', 'complete']); expect(status).to.equal(STATUS_SUCCESS); }); + + itLeaks('should list rules and exit', async () => { + const status = await main(['node', 'test', 'list']); + expect(status).to.equal(STATUS_SUCCESS); + }); + + itLeaks('should load the source', async () => { + mockFs({ + 'docs': { + 'config.yml': 'data: {logger: {level: debug, name: test, stream: !stream stderr}}', + }, + 'test.yml': 'hello world', + }); + + const status = await main([ + 'node', 'test', + '--config-path', 'docs', + '--config-name', 'config.yml', + '--source', 'test.yml', + ]); + + mockFs.restore(); + + expect(status).to.equal(STATUS_SUCCESS); + }); });