From 9c44d0993dc88082b8a5bff0deb8bcbbd1d8d95e Mon Sep 17 00:00:00 2001 From: Tyler Smalley Date: Mon, 14 Dec 2020 12:12:40 -0800 Subject: [PATCH] Combines Jest unit tests Signed-off-by: Tyler Smalley --- .ci/teamcity/oss/jest.sh | 10 ------- .ci/teamcity/oss/jest_integration.sh | 10 ------- .ci/teamcity/{default => tests}/jest.sh | 4 +-- .ci/teamcity/tests/jest_integration.sh | 10 +++++++ .teamcity/src/builds/test/AllTests.kt | 2 +- .teamcity/src/builds/test/Jest.kt | 2 +- .teamcity/src/builds/test/JestIntegration.kt | 2 +- .teamcity/src/builds/test/XPackJest.kt | 19 ------------- .teamcity/src/projects/Kibana.kt | 1 - jest.config.integration.js | 1 + jest.config.js | 10 ++++++- jest.config.oss.js | 30 -------------------- packages/kbn-test/jest-preset.js | 2 +- test/scripts/jenkins_unit.sh | 24 ++++------------ test/scripts/jenkins_xpack.sh | 23 --------------- test/scripts/test/jest_integration.sh | 2 +- test/scripts/test/jest_unit.sh | 2 +- test/scripts/test/xpack_jest_unit.sh | 6 ---- vars/tasks.groovy | 1 - 19 files changed, 34 insertions(+), 127 deletions(-) delete mode 100755 .ci/teamcity/oss/jest.sh delete mode 100755 .ci/teamcity/oss/jest_integration.sh rename .ci/teamcity/{default => tests}/jest.sh (52%) create mode 100755 .ci/teamcity/tests/jest_integration.sh delete mode 100644 .teamcity/src/builds/test/XPackJest.kt delete mode 100644 jest.config.oss.js delete mode 100755 test/scripts/jenkins_xpack.sh delete mode 100755 test/scripts/test/xpack_jest_unit.sh diff --git a/.ci/teamcity/oss/jest.sh b/.ci/teamcity/oss/jest.sh deleted file mode 100755 index 0dee07d00d2bea2..000000000000000 --- a/.ci/teamcity/oss/jest.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -source "$(dirname "${0}")/../util.sh" - -export JOB=kibana-oss-jest - -checks-reporter-with-killswitch "OSS Jest Unit Tests" \ - node scripts/jest --config jest.config.oss.js --ci --verbose --maxWorkers=5 diff --git a/.ci/teamcity/oss/jest_integration.sh b/.ci/teamcity/oss/jest_integration.sh deleted file mode 100755 index 4c51d2ff29888d6..000000000000000 --- a/.ci/teamcity/oss/jest_integration.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -source "$(dirname "${0}")/../util.sh" - -export JOB=kibana-oss-jest-integration - -checks-reporter-with-killswitch "OSS Jest Integration Tests" \ - node scripts/jest_integration --ci --verbose diff --git a/.ci/teamcity/default/jest.sh b/.ci/teamcity/tests/jest.sh similarity index 52% rename from .ci/teamcity/default/jest.sh rename to .ci/teamcity/tests/jest.sh index b900d1b6d6b4e61..991791d17edde5d 100755 --- a/.ci/teamcity/default/jest.sh +++ b/.ci/teamcity/tests/jest.sh @@ -4,7 +4,7 @@ set -euo pipefail source "$(dirname "${0}")/../util.sh" -export JOB=kibana-default-jest +export JOB=kibana-jest checks-reporter-with-killswitch "Jest Unit Tests" \ - node scripts/jest x-pack --ci --verbose --maxWorkers=5 + node scripts/jest --ci --verbose --maxWorkers=10 --coverage --coverageReporters json diff --git a/.ci/teamcity/tests/jest_integration.sh b/.ci/teamcity/tests/jest_integration.sh new file mode 100755 index 000000000000000..77210e156f1d7a1 --- /dev/null +++ b/.ci/teamcity/tests/jest_integration.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -euo pipefail + +source "$(dirname "${0}")/../util.sh" + +export JOB=kibana-jest-integration + +checks-reporter-with-killswitch "Jest Integration Tests" \ + node --expose-gc scripts/jest_integration --logHeapUsage --ci --verbose --coverage --coverageReporters json diff --git a/.teamcity/src/builds/test/AllTests.kt b/.teamcity/src/builds/test/AllTests.kt index 9506d98cbe50ee9..a49d5f2b07f4c86 100644 --- a/.teamcity/src/builds/test/AllTests.kt +++ b/.teamcity/src/builds/test/AllTests.kt @@ -9,5 +9,5 @@ object AllTests : BuildType({ description = "All Non-Functional Tests" type = Type.COMPOSITE - dependsOn(QuickTests, Jest, XPackJest, JestIntegration, OssApiServerIntegration) + dependsOn(QuickTests, Jest, JestIntegration, OssApiServerIntegration) }) diff --git a/.teamcity/src/builds/test/Jest.kt b/.teamcity/src/builds/test/Jest.kt index c33c9c2678ca490..c9d170b5e5c3d26 100644 --- a/.teamcity/src/builds/test/Jest.kt +++ b/.teamcity/src/builds/test/Jest.kt @@ -12,7 +12,7 @@ object Jest : BuildType({ kibanaAgent(8) steps { - runbld("Jest Unit", "./.ci/teamcity/oss/jest.sh") + runbld("Jest Unit", "./.ci/teamcity/tests/jest.sh") } addTestSettings() diff --git a/.teamcity/src/builds/test/JestIntegration.kt b/.teamcity/src/builds/test/JestIntegration.kt index 7d44e41493b2b53..4a34ebc3abe490b 100644 --- a/.teamcity/src/builds/test/JestIntegration.kt +++ b/.teamcity/src/builds/test/JestIntegration.kt @@ -9,7 +9,7 @@ object JestIntegration : BuildType({ description = "Executes Jest Integration Tests" steps { - runbld("Jest Integration", "./.ci/teamcity/oss/jest_integration.sh") + runbld("Jest Integration", "./.ci/teamcity/tests/jest_integration.sh") } addTestSettings() diff --git a/.teamcity/src/builds/test/XPackJest.kt b/.teamcity/src/builds/test/XPackJest.kt deleted file mode 100644 index 8246b60823ff9b6..000000000000000 --- a/.teamcity/src/builds/test/XPackJest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package builds.test - -import addTestSettings -import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType -import kibanaAgent -import runbld - -object XPackJest : BuildType({ - name = "X-Pack Jest Unit" - description = "Executes X-Pack Jest Unit Tests" - - kibanaAgent(16) - - steps { - runbld("X-Pack Jest Unit", "./.ci/teamcity/default/jest.sh") - } - - addTestSettings() -}) diff --git a/.teamcity/src/projects/Kibana.kt b/.teamcity/src/projects/Kibana.kt index 1878f49debe8c1a..dad828c1e33f9ea 100644 --- a/.teamcity/src/projects/Kibana.kt +++ b/.teamcity/src/projects/Kibana.kt @@ -76,7 +76,6 @@ fun Kibana(config: KibanaConfiguration = KibanaConfiguration()) : Project { name = "Jest" buildType(Jest) - buildType(XPackJest) buildType(JestIntegration) } diff --git a/jest.config.integration.js b/jest.config.integration.js index 3dacb107f94c047..4351afd1299bec3 100644 --- a/jest.config.integration.js +++ b/jest.config.integration.js @@ -36,4 +36,5 @@ module.exports = { ], ], setupFilesAfterEnv: ['/packages/kbn-test/target/jest/setup/after_env.integration.js'], + coverageDirectory: '/target/jest-coverage/jest_integration', }; diff --git a/jest.config.js b/jest.config.js index c190556700b8128..3228d2250897757 100644 --- a/jest.config.js +++ b/jest.config.js @@ -19,5 +19,13 @@ module.exports = { rootDir: '.', - projects: [...require('./jest.config.oss').projects, ...require('./x-pack/jest.config').projects], + projects: [ + '/packages/*/jest.config.js', + '/src/*/jest.config.js', + '/src/legacy/*/jest.config.js', + '/src/plugins/*/jest.config.js', + '/test/*/jest.config.js', + ...require('./x-pack/jest.config').projects, + ], + reporters: ['default', '/packages/kbn-test/target/jest/junit_reporter'], }; diff --git a/jest.config.oss.js b/jest.config.oss.js deleted file mode 100644 index 874fd1e929a7a23..000000000000000 --- a/jest.config.oss.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you 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 = { - preset: '@kbn/test', - rootDir: '.', - projects: [ - '/packages/*/jest.config.js', - '/src/*/jest.config.js', - '/src/legacy/*/jest.config.js', - '/src/plugins/*/jest.config.js', - '/test/*/jest.config.js', - ], -}; diff --git a/packages/kbn-test/jest-preset.js b/packages/kbn-test/jest-preset.js index 55514da3e231f54..bbc15abd3268832 100644 --- a/packages/kbn-test/jest-preset.js +++ b/packages/kbn-test/jest-preset.js @@ -30,7 +30,7 @@ module.exports = { coveragePathIgnorePatterns: ['/node_modules/', '.*\\.d\\.ts'], // A list of reporter names that Jest uses when writing coverage reports - coverageReporters: !!process.env.CODE_COVERAGE ? ['json'] : ['html', 'text'], + coverageReporters: ['html', 'text'], // An array of file extensions your modules use moduleFileExtensions: ['js', 'mjs', 'json', 'ts', 'tsx', 'node'], diff --git a/test/scripts/jenkins_unit.sh b/test/scripts/jenkins_unit.sh index 7384cec36b27786..70c216c8474bef4 100755 --- a/test/scripts/jenkins_unit.sh +++ b/test/scripts/jenkins_unit.sh @@ -2,12 +2,6 @@ source test/scripts/jenkins_test_setup.sh -rename_coverage_file() { - test -f target/kibana-coverage/jest/coverage-final.json \ - && mv target/kibana-coverage/jest/coverage-final.json \ - target/kibana-coverage/jest/$1-coverage-final.json -} - if [[ -z "$CODE_COVERAGE" ]] ; then # Lint ./test/scripts/lint/eslint.sh @@ -34,18 +28,12 @@ if [[ -z "$CODE_COVERAGE" ]] ; then ./test/scripts/checks/test_projects.sh ./test/scripts/checks/test_hardening.sh else - echo " -> Running jest tests with coverage" - node scripts/jest --ci --verbose --coverage --config jest.config.oss.js || true; - rename_coverage_file "oss" - echo "" - echo "" - echo " -> Running jest integration tests with coverage" - node --max-old-space-size=8192 scripts/jest_integration --ci --verbose --coverage || true; - rename_coverage_file "oss-integration" - echo "" - echo "" + echo " -> Build runtime for canvas" + node ./x-pack/plugins/canvas/scripts/shareable_runtime + + ./test/scripts/test/jest_unit.sh + ./test/scripts/test/jest_integration.sh + echo " -> Running mocha tests with coverage" ./test/scripts/checks/mocha_coverage.sh - echo "" - echo "" fi diff --git a/test/scripts/jenkins_xpack.sh b/test/scripts/jenkins_xpack.sh deleted file mode 100755 index 66fb5ae5370bc7d..000000000000000 --- a/test/scripts/jenkins_xpack.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -source test/scripts/jenkins_test_setup.sh - -if [[ -z "$CODE_COVERAGE" ]] ; then - echo " -> Running jest tests" - - ./test/scripts/test/xpack_jest_unit.sh -else - echo " -> Build runtime for canvas" - # build runtime for canvas - echo "NODE_ENV=$NODE_ENV" - node ./x-pack/plugins/canvas/scripts/shareable_runtime - echo " -> Running jest tests with coverage" - cd x-pack - node --max-old-space-size=6144 scripts/jest --ci --verbose --maxWorkers=5 --coverage --config jest.config.js || true; - # rename file in order to be unique one - test -f ../target/kibana-coverage/jest/coverage-final.json \ - && mv ../target/kibana-coverage/jest/coverage-final.json \ - ../target/kibana-coverage/jest/xpack-coverage-final.json - echo "" - echo "" -fi diff --git a/test/scripts/test/jest_integration.sh b/test/scripts/test/jest_integration.sh index 78ed804f884305e..92ede10dd84418c 100755 --- a/test/scripts/test/jest_integration.sh +++ b/test/scripts/test/jest_integration.sh @@ -3,4 +3,4 @@ source src/dev/ci_setup/setup_env.sh checks-reporter-with-killswitch "Jest Integration Tests" \ - node scripts/jest_integration --ci --verbose + node --expose-gc scripts/jest_integration --logHeapUsage --ci --verbose --coverage --coverageReporters json diff --git a/test/scripts/test/jest_unit.sh b/test/scripts/test/jest_unit.sh index 88c0fe528b88c84..e7d3a183a6b46d1 100755 --- a/test/scripts/test/jest_unit.sh +++ b/test/scripts/test/jest_unit.sh @@ -3,4 +3,4 @@ source src/dev/ci_setup/setup_env.sh checks-reporter-with-killswitch "Jest Unit Tests" \ - node scripts/jest --config jest.config.oss.js --ci --verbose --maxWorkers=5 + node scripts/jest --ci --verbose --maxWorkers=10 --coverage --coverageReporters json diff --git a/test/scripts/test/xpack_jest_unit.sh b/test/scripts/test/xpack_jest_unit.sh deleted file mode 100755 index 33b1c8a2b51833b..000000000000000 --- a/test/scripts/test/xpack_jest_unit.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -source src/dev/ci_setup/setup_env.sh - -checks-reporter-with-killswitch "X-Pack Jest" \ - node scripts/jest x-pack --ci --verbose --maxWorkers=5 diff --git a/vars/tasks.groovy b/vars/tasks.groovy index 221e93fd7b83990..8a9d13e476d8c06 100644 --- a/vars/tasks.groovy +++ b/vars/tasks.groovy @@ -36,7 +36,6 @@ def test() { kibanaPipeline.scriptTask('Jest Unit Tests', 'test/scripts/test/jest_unit.sh'), kibanaPipeline.scriptTask('API Integration Tests', 'test/scripts/test/api_integration.sh'), - kibanaPipeline.scriptTask('X-Pack Jest Unit Tests', 'test/scripts/test/xpack_jest_unit.sh'), ]) }