diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 1c2b8feb5b..006975e77e 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -96,7 +96,7 @@ export function registerScriptCommand(program: CommanderStatic) { ) .action(lazy(() => import('./build').then(m => m.command))); - program + command .command('lint') .option( '--format ', @@ -107,7 +107,7 @@ export function registerScriptCommand(program: CommanderStatic) { .description('Lint a package') .action(lazy(() => import('./lint').then(m => m.default))); - program + command .command('test') .allowUnknownOption(true) // Allows the command to run, but we still need to parse raw args .helpOption(', --backstage-cli-help') // Let Jest handle help diff --git a/packages/cli/src/commands/testCommand.ts b/packages/cli/src/commands/testCommand.ts index 24a4e06f9e..7165b20925 100644 --- a/packages/cli/src/commands/testCommand.ts +++ b/packages/cli/src/commands/testCommand.ts @@ -29,7 +29,11 @@ function includesAnyOf(hayStack: string[], ...needles: string[]) { export default async (cmd: Command) => { // all args are forwarded to jest - const rawArgs = cmd.parent.rawArgs as string[]; + let parent = cmd; + while (parent.parent) { + parent = parent.parent; + } + const rawArgs = parent.rawArgs as string[]; const args = rawArgs.slice(rawArgs.indexOf('test') + 1); // Only include our config if caller isn't passing their own config @@ -37,6 +41,10 @@ export default async (cmd: Command) => { args.push('--config', paths.resolveOwn('config/jest.js')); } + if (!includesAnyOf(args, '--no-passWithNoTests', '--passWithNoTests=false')) { + args.push('--passWithNoTests'); + } + // Run in watch mode unless in CI, coverage mode, or running all tests if ( !process.env.CI &&