Address review feedback: role.ts, repo start params, test coverage

- Remove unnecessary optional chaining on getRoleInfo().role since it
  throws for unknown roles.
- Add parameters declaration to repo start so [packages...] shows in
  help output.
- Add tests verifying cleye strips Backstage flags from args before
  forwarding to Jest, including legacy camelCase flag support.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-04 10:10:31 +01:00
parent 629e9f5558
commit e8173b3012
4 changed files with 61 additions and 4 deletions
+2 -2
View File
@@ -33,7 +33,7 @@ Commands:
### `backstage-cli build-workspace`
```
Usage: backstage-cli build-workspace
Usage: backstage-cli build-workspace <workspace-dir> [packages...]
Options:
--always-pack
@@ -511,7 +511,7 @@ Options:
### `backstage-cli repo start`
```
Usage: backstage-cli repo start
Usage: backstage-cli repo start [packages...]
Options:
--config <string>
@@ -41,7 +41,8 @@ export default async ({ args, info }: CommandContext) => {
_: namesOrPaths,
} = cli(
{
help: info,
help: { ...info, usage: `${info.usage} [packages...]` },
parameters: ['[packages...]'],
flags: {
plugin: {
type: [String],
+1 -1
View File
@@ -23,7 +23,7 @@ export async function findRoleFromCommand(opts: {
role?: string;
}): Promise<PackageRole> {
if (opts.role) {
return PackageRoles.getRoleInfo(opts.role)?.role;
return PackageRoles.getRoleInfo(opts.role).role;
}
const pkg = await fs.readJson(targetPaths.resolve('package.json'));
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import { cli } from 'cleye';
import { createFlagFinder } from './test';
describe('createFlagFinder', () => {
@@ -45,3 +46,58 @@ describe('createFlagFinder', () => {
expect(find('--qux')).toBe(true);
});
});
describe('repo test arg forwarding', () => {
// Mirrors the cleye configuration used in the repo test command handler
function parseRepoTestArgs(args: string[]) {
return cli(
{
help: false,
flags: {
since: { type: String },
successCache: { type: Boolean },
successCacheDir: { type: String },
jestHelp: { type: Boolean },
},
ignoreArgv: type => type === 'unknown-flag' || type === 'argument',
},
undefined,
args,
);
}
it('strips Backstage flags from args while preserving Jest flags and arguments', () => {
const args = [
'--since',
'main',
'--success-cache',
'--coverage',
'--watch',
'path/to/test',
];
const { flags } = parseRepoTestArgs(args);
expect(flags.since).toBe('main');
expect(flags.successCache).toBe(true);
expect(args).toEqual(['--coverage', '--watch', 'path/to/test']);
});
it('supports legacy camelCase flag names', () => {
const args = ['--successCache', '--successCacheDir', '/tmp/cache'];
const { flags } = parseRepoTestArgs(args);
expect(flags.successCache).toBe(true);
expect(flags.successCacheDir).toBe('/tmp/cache');
expect(args).toEqual([]);
});
it('leaves args untouched when no Backstage flags are present', () => {
const args = ['--coverage', '--verbose', '--bail'];
parseRepoTestArgs(args);
expect(args).toEqual(['--coverage', '--verbose', '--bail']);
});
});