cli: fix test script setup and make it pass with no tests by default
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -96,7 +96,7 @@ export function registerScriptCommand(program: CommanderStatic) {
|
||||
)
|
||||
.action(lazy(() => import('./build').then(m => m.command)));
|
||||
|
||||
program
|
||||
command
|
||||
.command('lint')
|
||||
.option(
|
||||
'--format <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
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user