fix: manually pass argv to yargs
This commit is contained in:
parent
838f87baf5
commit
11b3bd0d09
|
@ -14,7 +14,7 @@ export const STATUS_ERROR = 1;
|
||||||
export const STATUS_MAX = 255;
|
export const STATUS_MAX = 255;
|
||||||
|
|
||||||
export async function main(argv: Array<string>): Promise<number> {
|
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) {
|
if (mode === MODE.complete) {
|
||||||
showCompletionScript();
|
showCompletionScript();
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
|
|
|
@ -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
|
// @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
|
// tslint:disable-next-line:no-any
|
||||||
const args = parser.argv as any;
|
const args = parser.parse(argv) as any;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
args,
|
args,
|
||||||
mode,
|
mode,
|
||||||
|
|
|
@ -1,11 +1,37 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
import mockFs from 'mock-fs';
|
||||||
|
|
||||||
import { main, STATUS_SUCCESS } from '../src/app';
|
import { main, STATUS_SUCCESS } from '../src/app';
|
||||||
import { describeLeaks } from './helpers/async';
|
import { describeLeaks, itLeaks } from './helpers/async';
|
||||||
|
|
||||||
describeLeaks('main app', async () => {
|
describeLeaks('main app', async () => {
|
||||||
xit('completion should succeed', async () => {
|
itLeaks('completion should succeed', async () => {
|
||||||
const status = await main(['node', 'test', 'complete']);
|
const status = await main(['node', 'test', 'complete']);
|
||||||
expect(status).to.equal(STATUS_SUCCESS);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue