Skip to content

feat(test): validate commands and generators #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions bin/commands/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

import { Option } from 'commander';

import commands from '../index.mjs';

describe('Commands', () => {
it('should have unique command names', () => {
const names = new Set();

commands.forEach(({ name }) => {
assert.equal(names.has(name), false, `Duplicate command name: "${name}"`);
names.add(name);
});
});

it('should use correct option names', () => {
commands.forEach(({ name: cmdName, options }) => {
Object.entries(options).forEach(([optName, { flags }]) => {
const expectedName = new Option(flags.at(-1)).attributeName();
assert.equal(
optName,
expectedName,
`In "${cmdName}" command: option "${flags}" should be named "${expectedName}", not "${optName}"`
);
});
});
});
});
6 changes: 3 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ coverage:
target: 80%
project:
default:
# TODO(@avivkeller): Once our coverage > 50%,
# increase this to 50%, and increase on increments
target: 40%
# TODO(@avivkeller): Once our coverage > 70%,
# increase this to 70%, and increase on increments
target: 60%

ignore:
- 'eslint.config.mjs'
Expand Down
42 changes: 42 additions & 0 deletions src/generators/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

import semver from 'semver';

import { allGenerators } from '../index.mjs';

const validDependencies = [...Object.keys(allGenerators), 'ast'];
const generatorEntries = Object.entries(allGenerators);

describe('All Generators', () => {
it('should have keys matching their name property', () => {
generatorEntries.forEach(([key, generator]) => {
assert.equal(
key,
generator.name,
`Generator key "${key}" does not match its name property "${generator.name}"`
);
});
});

it('should have valid semver versions', () => {
generatorEntries.forEach(([key, generator]) => {
const isValid = semver.valid(generator.version);
assert.ok(
isValid,
`Generator "${key}" has invalid semver version: "${generator.version}"`
);
});
});

it('should have valid dependsOn references', () => {
generatorEntries.forEach(([key, generator]) => {
if (generator.dependsOn) {
assert.ok(
validDependencies.includes(generator.dependsOn),
`Generator "${key}" depends on "${generator.dependsOn}" which is not a valid generator or 'ast'`
);
}
});
});
});
Loading