1
0
Fork 0

fix: manually pass argv to yargs

This commit is contained in:
ssube 2019-11-13 23:07:54 -06:00 committed by Sean Sube
parent 838f87baf5
commit 11b3bd0d09
3 changed files with 31 additions and 4 deletions

View File

@ -14,7 +14,7 @@ export const STATUS_ERROR = 1;
export const STATUS_MAX = 255;
export async function main(argv: Array<string>): Promise<number> {
const { args, mode } = await parseArgs(argv);
const { args, mode } = await parseArgs(argv.slice(2));
if (mode === MODE.complete) {
showCompletionScript();
return STATUS_SUCCESS;

View File

@ -167,7 +167,8 @@ export async function parseArgs(argv: Array<string>): Promise<ParseResults> {
// @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,

View File

@ -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);
});
});