From 795b74a405db91f6b8019ad975b7c9e9842fcec2 Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Wed, 18 Aug 2021 14:57:14 -0700 Subject: [PATCH] [1.x][Docs] Added TESTING.md (#713) (#717) Adding TESTING.md to the project as referenced in the README. The content is some general information about testing and should not be considered exhaustive. Issue resolved: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/667 Backport PR: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/713 Signed-off-by: Kawika Avilla --- TESTING.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 TESTING.md diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 000000000000..94c715737239 --- /dev/null +++ b/TESTING.md @@ -0,0 +1,68 @@ +Below is a draft of the contents, what do y'all think: +--- +- [General information](#general-information) +- [Requirements](#requirements) +- [Running tests](#running-tests) + - [Unit tests](#unit-tests) + - [Integration tests](#integration-tests) + - [Functional tests](#functional-tests) +- [Continuous Integration](#continuous-integration) +- [Environment misc](#environment-misc) +- [Misc](#misc) + +# General information +OpenSearch Dashboards uses [Jest](https://jestjs.io/) for unit and integration tests and [Selenium](https://www.selenium.dev/) for functional tests. + +In general, we recommend three tiers of tests: +* Unit tests: Unit tests: small and modular tests that utilize mocks for external dependencies. +* Integration tests: higher-level tests that verify interactions between systems (eg. HTTP APIs, OpenSearch API calls, calling other plugin). +* End-to-end tests (e2e): functional tests that verify behavior in a web browser. + +# Requirements +* Install the latest NodeJS, [NPM](https://www.npmjs.com/get-npm) and [Yarn](https://classic.yarnpkg.com/en/docs/install/#mac-stable) + * `nvm install v10.24.1` + * `npm install -g yarn` + +# Running tests +The following is a cheatsheet of options for running the tests for OpenSearch Dashboards. + +### Unit tests +To run all the unit tests: +`yarn test:jest` +To run specific unit tests, pass the path to the test: +`yarn test:jest [test path]` + +### Integration tests +To run all the integration tests: +`yarn test:jest_integration` +To run specific integration tests, pass the path to the test: +`yarn test:jest_integration [test path]` + +### Functional tests +To run all functional tests: +`yarn test:ftr` +To run specific functional tests, you can run by CI group: +`node scripts/functional_tests.js --include ciGroup1` + +To debug functional tests: +Say that you would want to debug a test in CI group 1, you can run the following command in your environment: +`node --debug-brk --inspect scripts/functional_tests.js --config test/functional/config.js --include ciGroup1 --debug` + +This will print of an address, to which you could open your chrome browser on your instance and navigate to `chrome://inspect/#devices` and inspect the functional test runner `scripts/functional_tests.js`. + +# Continuous Integration +Automated testing is provided with Jenkins for Continuous Integration. Jenkins enables developers to build, deploy, and automate projects and provides us to run groups of tests quickly. CI groups are ran from the [Jenkinsfile](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/Jenkinsfile). + +# Environment misc +Selenium tests are run in headless mode on CI. Locally the same tests will be executed in a real browser. You can activate headless mode by setting the environment variable: +`export TEST_BROWSER_HEADLESS=1` + +By default the version of OpenSearch Dashboards will pull the snapshot of the same version of OpenSearch if available while running a few integration tests and for running functional tests. However, if the version of OpenSearch Dashboards is not available, you can build OpenSearch locally and point the functional test runner to the executable with: +`export TEST_OPENSEARCH_FROM=[local directory of OpenSearch executable]` + +# Misc +Although Jest is the standard for this project, there are a few Mocha tests that still exist. You can run these tests by running: +`yarn test:mocha` + +However, these tests will eventually be migrated. Please avoid writing new Mocha tests. For further questions or to check the status please see this [issue](https://github.com/opensearch-project/OpenSearch-Dashboards/issues/215). +