Skip to content

Commit

Permalink
fix: manually pass argv to yargs
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Nov 16, 2019
1 parent 838f87b commit 11b3bd0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/config/args.ts
Expand Up @@ -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,
Expand Down
30 changes: 28 additions & 2 deletions 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);
});
});

0 comments on commit 11b3bd0

Please sign in to comment.