Skip to content

Commit 7167716

Browse files
committed
feat(test): validate commands
1 parent f26013f commit 7167716

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import assert from 'node:assert/strict';
2+
import { describe, it } from 'node:test';
3+
4+
import { Option } from 'commander';
5+
6+
import commands from '../index.mjs';
7+
8+
describe('Commands', () => {
9+
it('should have unique command names', () => {
10+
const names = new Set();
11+
12+
commands.forEach(({ name }) => {
13+
assert.equal(names.has(name), false, `Duplicate command name: "${name}"`);
14+
names.add(name);
15+
});
16+
});
17+
18+
it('should use correct option names', () => {
19+
commands.forEach(({ name: cmdName, options }) => {
20+
Object.entries(options).forEach(([optName, { flags }]) => {
21+
const expectedName = new Option(flags.at(-1)).attributeName();
22+
assert.equal(
23+
optName,
24+
expectedName,
25+
`In "${cmdName}" command: option "${flags}" should be named "${expectedName}", not "${optName}"`
26+
);
27+
});
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)