From 89f39a06e1f33b344ca36dba6424f84210d1283d Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 18 Mar 2020 17:42:40 +0100 Subject: [PATCH] cli: unify test and lint commands --- packages/app/package.json | 4 +- packages/cli/src/commands/{app => }/lint.ts | 2 +- packages/cli/src/commands/plugin/lint.ts | 27 -------------- .../cli/src/commands/{app => }/testCommand.ts | 4 +- packages/cli/src/index.ts | 37 ++++++------------- .../templates/default-plugin/jest.config.js | 20 ---------- .../templates/default-plugin/package.json.hbs | 4 +- .../{jest.setup.ts => src/setupTests.ts} | 0 plugins/home-page/package.json | 4 +- plugins/welcome/package.json | 4 +- 10 files changed, 22 insertions(+), 84 deletions(-) rename packages/cli/src/commands/{app => }/lint.ts (95%) delete mode 100644 packages/cli/src/commands/plugin/lint.ts rename packages/cli/src/commands/{app => }/testCommand.ts (90%) delete mode 100644 packages/cli/templates/default-plugin/jest.config.js rename packages/cli/templates/default-plugin/{jest.setup.ts => src/setupTests.ts} (100%) diff --git a/packages/app/package.json b/packages/app/package.json index e1f5c68c5f..4a7d0a5e4c 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -27,8 +27,8 @@ "scripts": { "start": "cross-env EXTEND_ESLINT=true SKIP_PREFLIGHT_CHECK=true backstage-cli watch-deps -- react-scripts start", "build": "cross-env EXTEND_ESLINT=true SKIP_PREFLIGHT_CHECK=true react-scripts build", - "test": "backstage-cli app:test", - "lint": "backstage-cli app:lint" + "test": "backstage-cli test", + "lint": "backstage-cli lint" }, "browserslist": { "production": [ diff --git a/packages/cli/src/commands/app/lint.ts b/packages/cli/src/commands/lint.ts similarity index 95% rename from packages/cli/src/commands/app/lint.ts rename to packages/cli/src/commands/lint.ts index bacd66f1c7..3fbc30f897 100644 --- a/packages/cli/src/commands/app/lint.ts +++ b/packages/cli/src/commands/lint.ts @@ -15,7 +15,7 @@ */ import { Command } from 'commander'; -import { run } from '../../helpers/run'; +import { run } from '../helpers/run'; export default async (cmd: Command) => { const args = ['lint', '--max-warnings=0', '--format=codeframe']; diff --git a/packages/cli/src/commands/plugin/lint.ts b/packages/cli/src/commands/plugin/lint.ts deleted file mode 100644 index bacd66f1c7..0000000000 --- a/packages/cli/src/commands/plugin/lint.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { run } from '../../helpers/run'; - -export default async (cmd: Command) => { - const args = ['lint', '--max-warnings=0', '--format=codeframe']; - if (cmd.fix) { - args.push('--fix'); - } - - await run('web-scripts', args); -}; diff --git a/packages/cli/src/commands/app/testCommand.ts b/packages/cli/src/commands/testCommand.ts similarity index 90% rename from packages/cli/src/commands/app/testCommand.ts rename to packages/cli/src/commands/testCommand.ts index d6ba35224d..f632670184 100644 --- a/packages/cli/src/commands/app/testCommand.ts +++ b/packages/cli/src/commands/testCommand.ts @@ -16,13 +16,13 @@ import { Command } from 'commander'; import { resolve as resolvePath } from 'path'; -import { run } from '../../helpers/run'; +import { run } from '../helpers/run'; export default async (cmd: Command) => { const args = [ 'test', '--config', - resolvePath(__dirname, '../../../config/jest.js'), + resolvePath(__dirname, '../../config/jest.js'), ]; if (cmd.watch) { diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 127ca213f6..c9a7a14393 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -19,12 +19,10 @@ import chalk from 'chalk'; import fs from 'fs'; import createPluginCommand from './commands/createPlugin'; import watch from './commands/watch-deps'; -import appLint from './commands/app/lint'; -import appTest from './commands/app/testCommand'; +import lintCommand from './commands/lint'; +import testCommand from './commands/testCommand'; import pluginBuild from './commands/plugin/build'; -import pluginLint from './commands/plugin/lint'; import pluginServe from './commands/plugin/serve'; -import pluginTest from './commands/plugin/testCommand'; import { exitWithError } from './helpers/errors'; const main = (argv: string[]) => { @@ -32,19 +30,6 @@ const main = (argv: string[]) => { program.name('backstage-cli').version(packageJson.version ?? '0.0.0'); - program - .command('app:lint') - .option('--fix', 'Attempt to automatically fix violations') - .description('Lint an app') - .action(actionHandler(appLint)); - - program - .command('app:test') - .option('--watch', 'Enable watch mode') - .option('--coverage', 'Report test coverage') - .description('Run all tests for an app') - .action(actionHandler(appTest)); - program .command('create-plugin') .description('Creates a new plugin in the current repository') @@ -56,23 +41,23 @@ const main = (argv: string[]) => { .description('Build a plugin') .action(actionHandler(pluginBuild)); - program - .command('plugin:lint') - .option('--fix', 'Attempt to automatically fix violations') - .description('Lint a plugin') - .action(actionHandler(pluginLint)); - program .command('plugin:serve') .description('Serves the dev/ folder of a plugin') .action(actionHandler(pluginServe)); program - .command('plugin:test') + .command('lint') + .option('--fix', 'Attempt to automatically fix violations') + .description('Lint a package') + .action(actionHandler(lintCommand)); + + program + .command('test') .option('--watch', 'Enable watch mode') .option('--coverage', 'Report test coverage') - .description('Run all tests for a plugin') - .action(actionHandler(pluginTest)); + .description('Run all tests for package') + .action(actionHandler(testCommand)); program .command('watch-deps') diff --git a/packages/cli/templates/default-plugin/jest.config.js b/packages/cli/templates/default-plugin/jest.config.js deleted file mode 100644 index 2e584f12dc..0000000000 --- a/packages/cli/templates/default-plugin/jest.config.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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. - */ - -module.exports = { - ...require('@spotify/web-scripts/config/jest.config.js'), - setupFilesAfterEnv: ['../jest.setup.ts'], -}; diff --git a/packages/cli/templates/default-plugin/package.json.hbs b/packages/cli/templates/default-plugin/package.json.hbs index 2b0f66ea2f..3b9af836a2 100644 --- a/packages/cli/templates/default-plugin/package.json.hbs +++ b/packages/cli/templates/default-plugin/package.json.hbs @@ -7,8 +7,8 @@ "private": false, "scripts": { "build": "backstage-cli plugin:build", - "lint": "backstage-cli plugin:lint", - "test": "backstage-cli plugin:test" + "lint": "backstage-cli lint", + "test": "backstage-cli test" }, "devDependencies": { "@spotify-backstage/cli": "^{{version}}" diff --git a/packages/cli/templates/default-plugin/jest.setup.ts b/packages/cli/templates/default-plugin/src/setupTests.ts similarity index 100% rename from packages/cli/templates/default-plugin/jest.setup.ts rename to packages/cli/templates/default-plugin/src/setupTests.ts diff --git a/plugins/home-page/package.json b/plugins/home-page/package.json index af515ae646..551437e874 100644 --- a/plugins/home-page/package.json +++ b/plugins/home-page/package.json @@ -18,8 +18,8 @@ }, "scripts": { "build": "backstage-cli plugin:build", - "lint": "backstage-cli plugin:lint", - "test": "backstage-cli plugin:test" + "lint": "backstage-cli lint", + "test": "backstage-cli test" }, "license": "Apache-2.0" } diff --git a/plugins/welcome/package.json b/plugins/welcome/package.json index 3a75a62755..078812e300 100644 --- a/plugins/welcome/package.json +++ b/plugins/welcome/package.json @@ -7,8 +7,8 @@ "private": false, "scripts": { "build": "backstage-cli plugin:build", - "lint": "backstage-cli plugin:lint", - "test": "backstage-cli plugin:test" + "lint": "backstage-cli lint", + "test": "backstage-cli test" }, "devDependencies": { "@spotify-backstage/core": "^0.1.0",