Skip to content

Commit

Permalink
test(deno): add example of parseAsync behavior (yargs#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Apr 7, 2021
1 parent 11a9aac commit 6d115fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 1 addition & 5 deletions deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
import denoPlatformShim from './lib/platform-shims/deno.ts';
import {YargsFactory} from './build/lib/yargs-factory.js';

const WrappedYargs = YargsFactory(denoPlatformShim);

function Yargs(args?: string[]) {
return WrappedYargs(args);
}
const Yargs = YargsFactory(denoPlatformShim);

export default Yargs;
17 changes: 17 additions & 0 deletions test/deno/yargs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,20 @@ Deno.test('hierarchy of commands', async () => {
yargs().command(commands).parse('a c 10 5', context);
assertEquals(context.output.value, 15);
});

Deno.test('parseAsync()', async () => {
const err: Error | null = null;
const argvPromise = yargs()
.middleware([
async (argv: Arguments) => {
await new Promise(resolve => {
setTimeout(resolve, 10);
});
argv.foo *= 2;
},
])
.parseAsync('--foo 33');
assertEquals(typeof argvPromise.then, 'function');
const argv = (await argvPromise) as Arguments;
assertEquals(argv.foo, 66);
});

0 comments on commit 6d115fc

Please sign in to comment.