cli: added app:test command

This commit is contained in:
Patrik Oldsberg
2020-03-18 16:54:10 +01:00
parent 697ac5923f
commit 4fb95dc3f1
3 changed files with 81 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
/*
* 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.
*/
const fs = require('fs');
const path = require('path');
// If the package has it's own jest config, we use that instead. It will have to
// manually extend @spotify/web-scripts/config/jest.config.js that is desired
if (fs.existsSync('jest.config.js')) {
module.exports = require(path.resolve('jest.config.js'));
} else {
module.exports = {
// We base the jest config on web-scripts, it's pretty flat so we skip any complex merging of config objects
// Config can be found here: https://github.com/spotify/web-scripts/blob/master/packages/web-scripts/config/jest.config.js
...require('@spotify/web-scripts/config/jest.config.js'),
// Use src/setupTests.ts as the default location for configuring test env
setupFilesAfterEnv: ['<rootDir>/setupTests.ts'],
// If the package has a jest object in package.json we merge that config in. This is the recommended
// location for configuring tests.
...require(path.resolve('package.json')).jest,
};
}
@@ -0,0 +1,36 @@
/*
* 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 { resolve as resolvePath } from 'path';
import { run } from '../../helpers/run';
export default async (cmd: Command) => {
const args = [
'test',
'--config',
resolvePath(__dirname, '../../../config/jest.js'),
];
if (cmd.watch) {
args.push('--watch');
}
if (cmd.coverage) {
args.push('--coverage');
}
await run('web-scripts', args, { stdio: 'inherit' });
};
+8
View File
@@ -20,6 +20,7 @@ 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 pluginBuild from './commands/plugin/build';
import pluginLint from './commands/plugin/lint';
import pluginServe from './commands/plugin/serve';
@@ -37,6 +38,13 @@ const main = (argv: string[]) => {
.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')