From 875c7a8914d255697f1605859b94b12afcf9ba0e Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 12 Jan 2021 17:32:23 +0000 Subject: [PATCH 1/6] chore(NA): remove mocha junit ci integrations --- .ci/Jenkinsfile_flaky | 29 +++++-------------- .ci/teamcity/tests/mocha.sh | 8 ----- .eslintrc.js | 3 -- .teamcity/src/builds/test/QuickTests.kt | 1 - .../contributing/development-tests.asciidoc | 6 ---- .../interpreting-ci-failures.asciidoc | 2 +- package.json | 1 - packages/README.md | 16 ++++------ packages/kbn-plugin-generator/README.md | 4 --- scripts/mocha.js | 21 -------------- test/scripts/jenkins_unit.sh | 1 - test/scripts/test/mocha.sh | 7 ----- test/tsconfig.json | 2 +- vars/tasks.groovy | 1 - x-pack/package.json | 3 +- .../canvas/storybook/webpack.dll.config.js | 1 - x-pack/test/tsconfig.json | 2 +- 17 files changed, 17 insertions(+), 91 deletions(-) delete mode 100755 .ci/teamcity/tests/mocha.sh delete mode 100644 scripts/mocha.js delete mode 100755 test/scripts/test/mocha.sh diff --git a/.ci/Jenkinsfile_flaky b/.ci/Jenkinsfile_flaky index 2f496329dfd8ec..33204d73964616 100644 --- a/.ci/Jenkinsfile_flaky +++ b/.ci/Jenkinsfile_flaky @@ -5,11 +5,10 @@ kibanaLibrary.load() def CI_GROUP_PARAM = params.CI_GROUP -// Looks like 'oss:ciGroup:1', 'oss:firefoxSmoke', or 'all:serverMocha' +// Looks like 'oss:ciGroup:1', 'oss:firefoxSmoke' def JOB_PARTS = CI_GROUP_PARAM.split(':') def IS_XPACK = JOB_PARTS[0] == 'xpack' def JOB = JOB_PARTS[1] -def NEED_BUILD = JOB != 'serverMocha' def CI_GROUP = JOB_PARTS.size() > 2 ? JOB_PARTS[2] : '' def EXECUTIONS = params.NUMBER_EXECUTIONS.toInteger() def AGENT_COUNT = getAgentCount(EXECUTIONS) @@ -31,15 +30,13 @@ kibanaPipeline(timeoutMinutes: 180) { print "Agent ${agentNumberInside} - ${agentExecutions} executions" workers.functional('flaky-test-runner', { - if (NEED_BUILD) { - if (!IS_XPACK) { - kibanaPipeline.buildOss() - if (CI_GROUP == '1') { - runbld("./test/scripts/jenkins_build_kbn_sample_panel_action.sh", "Build kbn tp sample panel action for ciGroup1") - } - } else { - kibanaPipeline.buildXpack() + if (!IS_XPACK) { + kibanaPipeline.buildOss() + if (CI_GROUP == '1') { + runbld("./test/scripts/jenkins_build_kbn_sample_panel_action.sh", "Build kbn tp sample panel action for ciGroup1") } + } else { + kibanaPipeline.buildXpack() } }, getWorkerMap(agentNumberInside, agentExecutions, worker, workerFailures))() } @@ -60,17 +57,7 @@ kibanaPipeline(timeoutMinutes: 180) { def getWorkerFromParams(isXpack, job, ciGroup) { if (!isXpack) { - if (job == 'serverMocha') { - return kibanaPipeline.functionalTestProcess('serverMocha', { - kibanaPipeline.bash( - """ - source src/dev/ci_setup/setup_env.sh - node scripts/mocha - """, - "run `node scripts/mocha`" - ) - }) - } else if (job == 'accessibility') { + if (job == 'accessibility') { return kibanaPipeline.functionalTestProcess('kibana-accessibility', './test/scripts/jenkins_accessibility.sh') } else if (job == 'firefoxSmoke') { return kibanaPipeline.functionalTestProcess('firefoxSmoke', './test/scripts/jenkins_firefox_smoke.sh') diff --git a/.ci/teamcity/tests/mocha.sh b/.ci/teamcity/tests/mocha.sh deleted file mode 100755 index acb088220fa786..00000000000000 --- a/.ci/teamcity/tests/mocha.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -source "$(dirname "${0}")/../util.sh" - -checks-reporter-with-killswitch "Mocha Tests" \ - node scripts/mocha diff --git a/.eslintrc.js b/.eslintrc.js index 82275d9441cc24..7dac66575c14e0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -542,7 +542,6 @@ module.exports = { 'packages/kbn-eslint-import-resolver-kibana/**/*.js', 'packages/kbn-eslint-plugin-eslint/**/*', 'x-pack/gulpfile.js', - 'x-pack/dev-tools/mocha/setup_mocha.js', 'x-pack/scripts/*.js', ], excludedFiles: ['**/integration_tests/**/*'], @@ -794,7 +793,6 @@ module.exports = { files: ['x-pack/plugins/security_solution/**/*.{js,mjs,ts,tsx}'], plugins: ['eslint-plugin-node', 'react'], env: { - mocha: true, jest: true, }, rules: { @@ -930,7 +928,6 @@ module.exports = { files: ['x-pack/plugins/lists/**/*.{js,mjs,ts,tsx}'], plugins: ['eslint-plugin-node'], env: { - mocha: true, jest: true, }, rules: { diff --git a/.teamcity/src/builds/test/QuickTests.kt b/.teamcity/src/builds/test/QuickTests.kt index a294fce9599c36..086f65e4ee26b8 100644 --- a/.teamcity/src/builds/test/QuickTests.kt +++ b/.teamcity/src/builds/test/QuickTests.kt @@ -14,7 +14,6 @@ object QuickTests : BuildType({ val testScripts = mapOf( "Test Hardening" to ".ci/teamcity/checks/test_hardening.sh", "Test Projects" to ".ci/teamcity/tests/test_projects.sh", - "Mocha Tests" to ".ci/teamcity/tests/mocha.sh" ) steps { diff --git a/docs/developer/contributing/development-tests.asciidoc b/docs/developer/contributing/development-tests.asciidoc index 647dc8b3f3b263..7aabc480cdaa29 100644 --- a/docs/developer/contributing/development-tests.asciidoc +++ b/docs/developer/contributing/development-tests.asciidoc @@ -17,10 +17,6 @@ root) |Jest (integration) |`**/integration_tests/**/*.test.{js,mjs,ts,tsx}` |`yarn test:jest_integration [test path]` -|Mocha -|`**/__tests__/**/*.js` -|`node scripts/mocha --grep=regexp [test path]` - |Functional |`test/**/config.js` `x-pack/test/**/config.js` |`node scripts/functional_tests_server --config [directory]/config.js``node scripts/functional_test_runner_ --config [directory]/config.js --grep=regexp` @@ -60,8 +56,6 @@ kibana/src/plugins/dashboard/server$ yarn test:jest --coverage yarn jest --coverage --verbose --config /home/tyler/elastic/kibana/src/plugins/dashboard/jest.config.js server ---- -NOTE: There are still a handful of legacy tests that use the Mocha test runner. For those tests, use `node scripts/mocha --grep=regexp [test path]`. Tests using Mocha are located within `__tests__` directories. - [discrete] === Running browser automation tests diff --git a/docs/developer/contributing/interpreting-ci-failures.asciidoc b/docs/developer/contributing/interpreting-ci-failures.asciidoc index bb623bc7a541ca..38609b2be5c8cd 100644 --- a/docs/developer/contributing/interpreting-ci-failures.asciidoc +++ b/docs/developer/contributing/interpreting-ci-failures.asciidoc @@ -27,7 +27,7 @@ image::images/job_view.png[] [discrete] === Viewing ciGroup/test Logs -To view the logs for a failed specific ciGroup, jest, mocha, type checkers, linters, etc., click on the *Pipeline Steps* link in from the Job page. +To view the logs for a failed specific ciGroup, jest, type checkers, linters, etc., click on the *Pipeline Steps* link in from the Job page. image::images/pipeline_steps_view.png[] diff --git a/package.json b/package.json index f8fe8d7c7bac41..70e39852e535f7 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "es": "node scripts/es", "test:jest": "node scripts/jest", "test:jest_integration": "node scripts/jest_integration", - "test:mocha": "node scripts/mocha", "test:ftr": "node scripts/functional_tests", "test:ftr:server": "node scripts/functional_tests_server", "test:ftr:runner": "node scripts/functional_test_runner", diff --git a/packages/README.md b/packages/README.md index 9d9cd4ed7b6e55..c7879ce718933a 100644 --- a/packages/README.md +++ b/packages/README.md @@ -44,23 +44,17 @@ All new packages should use the `@kbn` namespace, and should be marked with ## Unit tests for a package -Currently there are two patterns used to test packages, one using Mocha and one using Jest. These patterns emerged out of convention and we'd like to make them more similar to each other in the near future. +Currently there is only one tool being used in order to test packages which is Jest. Below we will explain how it should be done. -### 1. Mocha -Today a package can follow the pattern of having a `__tests__` directory in each source code directory of a package which contains the tests for that module. These are usually run by Mocha. - -If a package's tests should be run with Mocha, you'll have to opt-in to run them by appending the package's test file pattern(s) to Kibana's `src/dev/mocha/run_mocha_cli.js` file. These will then be run by the unit test runner. - -* `yarn test` or `yarn grunt test` runs all unit tests. -* `node scripts/mocha` runs all Mocha tests. - -### 2. Jest -A package can also follow the pattern of having `.test.js` files as siblings of the source code files, and these run by Jest. +### Jest +A package should follow the pattern of having `.test.js` files as siblings of the source code files, and these run by Jest. A package using the `.test.js` naming convention will have those tests automatically picked up by Jest and run by the unit test runner, currently mapped to the Kibana `test` script in the root `package.json`. * `yarn test` or `yarn grunt test` runs all unit tests. * `yarn jest` runs all Jest tests in Kibana. +In order to Jest found those tests a `jest.config.js` file should be created in the root of the package. + ---- Each package can also specify its own `test` script in the package's `package.json`, for cases where you'd prefer to run the tests from the local package directory. diff --git a/packages/kbn-plugin-generator/README.md b/packages/kbn-plugin-generator/README.md index bee8e6c2ca783b..4603c9ed7b1ba6 100644 --- a/packages/kbn-plugin-generator/README.md +++ b/packages/kbn-plugin-generator/README.md @@ -63,10 +63,6 @@ Generated plugins receive a handful of scripts that can be used during developme Build a distributable archive of your plugin. - - `yarn test:mocha` - - Run the server tests using mocha. - To start kibana run the following command from Kibana root. diff --git a/scripts/mocha.js b/scripts/mocha.js deleted file mode 100644 index 8d25d18a594ccf..00000000000000 --- a/scripts/mocha.js +++ /dev/null @@ -1,21 +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. - */ - -require('../src/setup_node_env'); -require('@kbn/test').runMochaCli(); diff --git a/test/scripts/jenkins_unit.sh b/test/scripts/jenkins_unit.sh index 2edd66579f72f4..a3e148f451b32e 100755 --- a/test/scripts/jenkins_unit.sh +++ b/test/scripts/jenkins_unit.sh @@ -15,7 +15,6 @@ if [[ -z "$CODE_COVERAGE" ]] ; then # Test ./test/scripts/test/jest_integration.sh - ./test/scripts/test/mocha.sh ./test/scripts/test/jest_unit.sh ./test/scripts/test/api_integration.sh diff --git a/test/scripts/test/mocha.sh b/test/scripts/test/mocha.sh deleted file mode 100755 index 5e005c89330ca7..00000000000000 --- a/test/scripts/test/mocha.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -source src/dev/ci_setup/setup_env.sh - -# TODO: will remove mocha in another PR -# checks-reporter-with-killswitch "Mocha Tests" \ -# node scripts/mocha diff --git a/test/tsconfig.json b/test/tsconfig.json index f9008505ed66e1..87f9928be71136 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -2,7 +2,7 @@ "extends": "../tsconfig.base.json", "compilerOptions": { "incremental": false, - "types": ["node", "mocha", "flot"] + "types": ["node", "flot"] }, "include": ["**/*", "../typings/elastic__node_crypto.d.ts", "typings/**/*", "../packages/kbn-test/types/ftr_globals/**/*"], "exclude": ["plugin_functional/plugins/**/*", "interpreter_functional/plugins/**/*"], diff --git a/vars/tasks.groovy b/vars/tasks.groovy index 18be6e69a2637d..e01fb4220b85df 100644 --- a/vars/tasks.groovy +++ b/vars/tasks.groovy @@ -32,7 +32,6 @@ def test() { tasks([ // These 2 tasks require isolation because of hard-coded, conflicting ports and such, so let's use Docker here kibanaPipeline.scriptTaskDocker('Jest Integration Tests', 'test/scripts/test/jest_integration.sh'), - kibanaPipeline.scriptTaskDocker('Mocha Tests', 'test/scripts/test/mocha.sh'), kibanaPipeline.scriptTask('Jest Unit Tests', 'test/scripts/test/jest_unit.sh'), kibanaPipeline.scriptTask('API Integration Tests', 'test/scripts/test/api_integration.sh'), diff --git a/x-pack/package.json b/x-pack/package.json index 34ef8bb589b44c..97fe5144f135a4 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -12,8 +12,7 @@ "build": "../node_modules/.bin/gulp build", "testonly": "echo 'Deprecated, use `yarn test`'", "test": "../node_modules/.bin/gulp test", - "test:jest": "node ../scripts/jest", - "test:mocha": "node scripts/mocha" + "test:jest": "node ../scripts/jest" }, "kibana": { "build": { diff --git a/x-pack/plugins/canvas/storybook/webpack.dll.config.js b/x-pack/plugins/canvas/storybook/webpack.dll.config.js index b830f72692eded..2fa31235ac0bb1 100644 --- a/x-pack/plugins/canvas/storybook/webpack.dll.config.js +++ b/x-pack/plugins/canvas/storybook/webpack.dll.config.js @@ -39,7 +39,6 @@ module.exports = { 'jquery', 'lodash', 'markdown-it', - 'mocha', 'monaco-editor', 'prop-types', 'react-ace', diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index 27c43abf1401e7..5ea0ab2bebdc09 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { // overhead is too significant "incremental": false, - "types": ["mocha", "node", "flot"] + "types": ["node", "flot"] }, "include": ["**/*", "../typings/**/*", "../../packages/kbn-test/types/ftr_globals/**/*"], "exclude": ["../typings/jest.d.ts"], From f32e8c35afc37ccfb2b49ea3a106ac39e854dbd0 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 13 Jan 2021 14:55:09 +0000 Subject: [PATCH 2/6] chore(NA): remove mocha script from xpack --- x-pack/scripts/mocha.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 x-pack/scripts/mocha.js diff --git a/x-pack/scripts/mocha.js b/x-pack/scripts/mocha.js deleted file mode 100644 index cc0f94a2a760e0..00000000000000 --- a/x-pack/scripts/mocha.js +++ /dev/null @@ -1,7 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -require('../../scripts/mocha'); From 9ac94f9d8cf8a56f3c3f0ed6a481183866b6cb33 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 13 Jan 2021 18:09:56 +0000 Subject: [PATCH 3/6] chore(NA): single rule exclusion on eslint config for mocha --- .eslintrc.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7dac66575c14e0..db5d36d1168dfd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -71,11 +71,6 @@ const SAFER_LODASH_SET_DEFINITELYTYPED_HEADER = ` */ `; -const allMochaRulesOff = {}; -Object.keys(require('eslint-plugin-mocha').rules).forEach((k) => { - allMochaRulesOff['mocha/' + k] = 'off'; -}); - module.exports = { root: true, @@ -573,7 +568,9 @@ module.exports = { */ { files: ['test/harden/*.js', 'packages/elastic-safer-lodash-set/test/*.js'], - rules: allMochaRulesOff, + rules: { + 'mocha/handle-done-callback': 'off', + }, }, { files: ['**/*.{js,mjs,ts,tsx}'], From c751481d5f16331835c9812669705fb02e8fd3bc Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 13 Jan 2021 18:33:42 +0000 Subject: [PATCH 4/6] chore(NA): remove unused custom mocha integration code from kbn/test --- packages/kbn-test/src/index.ts | 7 +- .../kbn-test/src/mocha/auto_junit_reporter.js | 37 ------- packages/kbn-test/src/mocha/index.ts | 4 - packages/kbn-test/src/mocha/run_mocha_cli.js | 99 ------------------- .../src/mocha/server_junit_reporter.js | 25 ----- src/dev/index.js | 2 +- 6 files changed, 2 insertions(+), 172 deletions(-) delete mode 100644 packages/kbn-test/src/mocha/auto_junit_reporter.js delete mode 100644 packages/kbn-test/src/mocha/run_mocha_cli.js delete mode 100644 packages/kbn-test/src/mocha/server_junit_reporter.js diff --git a/packages/kbn-test/src/index.ts b/packages/kbn-test/src/index.ts index a88820eb281ccf..fa7124a5b042d1 100644 --- a/packages/kbn-test/src/index.ts +++ b/packages/kbn-test/src/index.ts @@ -46,12 +46,7 @@ export { readConfigFile } from './functional_test_runner/lib/config/read_config_ export { runFtrCli } from './functional_test_runner/cli'; -export { - createAutoJUnitReporter, - runMochaCli, - setupJUnitReportGeneration, - escapeCdata, -} from './mocha'; +export { setupJUnitReportGeneration, escapeCdata } from './mocha'; export { runFailedTestsReporterCli } from './failed_tests_reporter'; diff --git a/packages/kbn-test/src/mocha/auto_junit_reporter.js b/packages/kbn-test/src/mocha/auto_junit_reporter.js deleted file mode 100644 index b6e79616e1cde0..00000000000000 --- a/packages/kbn-test/src/mocha/auto_junit_reporter.js +++ /dev/null @@ -1,37 +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. - */ - -import mocha from 'mocha'; -import { setupJUnitReportGeneration } from './junit_report_generation'; - -const MochaSpecReporter = mocha.reporters.spec; - -export function createAutoJUnitReporter(junitReportOptions) { - return class AutoJUnitReporter { - constructor(runner, options) { - // setup a spec reporter for console output - new MochaSpecReporter(runner, options); - - // in CI we also setup the JUnit reporter - if (process.env.CI && !process.env.DISABLE_JUNIT_REPORTER) { - setupJUnitReportGeneration(runner, junitReportOptions); - } - } - }; -} diff --git a/packages/kbn-test/src/mocha/index.ts b/packages/kbn-test/src/mocha/index.ts index 99c0f6f4230b7a..aadf1b7f16a19d 100644 --- a/packages/kbn-test/src/mocha/index.ts +++ b/packages/kbn-test/src/mocha/index.ts @@ -17,13 +17,9 @@ * under the License. */ -// @ts-ignore not typed yet -export { createAutoJUnitReporter } from './auto_junit_reporter'; // @ts-ignore not typed yet export { setupJUnitReportGeneration } from './junit_report_generation'; // @ts-ignore not typed yet -export { runMochaCli } from './run_mocha_cli'; -// @ts-ignore not typed yet export { recordLog, snapshotLogsForRunnable } from './log_cache'; // @ts-ignore not typed yet export { escapeCdata } from './xml'; diff --git a/packages/kbn-test/src/mocha/run_mocha_cli.js b/packages/kbn-test/src/mocha/run_mocha_cli.js deleted file mode 100644 index f61b3096103416..00000000000000 --- a/packages/kbn-test/src/mocha/run_mocha_cli.js +++ /dev/null @@ -1,99 +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. - */ - -import { REPO_ROOT } from '@kbn/utils'; -import getopts from 'getopts'; -import globby from 'globby'; - -export function runMochaCli() { - const opts = getopts(process.argv.slice(2), { - alias: { - t: 'timeout', - }, - boolean: ['no-timeouts'], - }); - - const runInBand = - process.execArgv.includes('--inspect') || process.execArgv.includes('--inspect-brk'); - - // ensure that mocha exits when test have completed - process.argv.push('--exit'); - - // check that we aren't leaking any globals - process.argv.push('--check-leaks'); - // prevent globals injected from canvas plugins from triggering leak check - process.argv.push('--globals', '__core-js_shared__,core,_, '); - - // set default test timeout - if (opts.timeout == null && !opts['no-timeouts']) { - if (runInBand) { - process.argv.push('--no-timeouts'); - } else { - process.argv.push('--timeout', '10000'); - } - } - - // set default slow timeout - if (opts.slow == null) { - process.argv.push('--slow', '5000'); - } - - // set default reporter - if (opts.reporter == null) { - process.argv.push('--reporter', require.resolve('./server_junit_reporter')); - } - - // set default test files - if (!opts._.length) { - globby - .sync( - [ - 'src/**/__tests__/**/*.{js,ts,tsx}', - 'packages/**/__tests__/**/*.{js,ts,tsx}', - 'tasks/**/__tests__/**/*.{js,ts,tsx}', - 'x-pack/common/**/__tests__/**/*.{js,ts,tsx}', - 'x-pack/server/**/__tests__/**/*.{js,ts,tsx}', - `x-pack/legacy/plugins/*/__tests__/**/*.{js,ts,tsx}`, - `x-pack/legacy/plugins/*/common/**/__tests__/**/*.{js,ts,tsx}`, - `x-pack/legacy/plugins/*/**/server/**/__tests__/**/*.{js,ts,tsx}`, - ], - { - cwd: REPO_ROOT, - onlyFiles: true, - absolute: true, - ignore: [ - '**/__tests__/fixtures/**', - 'src/**/public/**', - '**/_*.{js,ts,tsx}', - '**/*.test.*', - 'packages/**/target/**', - ], - } - ) - .forEach((file) => { - process.argv.push(file); - }); - } - - if (runInBand) { - require('mocha/bin/_mocha'); - } else { - require('mocha/bin/mocha'); - } -} diff --git a/packages/kbn-test/src/mocha/server_junit_reporter.js b/packages/kbn-test/src/mocha/server_junit_reporter.js deleted file mode 100644 index c629f401d05809..00000000000000 --- a/packages/kbn-test/src/mocha/server_junit_reporter.js +++ /dev/null @@ -1,25 +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. - */ - -// when the reporter is loaded by mocha in child process it might be before setup_node_env -require('../../../../src/setup_node_env'); - -module.exports = require('./auto_junit_reporter').createAutoJUnitReporter({ - reportName: 'Server Mocha Tests', -}); diff --git a/src/dev/index.js b/src/dev/index.js index f24eee040c8671..d9d0cec0f15737 100644 --- a/src/dev/index.js +++ b/src/dev/index.js @@ -17,6 +17,6 @@ * under the License. */ -export { createAutoJUnitReporter, setupJUnitReportGeneration } from '@kbn/test'; +export { setupJUnitReportGeneration } from '@kbn/test'; export { generateNoticeFromSource } from './notice'; From ecb96d7f80452f86ba63448c06db9e4be0172dc5 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Fri, 15 Jan 2021 00:08:15 +0000 Subject: [PATCH 5/6] chore(NA): rewording packages readme --- packages/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/README.md b/packages/README.md index c7879ce718933a..a328fe70e201fb 100644 --- a/packages/README.md +++ b/packages/README.md @@ -54,7 +54,7 @@ A package using the `.test.js` naming convention will have those tests automatic * `yarn test` or `yarn grunt test` runs all unit tests. * `yarn jest` runs all Jest tests in Kibana. -In order to Jest found those tests a `jest.config.js` file should be created in the root of the package. +In order for the plugin or package to use Jest, a jest.config.js file must be present in it's root. However, there are safeguards for this in CI should a test file be added without a corresponding config file. ---- Each package can also specify its own `test` script in the package's `package.json`, for cases where you'd prefer to run the tests from the local package directory. From 8cce3b49ca17783f9e71040f3ef104ff94edcb95 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Fri, 15 Jan 2021 00:18:11 +0000 Subject: [PATCH 6/6] docs(NA): remoe mocha mention from development-unit-tests --- .../development-unit-tests.asciidoc | 34 +++---------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/docs/developer/contributing/development-unit-tests.asciidoc b/docs/developer/contributing/development-unit-tests.asciidoc index d5f5bc76b3302f..72edaf1241bc67 100644 --- a/docs/developer/contributing/development-unit-tests.asciidoc +++ b/docs/developer/contributing/development-unit-tests.asciidoc @@ -1,20 +1,7 @@ [[development-unit-tests]] == Unit testing frameworks -{kib} is migrating unit testing from `Mocha` to `Jest`. Legacy unit tests -still exist in Mocha but all new unit tests should be written in Jest. - -[discrete] -=== Mocha (legacy) - -Mocha tests are contained in `__tests__` directories. - -*Running Mocha Unit Tests* - -["source","shell"] ------------ -yarn test:mocha ------------ +{kib} is doing unit testing doing `Jest`. [discrete] == Jest @@ -92,23 +79,10 @@ the `--debug-brk` flag. You’ll need to connect a remote debugger such as https://github.com/node-inspector/node-inspector[`node-inspector`] to proceed in this mode. -[source,bash] ----- -node scripts/mocha --debug ----- - [discrete] === Unit Testing Plugins -This should work super if you’re using the +Even when using https://github.com/elastic/kibana/tree/master/packages/kbn-plugin-generator[Kibana -plugin generator]. If you’re not using the generator, well, you’re on -your own. We suggest you look at how the generator works. - -To run the tests for just your particular plugin run the following -command from your plugin: - -[source,bash] ----- -yarn test:mocha ----- \ No newline at end of file +plugin generator] we do not enforce a way for unit testing your plugin. Please setup and you use +the tools of your choice. If the plugin will live inside the Kibana repo `Jest` must be used. \ No newline at end of file