deno.land / x / yargs@v17.6.0-deno / test / esm / yargs-test.mjs

yargs-test.mjs
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* global describe, it */
import * as assert from 'assert';import yargs from '../../index.mjs';
// Example of composing hierarchical commands when using ESM:import {commands} from './fixtures/commands/index.mjs';
describe('ESM', () => { describe('parser', () => { it('parses process.argv by default', () => { const parsed = yargs(['--goodnight', 'moon']).parse(); assert.strictEqual(parsed.goodnight, 'moon'); }); }); describe('commandDir', () => { it('throws an error if commndDir() used in ESM mode', () => { let err; try { yargs().commandDir('./'); } catch (_err) { err = _err; } assert.match(err.message, /not supported yet for ESM/); }); }); // Handling of strings that look like numbers, see: // https://github.com/yargs/yargs/issues/1758 describe('bug #1758', () => { it('does not drop .0 if positional is configured as string', () => { const argv = yargs('cmd 33.0') .command('cmd [str]', 'a command', yargs => { return yargs.positional('str', { type: 'string', }); }) .parse(); assert.strictEqual(argv.str, '33.0'); }); }); describe('hierarchy of commands', () => { it('allows array of commands to be registered', () => { const context = { output: {}, }; yargs().command(commands).parse('b hello world!', context); assert.strictEqual(context.output.text, 'hello world!'); }); it('allows array of subcommands to be registered', () => { const context = { output: {}, }; yargs().command(commands).parse('a d 10 5', context); assert.strictEqual(context.output.value, 50); }); });});
yargs

Version Info

Tagged at
a year ago