Skip to content

Commit b3e6795

Browse files
authored
Add describe wrappers so test output makes sense without filenames (#2472)
1 parent 3dd6086 commit b3e6795

File tree

100 files changed

+5441
-5275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+5441
-5275
lines changed

tests/args.literal.test.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
const commander = require('../');
2-
const { test } = require('node:test');
2+
const { test, describe } = require('node:test');
33
const assert = require('node:assert/strict');
44

55
// Utility Conventions: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02
66
//
77
// 12.2 Utility Syntax Guidelines, Guideline 10:
88
// The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.
99

10-
test('when arguments includes -- then stop processing options', () => {
11-
const program = new commander.Command();
12-
program
13-
.option('-f, --foo', 'add some foo')
14-
.option('-b, --bar', 'add some bar')
15-
.argument('[args...]');
16-
program.parse(['node', 'test', '--foo', '--', '--bar', 'baz']);
17-
// More than one assert, ported from legacy test
18-
const opts = program.opts();
19-
assert.equal(opts.foo, true);
20-
assert.equal(opts.bar, undefined);
21-
assert.deepEqual(program.args, ['--bar', 'baz']);
22-
});
10+
describe('end of options delimiter "--"', () => {
11+
test('when arguments includes -- then stop processing options', () => {
12+
const program = new commander.Command();
13+
program
14+
.option('-f, --foo', 'add some foo')
15+
.option('-b, --bar', 'add some bar')
16+
.argument('[args...]');
17+
program.parse(['node', 'test', '--foo', '--', '--bar', 'baz']);
18+
// More than one assert, ported from legacy test
19+
const opts = program.opts();
20+
assert.equal(opts.foo, true);
21+
assert.equal(opts.bar, undefined);
22+
assert.deepEqual(program.args, ['--bar', 'baz']);
23+
});
2324

24-
test('when arguments include -- then more literals are passed-through as args', () => {
25-
const program = new commander.Command();
26-
program
27-
.option('-f, --foo', 'add some foo')
28-
.option('-b, --bar', 'add some bar')
29-
.argument('[args...]');
30-
program.parse(['node', 'test', '--', 'cmd', '--', '--arg']);
31-
assert.deepEqual(program.args, ['cmd', '--', '--arg']);
25+
test('when arguments include -- then more -- are passed-through as args', () => {
26+
const program = new commander.Command();
27+
program
28+
.option('-f, --foo', 'add some foo')
29+
.option('-b, --bar', 'add some bar')
30+
.argument('[args...]');
31+
program.parse(['node', 'test', '--', 'cmd', '--', '--arg']);
32+
assert.deepEqual(program.args, ['cmd', '--', '--arg']);
33+
});
3234
});

tests/args.variadic.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('node:assert/strict');
44

55
// Testing variadic arguments.
66

7-
describe('variadic argument', () => {
7+
describe('Command variadic argument using .arguments() or .command()', () => {
88
test('when no extra arguments specified for program then variadic arg is empty array', (t) => {
99
const actionMock = t.mock.fn();
1010
const program = new commander.Command();

tests/argument.choices.test.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@ const { createTestCommand } = require('./testHelpers');
33
const { test, describe } = require('node:test');
44
const assert = require('node:assert/strict');
55

6-
test('when command argument in choices then argument set', () => {
7-
const program = createTestCommand();
8-
let shade;
9-
program
10-
.addArgument(new commander.Argument('<shade>').choices(['red', 'blue']))
11-
.action((shadeParam) => {
12-
shade = shadeParam;
13-
});
14-
program.parse(['red'], { from: 'user' });
15-
assert.equal(shade, 'red');
16-
});
6+
describe('Argument.choices()', () => {
7+
test('when command argument in choices then argument set', () => {
8+
const program = createTestCommand();
9+
let shade;
10+
program
11+
.addArgument(new commander.Argument('<shade>').choices(['red', 'blue']))
12+
.action((shadeParam) => {
13+
shade = shadeParam;
14+
});
15+
program.parse(['red'], { from: 'user' });
16+
assert.equal(shade, 'red');
17+
});
1718

18-
test('when command argument is not in choices then error', () => {
19-
// Lightweight check, more detailed testing of behaviour in command.exitOverride.test.js
20-
const program = createTestCommand();
21-
program.addArgument(
22-
new commander.Argument('<shade>').choices(['red', 'blue']),
23-
);
24-
assert.throws(() => {
25-
program.parse(['orange'], { from: 'user' });
19+
test('when command argument is not in choices then error', () => {
20+
// Lightweight check, more detailed testing of behaviour in command.exitOverride.test.js
21+
const program = createTestCommand();
22+
program.addArgument(
23+
new commander.Argument('<shade>').choices(['red', 'blue']),
24+
);
25+
assert.throws(() => {
26+
program.parse(['orange'], { from: 'user' });
27+
});
2628
});
2729
});
2830

29-
describe('choices parameter is treated as readonly, per TypeScript declaration', () => {
31+
describe('Argument.choices() parameter is treated as readonly, per TypeScript declaration', () => {
3032
test('when choices called then parameter does not change', () => {
3133
// Unlikely this could break, but check the API we are declaring in TypeScript.
3234
const original = ['red', 'blue', 'green'];

0 commit comments

Comments
 (0)