toolkit: expose maxWorkers option for plugin build & test tasks (#27724)

This commit is contained in:
Domas 2020-10-01 11:50:56 +03:00 committed by GitHub
parent 22b2d4d412
commit bd9add72de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 19 deletions

View File

@ -93,6 +93,7 @@ Available options:
- `-u`, `--updateSnapshot` - Performs snapshots update. - `-u`, `--updateSnapshot` - Performs snapshots update.
- `--testNamePattern=<regex>` - Runs test with names that match provided regex (https://jestjs.io/docs/en/cli#testnamepattern-regex). - `--testNamePattern=<regex>` - Runs test with names that match provided regex (https://jestjs.io/docs/en/cli#testnamepattern-regex).
- `--testPathPattern=<regex>` - Runs test with paths that match provided regex (https://jestjs.io/docs/en/cli#testpathpattern-regex). - `--testPathPattern=<regex>` - Runs test with paths that match provided regex (https://jestjs.io/docs/en/cli#testpathpattern-regex).
- `--maxWorkers=<num>|<string>` - Limit number of Jest workers spawned (https://jestjs.io/docs/en/cli#--maxworkersnumstring)
### Build your plugin ### Build your plugin

View File

@ -138,10 +138,11 @@ export const run = (includeInternalScripts = false) => {
program program
.command('plugin:build') .command('plugin:build')
.option('--maxJestWorkers <num>|<string>', 'Limit number of Jest workers spawned')
.description('Prepares plugin dist package') .description('Prepares plugin dist package')
.option('--coverage', 'Run code coverage', false) .option('--coverage', 'Run code coverage', false)
.action(async cmd => { .action(async cmd => {
await execTask(pluginBuildTask)({ coverage: cmd.coverage, silent: true }); await execTask(pluginBuildTask)({ coverage: cmd.coverage, silent: true, maxJestWorkers: cmd.maxJestWorkers });
}); });
program program
@ -164,6 +165,7 @@ export const run = (includeInternalScripts = false) => {
.option('--watch', 'Run tests in interactive watch mode') .option('--watch', 'Run tests in interactive watch mode')
.option('--testPathPattern <regex>', 'Run only tests with a path that matches the regex') .option('--testPathPattern <regex>', 'Run only tests with a path that matches the regex')
.option('--testNamePattern <regex>', 'Run only tests with a name that matches the regex') .option('--testNamePattern <regex>', 'Run only tests with a name that matches the regex')
.option('--maxWorkers <num>|<string>', 'Limit number of workers spawned')
.description('Executes plugin tests') .description('Executes plugin tests')
.action(async cmd => { .action(async cmd => {
await execTask(pluginTestTask)({ await execTask(pluginTestTask)({
@ -172,6 +174,7 @@ export const run = (includeInternalScripts = false) => {
watch: !!cmd.watch, watch: !!cmd.watch,
testPathPattern: cmd.testPathPattern, testPathPattern: cmd.testPathPattern,
testNamePattern: cmd.testNamePattern, testNamePattern: cmd.testNamePattern,
maxWorkers: cmd.maxWorkers,
silent: true, silent: true,
}); });
}); });
@ -179,10 +182,12 @@ export const run = (includeInternalScripts = false) => {
program program
.command('plugin:ci-build') .command('plugin:ci-build')
.option('--finish', 'move all results to the jobs folder', false) .option('--finish', 'move all results to the jobs folder', false)
.option('--maxJestWorkers <num>|<string>', 'Limit number of Jest workers spawned')
.description('Build the plugin, leaving results in /dist and /coverage') .description('Build the plugin, leaving results in /dist and /coverage')
.action(async cmd => { .action(async cmd => {
await execTask(ciBuildPluginTask)({ await execTask(ciBuildPluginTask)({
finish: cmd.finish, finish: cmd.finish,
maxJestWorkers: cmd.maxJestWorkers,
}); });
}); });

View File

@ -16,6 +16,7 @@ const rimraf = promisify(rimrafCallback);
interface PluginBuildOptions { interface PluginBuildOptions {
coverage: boolean; coverage: boolean;
maxJestWorkers?: string;
} }
interface Fixable { interface Fixable {
@ -111,10 +112,10 @@ export const lintPlugin = ({ fix }: Fixable = {}) =>
} }
}); });
export const pluginBuildRunner: TaskRunner<PluginBuildOptions> = async ({ coverage }) => { export const pluginBuildRunner: TaskRunner<PluginBuildOptions> = async ({ coverage, maxJestWorkers }) => {
await prepare(); await prepare();
await lintPlugin({ fix: false }); await lintPlugin({ fix: false });
await testPlugin({ updateSnapshot: false, coverage, watch: false }); await testPlugin({ updateSnapshot: false, coverage, maxWorkers: maxJestWorkers, watch: false });
await bundlePlugin({ watch: false, production: true }); await bundlePlugin({ watch: false, production: true });
}; };

View File

@ -27,6 +27,7 @@ export interface PluginCIOptions {
finish?: boolean; finish?: boolean;
upload?: boolean; upload?: boolean;
signingAdmin?: boolean; signingAdmin?: boolean;
maxJestWorkers?: string;
} }
/** /**
@ -40,7 +41,7 @@ export interface PluginCIOptions {
* Anything that should be put into the final zip file should be put in: * Anything that should be put into the final zip file should be put in:
* ~/ci/jobs/build_xxx/dist * ~/ci/jobs/build_xxx/dist
*/ */
const buildPluginRunner: TaskRunner<PluginCIOptions> = async ({ finish }) => { const buildPluginRunner: TaskRunner<PluginCIOptions> = async ({ finish, maxJestWorkers }) => {
const start = Date.now(); const start = Date.now();
if (finish) { if (finish) {
@ -58,7 +59,7 @@ const buildPluginRunner: TaskRunner<PluginCIOptions> = async ({ finish }) => {
writeJobStats(start, workDir); writeJobStats(start, workDir);
} else { } else {
// Do regular build process with coverage // Do regular build process with coverage
await pluginBuildRunner({ coverage: true }); await pluginBuildRunner({ coverage: true, maxJestWorkers });
} }
}; };

View File

@ -8,9 +8,17 @@ export interface PluginTestOptions {
watch: boolean; watch: boolean;
testPathPattern?: string; testPathPattern?: string;
testNamePattern?: string; testNamePattern?: string;
maxWorkers?: string;
} }
export const testPlugin = ({ updateSnapshot, coverage, watch, testPathPattern, testNamePattern }: PluginTestOptions) => export const testPlugin = ({
updateSnapshot,
coverage,
watch,
testPathPattern,
testNamePattern,
maxWorkers,
}: PluginTestOptions) =>
useSpinner('Running tests', async () => { useSpinner('Running tests', async () => {
const testConfig = loadJestPluginConfig(); const testConfig = loadJestPluginConfig();
@ -22,6 +30,7 @@ export const testPlugin = ({ updateSnapshot, coverage, watch, testPathPattern, t
testPathPattern: testPathPattern ? [testPathPattern] : [], testPathPattern: testPathPattern ? [testPathPattern] : [],
testNamePattern: testNamePattern ? [testNamePattern] : [], testNamePattern: testNamePattern ? [testNamePattern] : [],
passWithNoTests: true, passWithNoTests: true,
maxWorkers,
}; };
// @ts-ignore // @ts-ignore

View File

@ -87,21 +87,21 @@ module.exports = (env = {}) =>
env.noTsCheck env.noTsCheck
? new webpack.DefinePlugin({}) // bogus plugin to satisfy webpack API ? new webpack.DefinePlugin({}) // bogus plugin to satisfy webpack API
: new ForkTsCheckerWebpackPlugin({ : new ForkTsCheckerWebpackPlugin({
eslint: { eslint: {
enabled: true, enabled: true,
files: ['public/app/**/*.{ts,tsx}', 'packages/*/src/**/*.{ts,tsx}'], files: ['public/app/**/*.{ts,tsx}', 'packages/*/src/**/*.{ts,tsx}'],
options: { options: {
cache: true, cache: true,
},
}, },
}, typescript: {
typescript: { mode: 'write-references',
mode: 'write-references', diagnosticOptions: {
diagnosticOptions: { semantic: true,
semantic: true, syntactic: true,
syntactic: true, },
}, },
}, }),
}),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: 'grafana.[name].[hash].css', filename: 'grafana.[name].[hash].css',
}), }),