module(cli): migrate test
Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
@@ -199,8 +199,8 @@ Options:
|
||||
Commands:
|
||||
start [options]
|
||||
build [options]
|
||||
lint [options] [directories...]
|
||||
test
|
||||
lint [options] [directories...]
|
||||
clean
|
||||
prepack
|
||||
postpack
|
||||
@@ -401,11 +401,11 @@ Options:
|
||||
|
||||
Commands:
|
||||
build [options]
|
||||
test [options]
|
||||
lint [options]
|
||||
fix [options]
|
||||
clean
|
||||
list-deprecations [options]
|
||||
test [options]
|
||||
help [command]
|
||||
```
|
||||
|
||||
|
||||
@@ -27,5 +27,6 @@ import chalk from 'chalk';
|
||||
initializer.add(import('./modules/config/alpha'));
|
||||
initializer.add(import('./modules/build/alpha'));
|
||||
initializer.add(import('./modules/migrate/alpha'));
|
||||
initializer.add(import('./modules/test/alpha'));
|
||||
await initializer.run();
|
||||
})();
|
||||
|
||||
@@ -26,6 +26,10 @@ import {
|
||||
registerCommands as registerBuildCommands,
|
||||
} from '../modules/build';
|
||||
import { registerCommands as registerMigrateCommand } from '../modules/migrate';
|
||||
import {
|
||||
registerRepoCommands as registerRepoTestCommands,
|
||||
registerPackageCommands as registerPackageTestCommands,
|
||||
} from '../modules/test';
|
||||
|
||||
export function registerRepoCommand(program: Command) {
|
||||
const command = program
|
||||
@@ -33,6 +37,7 @@ export function registerRepoCommand(program: Command) {
|
||||
.description('Command that run across an entire Backstage project');
|
||||
|
||||
registerRepoBuildCommands(command);
|
||||
registerRepoTestCommands(command);
|
||||
|
||||
command
|
||||
.command('lint')
|
||||
@@ -84,28 +89,6 @@ export function registerRepoCommand(program: Command) {
|
||||
.description('List deprecations')
|
||||
.option('--json', 'Output as JSON')
|
||||
.action(lazy(() => import('./repo/list-deprecations'), 'command'));
|
||||
|
||||
command
|
||||
.command('test')
|
||||
.allowUnknownOption(true) // Allows the command to run, but we still need to parse raw args
|
||||
.option(
|
||||
'--since <ref>',
|
||||
'Only test packages that changed since the specified ref',
|
||||
)
|
||||
.option(
|
||||
'--successCache',
|
||||
'Enable success caching, which skips running tests for unchanged packages that were successful in the previous run',
|
||||
)
|
||||
.option(
|
||||
'--successCacheDir <path>',
|
||||
'Set the success cache location, (default: node_modules/.cache/backstage-cli)',
|
||||
)
|
||||
.option(
|
||||
'--jest-help',
|
||||
'Show help for Jest CLI options, which are passed through',
|
||||
)
|
||||
.description('Run tests, forwarding args to Jest, defaulting to watch mode')
|
||||
.action(lazy(() => import('./repo/test'), 'command'));
|
||||
}
|
||||
|
||||
export function registerScriptCommand(program: Command) {
|
||||
@@ -129,6 +112,7 @@ export function registerScriptCommand(program: Command) {
|
||||
.action(lazy(() => import('./start'), 'command'));
|
||||
|
||||
registerPackageBuildCommands(command);
|
||||
registerPackageTestCommands(command);
|
||||
|
||||
command
|
||||
.command('lint [directories...]')
|
||||
@@ -149,13 +133,6 @@ export function registerScriptCommand(program: Command) {
|
||||
.description('Lint a package')
|
||||
.action(lazy(() => import('./lint'), 'default'));
|
||||
|
||||
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
|
||||
.description('Run tests, forwarding args to Jest, defaulting to watch mode')
|
||||
.action(lazy(() => import('./test'), 'default'));
|
||||
|
||||
command
|
||||
.command('clean')
|
||||
.description('Delete cache directories')
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '../../wiring/factory';
|
||||
import { Command } from 'commander';
|
||||
import { lazy } from '../../lib/lazy';
|
||||
|
||||
export default createCliPlugin({
|
||||
pluginId: 'test',
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
path: ['repo', 'test'],
|
||||
description:
|
||||
'Run tests, forwarding args to Jest, defaulting to watch mode',
|
||||
execute: async ({ args }) => {
|
||||
const command = new Command();
|
||||
command.allowUnknownOption(true);
|
||||
command.option(
|
||||
'--since <ref>',
|
||||
'Only test packages that changed since the specified ref',
|
||||
);
|
||||
command.option('--successCache', 'Enable success caching');
|
||||
command.option(
|
||||
'--successCacheDir <path>',
|
||||
'Set the success cache location, (default: node_modules/.cache/backstage-cli)',
|
||||
);
|
||||
command.option(
|
||||
'--jest-help',
|
||||
'Show help for Jest CLI options, which are passed through',
|
||||
);
|
||||
command.action(lazy(() => import('./commands/repo/test'), 'command'));
|
||||
await command.parseAsync(args, { from: 'user' });
|
||||
},
|
||||
});
|
||||
|
||||
reg.addCommand({
|
||||
path: ['package', 'test'],
|
||||
description:
|
||||
'Run tests, forwarding args to Jest, defaulting to watch mode',
|
||||
execute: async ({ args }) => {
|
||||
const command = new Command();
|
||||
|
||||
command.allowUnknownOption(true);
|
||||
command.helpOption(', --backstage-cli-help');
|
||||
command.action(
|
||||
lazy(() => import('./commands/package/test'), 'default'),
|
||||
);
|
||||
await command.parseAsync(args, { from: 'user' });
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
+2
-2
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
|
||||
import { Command, OptionValues } from 'commander';
|
||||
import { paths } from '../lib/paths';
|
||||
import { runCheck } from '../lib/run';
|
||||
import { paths } from '../../../../lib/paths';
|
||||
import { runCheck } from '../../../../lib/run';
|
||||
|
||||
function includesAnyOf(hayStack: string[], ...needles: string[]) {
|
||||
for (const needle of needles) {
|
||||
+3
-3
@@ -21,10 +21,10 @@ import { run as runJest, yargsOptions as jestYargsOptions } from 'jest-cli';
|
||||
import { relative as relativePath } from 'path';
|
||||
import { Command, OptionValues } from 'commander';
|
||||
import { Lockfile, PackageGraph } from '@backstage/cli-node';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { runCheck, runPlain } from '../../lib/run';
|
||||
import { paths } from '../../../../lib/paths';
|
||||
import { runCheck, runPlain } from '../../../../lib/run';
|
||||
import { isChildPath } from '@backstage/cli-common';
|
||||
import { SuccessCache } from '../../lib/cache/SuccessCache';
|
||||
import { SuccessCache } from '../../../../lib/cache/SuccessCache';
|
||||
|
||||
type JestProject = {
|
||||
displayName: string;
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2025 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { lazy } from '../../lib/lazy';
|
||||
|
||||
export function registerRepoCommands(command: Command) {
|
||||
command
|
||||
.command('test')
|
||||
.allowUnknownOption(true) // Allows the command to run, but we still need to parse raw args
|
||||
.option(
|
||||
'--since <ref>',
|
||||
'Only test packages that changed since the specified ref',
|
||||
)
|
||||
.option(
|
||||
'--successCache',
|
||||
'Enable success caching, which skips running tests for unchanged packages that were successful in the previous run',
|
||||
)
|
||||
.option(
|
||||
'--successCacheDir <path>',
|
||||
'Set the success cache location, (default: node_modules/.cache/backstage-cli)',
|
||||
)
|
||||
.option(
|
||||
'--jest-help',
|
||||
'Show help for Jest CLI options, which are passed through',
|
||||
)
|
||||
.description('Run tests, forwarding args to Jest, defaulting to watch mode')
|
||||
.action(lazy(() => import('./commands/repo/test'), 'command'));
|
||||
}
|
||||
|
||||
export function registerPackageCommands(command: Command) {
|
||||
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
|
||||
.description('Run tests, forwarding args to Jest, defaulting to watch mode')
|
||||
.action(lazy(() => import('./commands/package/test'), 'default'));
|
||||
}
|
||||
Reference in New Issue
Block a user