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:
Patrik Oldsberg
2022-02-14 21:16:50 +01:00
parent 03fb4d9c9b
commit 11e1621e53
2 changed files with 11 additions and 3 deletions
+2 -2
View File
@@ -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
+9 -1
View File
@@ -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 &&