[ci] Run Jest tests in parallel (#115687)

* [ci] Run Jest tests in parallel

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

* Disable coverage

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

* Make hourly match prs

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

* Update timeout

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

* mock process.execArgv so that it is consistent

* Remove comment

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
Tyler Smalley 2021-11-02 08:53:07 -07:00 committed by GitHub
parent 38213cd0e5
commit 237d68d6e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 66 additions and 93 deletions

View file

@ -119,6 +119,14 @@ steps:
- exit_status: '*'
limit: 1
- command: .buildkite/scripts/steps/test/jest.sh
label: 'Jest Tests'
parallelism: 6
agents:
queue: n2-4
timeout_in_minutes: 90
key: jest
- command: .buildkite/scripts/steps/test/jest_integration.sh
label: 'Jest Integration Tests'
agents:
@ -133,13 +141,6 @@ steps:
timeout_in_minutes: 120
key: api-integration
- command: .buildkite/scripts/steps/test/jest.sh
label: 'Jest Tests'
agents:
queue: c2-16
timeout_in_minutes: 120
key: jest
- command: .buildkite/scripts/steps/lint.sh
label: 'Linting'
agents:

View file

@ -117,6 +117,14 @@ steps:
- exit_status: '*'
limit: 1
- command: .buildkite/scripts/steps/test/jest.sh
label: 'Jest Tests'
parallelism: 6
agents:
queue: n2-4
timeout_in_minutes: 90
key: jest
- command: .buildkite/scripts/steps/test/jest_integration.sh
label: 'Jest Integration Tests'
agents:
@ -131,13 +139,6 @@ steps:
timeout_in_minutes: 120
key: api-integration
- command: .buildkite/scripts/steps/test/jest.sh
label: 'Jest Tests'
agents:
queue: c2-16
timeout_in_minutes: 120
key: jest
- command: .buildkite/scripts/steps/lint.sh
label: 'Linting'
agents:

View file

@ -9,5 +9,5 @@ is_test_execution_step
.buildkite/scripts/bootstrap.sh
echo '--- Jest'
checks-reporter-with-killswitch "Jest Unit Tests" \
node scripts/jest --ci --verbose --maxWorkers=10
checks-reporter-with-killswitch "Jest Unit Tests $((BUILDKITE_PARALLEL_JOB+1))" \
.buildkite/scripts/steps/test/jest_parallel.sh

View file

@ -0,0 +1,28 @@
#!/bin/bash
set -uo pipefail
JOB=$BUILDKITE_PARALLEL_JOB
JOB_COUNT=$BUILDKITE_PARALLEL_JOB_COUNT
# a jest failure will result in the script returning an exit
# code of 10
i=0
exitCode=0
find src x-pack packages -name jest.config.js -not -path "*/__fixtures__/*" | sort | while read config; do
if [ "$(($i % $JOB_COUNT))" -eq $JOB ]; then
echo "--- $ node scripts/jest --config $config"
node --max-old-space-size=5632 ./node_modules/.bin/jest --config=$config --runInBand --coverage=false
if [ $? -ne 0 ]; then
exitCode=10
echo "^^^ +++"
fi
fi
((i=i+1))
done
exit $exitCode

View file

@ -79,6 +79,7 @@ expect.addSnapshotSerializer(extendedEnvSerializer);
beforeEach(() => {
jest.clearAllMocks();
log.messages.length = 0;
process.execArgv = ['--inheritted', '--exec', '--argv'];
currentProc = undefined;
});
@ -138,8 +139,9 @@ describe('#run$', () => {
"isDevCliChild": "true",
},
"nodeOptions": Array [
"--preserve-symlinks-main",
"--preserve-symlinks",
"--inheritted",
"--exec",
"--argv",
],
"stdio": "pipe",
},

View file

@ -1,13 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-rule-data-utils'],
};

View file

@ -1,13 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-securitysolution-list-constants'],
};

View file

@ -1,13 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-securitysolution-t-grid'],
};

View file

@ -46,7 +46,15 @@ module.exports = {
modulePathIgnorePatterns: ['__fixtures__/', 'target/'],
// Use this configuration option to add custom reporters to Jest
reporters: ['default', '@kbn/test/target_node/jest/junit_reporter'],
reporters: [
'default',
[
'@kbn/test/target_node/jest/junit_reporter',
{
rootDirectory: '.',
},
],
],
// The paths to modules that run some code to configure or set up the testing environment before each test
setupFiles: [

View file

@ -52,11 +52,12 @@ export function runJest(configName = 'jest.config.js') {
const runStartTime = Date.now();
const reportTime = getTimeReporter(log, 'scripts/jest');
let cwd: string;
let testFiles: string[];
const cwd: string = process.env.INIT_CWD || process.cwd();
if (!argv.config) {
cwd = process.env.INIT_CWD || process.cwd();
testFiles = argv._.splice(2).map((p) => resolve(cwd, p));
const commonTestFiles = commonBasePath(testFiles);
const testFilesProvided = testFiles.length > 0;

View file

@ -1,16 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/src/plugins/expression_error'],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/expression_error',
coverageReporters: ['text', 'html'],
collectCoverageFrom: ['<rootDir>/src/plugins/expression_error/{common,public}/**/*.{ts,tsx}'],
};

View file

@ -1,15 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
module.exports = {
collectCoverageFrom: ['<rootDir>/x-pack/plugins/metrics_entities/{common,server}/**/*.{ts,tsx}'],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/x-pack/plugins/metrics_entities',
coverageReporters: ['text', 'html'],
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/plugins/metrics_entities'],
};

View file

@ -17,7 +17,8 @@ import { LevelLogger } from '../../lib';
jest.mock('./checksum');
jest.mock('./download');
describe('ensureBrowserDownloaded', () => {
// https://github.com/elastic/kibana/issues/115881
describe.skip('ensureBrowserDownloaded', () => {
let logger: jest.Mocked<LevelLogger>;
beforeEach(() => {

View file

@ -24,7 +24,8 @@ import { registerDeprecationsRoutes } from './deprecations';
type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
describe(`GET ${API_GET_ILM_POLICY_STATUS}`, () => {
// https://github.com/elastic/kibana/issues/115881
describe.skip(`GET ${API_GET_ILM_POLICY_STATUS}`, () => {
const reportingSymbol = Symbol('reporting');
let server: SetupServerReturn['server'];
let httpSetup: SetupServerReturn['httpSetup'];