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

pull/27955/head
Domas 5 years ago committed by GitHub
parent 22b2d4d412
commit bd9add72de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/grafana-toolkit/README.md
  2. 7
      packages/grafana-toolkit/src/cli/index.ts
  3. 5
      packages/grafana-toolkit/src/cli/tasks/plugin.build.ts
  4. 5
      packages/grafana-toolkit/src/cli/tasks/plugin.ci.ts
  5. 11
      packages/grafana-toolkit/src/cli/tasks/plugin/tests.ts
  6. 26
      scripts/webpack/webpack.dev.js

@ -93,6 +93,7 @@ Available options:
- `-u`, `--updateSnapshot` - Performs snapshots update.
- `--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).
- `--maxWorkers=<num>|<string>` - Limit number of Jest workers spawned (https://jestjs.io/docs/en/cli#--maxworkersnumstring)
### Build your plugin

@ -138,10 +138,11 @@ export const run = (includeInternalScripts = false) => {
program
.command('plugin:build')
.option('--maxJestWorkers <num>|<string>', 'Limit number of Jest workers spawned')
.description('Prepares plugin dist package')
.option('--coverage', 'Run code coverage', false)
.action(async cmd => {
await execTask(pluginBuildTask)({ coverage: cmd.coverage, silent: true });
await execTask(pluginBuildTask)({ coverage: cmd.coverage, silent: true, maxJestWorkers: cmd.maxJestWorkers });
});
program
@ -164,6 +165,7 @@ export const run = (includeInternalScripts = false) => {
.option('--watch', 'Run tests in interactive watch mode')
.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('--maxWorkers <num>|<string>', 'Limit number of workers spawned')
.description('Executes plugin tests')
.action(async cmd => {
await execTask(pluginTestTask)({
@ -172,6 +174,7 @@ export const run = (includeInternalScripts = false) => {
watch: !!cmd.watch,
testPathPattern: cmd.testPathPattern,
testNamePattern: cmd.testNamePattern,
maxWorkers: cmd.maxWorkers,
silent: true,
});
});
@ -179,10 +182,12 @@ export const run = (includeInternalScripts = false) => {
program
.command('plugin:ci-build')
.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')
.action(async cmd => {
await execTask(ciBuildPluginTask)({
finish: cmd.finish,
maxJestWorkers: cmd.maxJestWorkers,
});
});

@ -16,6 +16,7 @@ const rimraf = promisify(rimrafCallback);
interface PluginBuildOptions {
coverage: boolean;
maxJestWorkers?: string;
}
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 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 });
};

@ -27,6 +27,7 @@ export interface PluginCIOptions {
finish?: boolean;
upload?: 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:
* ~/ci/jobs/build_xxx/dist
*/
const buildPluginRunner: TaskRunner<PluginCIOptions> = async ({ finish }) => {
const buildPluginRunner: TaskRunner<PluginCIOptions> = async ({ finish, maxJestWorkers }) => {
const start = Date.now();
if (finish) {
@ -58,7 +59,7 @@ const buildPluginRunner: TaskRunner<PluginCIOptions> = async ({ finish }) => {
writeJobStats(start, workDir);
} else {
// Do regular build process with coverage
await pluginBuildRunner({ coverage: true });
await pluginBuildRunner({ coverage: true, maxJestWorkers });
}
};

@ -8,9 +8,17 @@ export interface PluginTestOptions {
watch: boolean;
testPathPattern?: 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 () => {
const testConfig = loadJestPluginConfig();
@ -22,6 +30,7 @@ export const testPlugin = ({ updateSnapshot, coverage, watch, testPathPattern, t
testPathPattern: testPathPattern ? [testPathPattern] : [],
testNamePattern: testNamePattern ? [testNamePattern] : [],
passWithNoTests: true,
maxWorkers,
};
// @ts-ignore

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

Loading…
Cancel
Save