Skip to content

Commit

Permalink
chore(NA): remove mocha junit ci integrations (elastic#88129)
Browse files Browse the repository at this point in the history
* chore(NA): remove mocha junit ci integrations

* chore(NA): remove mocha script from xpack

* chore(NA): single rule exclusion on eslint config for mocha

* chore(NA): remove unused custom mocha integration code from kbn/test

* chore(NA): rewording packages readme

* docs(NA): remoe mocha mention from development-unit-tests
# Conflicts:
#	docs/developer/contributing/development-unit-tests.asciidoc
#	test/scripts/jenkins_unit.sh
  • Loading branch information
mistic committed Jan 15, 2021
1 parent 5bc517c commit 14cf991
Show file tree
Hide file tree
Showing 25 changed files with 27 additions and 307 deletions.
29 changes: 8 additions & 21 deletions .ci/Jenkinsfile_flaky
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))()
}
Expand All @@ -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')
Expand Down
8 changes: 0 additions & 8 deletions .ci/teamcity/tests/mocha.sh

This file was deleted.

12 changes: 3 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -546,7 +541,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/**/*'],
Expand Down Expand Up @@ -578,7 +572,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}'],
Expand Down Expand Up @@ -798,7 +794,6 @@ module.exports = {
files: ['x-pack/plugins/security_solution/**/*.{js,mjs,ts,tsx}'],
plugins: ['eslint-plugin-node', 'react'],
env: {
mocha: true,
jest: true,
},
rules: {
Expand Down Expand Up @@ -934,7 +929,6 @@ module.exports = {
files: ['x-pack/plugins/lists/**/*.{js,mjs,ts,tsx}'],
plugins: ['eslint-plugin-node'],
env: {
mocha: true,
jest: true,
},
rules: {
Expand Down
1 change: 0 additions & 1 deletion .teamcity/src/builds/test/QuickTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions docs/developer/contributing/development-tests.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
34 changes: 4 additions & 30 deletions docs/developer/contributing/development-unit-tests.asciidoc
Original file line number Diff line number Diff line change
@@ -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 using `Jest`.

[discrete]
== Jest
Expand Down Expand Up @@ -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 <file>
----

[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
----
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.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ image::images/jenkins/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/jenkins/pipeline_steps_view.png[]

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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",
Expand Down
16 changes: 5 additions & 11 deletions packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.
4 changes: 0 additions & 4 deletions packages/kbn-plugin-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
7 changes: 1 addition & 6 deletions packages/kbn-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
37 changes: 0 additions & 37 deletions packages/kbn-test/src/mocha/auto_junit_reporter.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/kbn-test/src/mocha/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Loading

0 comments on commit 14cf991

Please sign in to comment.