From c92b887b8fa963ef34feb6b02eafb7b493513110 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Mon, 27 Jan 2020 09:11:57 -0600 Subject: [PATCH] Refactor test entry by runner Over the last few years we've increased the number of test runners. Entry points by test type have become too lage of a category for unique names, so this moves top level test scripts under yarn and replaces test types with the runner name. e.g. `yarn test:browser` -> `yarn test:karma` Closes #41133 --- CONTRIBUTING.md | 46 ++++++------------- package.json | 12 ++--- packages/kbn-plugin-generator/README.md | 2 +- .../integration_tests/generate_plugin.test.js | 8 ++-- .../sao_template/template/README.md | 2 +- .../template/package_template.json | 4 +- packages/kbn-plugin-helpers/README.md | 4 +- packages/kbn-plugin-helpers/cli.js | 12 ++--- packages/kbn-plugin-helpers/lib/index.d.ts | 2 +- packages/kbn-plugin-helpers/lib/tasks.js | 8 ++-- .../tasks/test/all/README.md | 4 +- .../tasks/test/all/test_all_action.js | 4 +- .../tasks/test/{browser => karma}/README.md | 8 ++-- .../tasks/test/{server => karma}/index.js | 2 +- .../test_karma_action.js} | 4 +- .../tasks/test/{server => mocha}/README.md | 6 +-- .../tasks/test/{browser => mocha}/index.js | 2 +- .../test_mocha_action.js} | 0 tasks/config/karma.js | 4 +- tasks/config/run.js | 22 ++++----- tasks/jenkins.js | 2 +- tasks/test.js | 12 ++--- test/scripts/jenkins_xpack.sh | 10 ++-- x-pack/README.md | 6 +-- x-pack/gulpfile.js | 6 +-- .../plugins/canvas/scripts/test_browser.js | 2 +- .../legacy/plugins/canvas/scripts/test_dev.js | 2 +- .../plugins/canvas/scripts/test_server.js | 2 +- x-pack/package.json | 4 +- x-pack/tasks/helpers/flags.ts | 2 +- x-pack/tasks/test.ts | 10 ++-- 31 files changed, 97 insertions(+), 117 deletions(-) rename packages/kbn-plugin-helpers/tasks/test/{browser => karma}/README.md (88%) rename packages/kbn-plugin-helpers/tasks/test/{server => karma}/index.js (94%) rename packages/kbn-plugin-helpers/tasks/test/{browser/test_browser_action.js => karma/test_karma_action.js} (91%) rename packages/kbn-plugin-helpers/tasks/test/{server => mocha}/README.md (85%) rename packages/kbn-plugin-helpers/tasks/test/{browser => mocha}/index.js (94%) rename packages/kbn-plugin-helpers/tasks/test/{server/test_server_action.js => mocha/test_mocha_action.js} (100%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 86be6e7e97155..6693f39ae3ef4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -193,7 +193,7 @@ yarn es snapshot ##### Keeping data between snapshots If you want to keep the data inside your Elasticsearch between usages of this command, -you should use the following command, to keep your data folder outside the downloaded snapshot +you should use the following command, to keep your data folder outside the downloaded snapshot folder: ```bash @@ -459,11 +459,11 @@ The following table outlines possible test file locations and how to invoke them | Test runner | Test location | Runner command (working directory is kibana root) | | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | -| Jest | `src/**/*.test.js`
`src/**/*.test.ts` | `node scripts/jest -t regexp [test path]` | -| Jest (integration) | `**/integration_tests/**/*.test.js` | `node scripts/jest_integration -t regexp [test path]` | +| Jest | `src/**/*.test.js`
`src/**/*.test.ts` | `yarn test:jest -t regexp [test path]` | +| Jest (integration) | `**/integration_tests/**/*.test.js` | `yarn test:jest_integration -t regexp [test path]` | | Mocha | `src/**/__tests__/**/*.js`
`!src/**/public/__tests__/*.js`
`packages/kbn-datemath/test/**/*.js`
`packages/kbn-dev-utils/src/**/__tests__/**/*.js`
`tasks/**/__tests__/**/*.js` | `node scripts/mocha --grep=regexp [test path]` | -| Functional | `test/*integration/**/config.js`
`test/*functional/**/config.js`
`test/accessibility/config.js` | `node scripts/functional_tests_server --config test/[directory]/config.js`
`node scripts/functional_test_runner --config test/[directory]/config.js --grep=regexp` | -| Karma | `src/**/public/__tests__/*.js` | `npm run test:dev` | +| Functional | `test/*integration/**/config.js`
`test/*functional/**/config.js`
`test/accessibility/config.js` | `yarn test:ftr:server --config test/[directory]/config.js`
`yarn test:ftr:runner --config test/[directory]/config.js --grep=regexp` | +| Karma | `src/**/public/__tests__/*.js` | `yarn test:karma:debug` | For X-Pack tests located in `x-pack/` see [X-Pack Testing](x-pack/README.md#testing) @@ -474,56 +474,38 @@ Test runner arguments: Examples: - Run the entire elasticsearch_service test suite: ``` - node scripts/jest src/core/server/elasticsearch/elasticsearch_service.test.ts + yarn test:jest src/core/server/elasticsearch/elasticsearch_service.test.ts ``` - Run the jest test case whose description matches `stops both admin and data clients`: ``` - node scripts/jest -t 'stops both admin and data clients' src/core/server/elasticsearch/elasticsearch_service.test.ts + yarn test:jest -t 'stops both admin and data clients' src/core/server/elasticsearch/elasticsearch_service.test.ts ``` - Run the api integration test case whose description matches the given string: ``` - node scripts/functional_tests_server --config test/api_integration/config.js - node scripts/functional_test_runner --config test/api_integration/config.js --grep='should return 404 if id does not match any sample data sets' + yarn test:ftr:server --config test/api_integration/config.js + yarn test:ftr:runner --config test/api_integration/config.js --grep='should return 404 if id does not match any sample data sets' ``` ### Debugging Unit Tests The standard `yarn test` task runs several sub tasks and can take several minutes to complete, making debugging failures pretty painful. In order to ease the pain specialized tasks provide alternate methods for running the tests. -To execute both server and browser tests, but skip linting, use `yarn test:quick`. - -```bash -yarn test:quick -``` - -Use `yarn test:mocha` when you want to run the mocha tests. - -```bash -yarn test:mocha -``` - -When you'd like to execute individual server-side test files, you can use the command below. Note that this command takes care of configuring Mocha with Babel compilation for you, and you'll be better off avoiding a globally installed `mocha` package. This command is great for development and for quickly identifying bugs. - -```bash -node scripts/mocha -``` - You could also add the `--debug` option so that `node` is run using the `--debug-brk` flag. You'll need to connect a remote debugger such as [`node-inspector`](https://github.com/node-inspector/node-inspector) to proceed in this mode. ```bash node scripts/mocha --debug ``` -With `yarn test:browser`, you can run only the browser tests. Coverage reports are available for browser tests by running `yarn test:coverage`. You can find the results under the `coverage/` directory that will be created upon completion. +With `yarn test:karma`, you can run only the browser tests. Coverage reports are available for browser tests by running `yarn test:coverage`. You can find the results under the `coverage/` directory that will be created upon completion. ```bash -yarn test:browser +yarn test:karma ``` -Using `yarn test:dev` initializes an environment for debugging the browser tests. Includes an dedicated instance of the kibana server for building the test bundle, and a karma server. When running this task the build is optimized for the first time and then a karma-owned instance of the browser is opened. Click the "debug" button to open a new tab that executes the unit tests. +Using `yarn test:karma:debug` initializes an environment for debugging the browser tests. Includes an dedicated instance of the kibana server for building the test bundle, and a karma server. When running this task the build is optimized for the first time and then a karma-owned instance of the browser is opened. Click the "debug" button to open a new tab that executes the unit tests. ```bash -yarn test:dev +yarn test:karma:debug ``` In the screenshot below, you'll notice the URL is `localhost:9876/debug.html`. You can append a `grep` query parameter to this URL and set it to a string value which will be used to exclude tests which don't match. For example, if you changed the URL to `localhost:9876/debug.html?query=my test` and then refreshed the browser, you'd only see tests run which contain "my test" in the test description. @@ -539,7 +521,7 @@ To run the tests for just your particular plugin run the following command from ```bash yarn test:mocha -yarn test:browser --dev # remove the --dev flag to run them once and close +yarn test:karma:debug # remove the debug flag to run them once and close ``` ### Cross-browser Compatibility diff --git a/package.json b/package.json index 9707d3863d295..81323c79f239a 100644 --- a/package.json +++ b/package.json @@ -40,15 +40,14 @@ "kbn": "node scripts/kbn", "es": "node scripts/es", "test": "grunt test", - "test:dev": "grunt test:dev", - "test:quick": "grunt test:quick", - "test:browser": "grunt test:browser", + "test:karma": "grunt test:karma", + "test:karma:debug": "grunt test:karmaDebug", "test:jest": "node scripts/jest", "test:mocha": "node scripts/mocha", "test:mocha:coverage": "grunt test:mochaCoverage", - "test:ui": "node scripts/functional_tests", - "test:ui:server": "node scripts/functional_tests_server", - "test:ui:runner": "node scripts/functional_test_runner", + "test:ftr": "node scripts/functional_tests", + "test:ftr:server": "node scripts/functional_tests_server", + "test:ftr:runner": "node scripts/functional_test_runner", "test:coverage": "grunt test:coverage", "typespec": "typings-tester --config x-pack/legacy/plugins/canvas/public/lib/aeroelastic/tsconfig.json x-pack/legacy/plugins/canvas/public/lib/aeroelastic/__fixtures__/typescript/typespec_tests.ts", "checkLicenses": "node scripts/check_licenses --dev", @@ -56,7 +55,6 @@ "start": "node --trace-warnings --throw-deprecation scripts/kibana --dev", "debug": "node --nolazy --inspect scripts/kibana --dev", "debug-break": "node --nolazy --inspect-brk scripts/kibana --dev", - "karma": "karma start", "lint": "yarn run lint:es && yarn run lint:sass", "lint:es": "node scripts/eslint", "lint:sass": "node scripts/sasslint", diff --git a/packages/kbn-plugin-generator/README.md b/packages/kbn-plugin-generator/README.md index 86871978aedeb..95de0e93fd075 100644 --- a/packages/kbn-plugin-generator/README.md +++ b/packages/kbn-plugin-generator/README.md @@ -71,7 +71,7 @@ Generated plugins receive a handful of scripts that can be used during developme Build a distributable archive of your plugin. - - `yarn test:browser` + - `yarn test:karma` Run the browser tests in a real web browser. diff --git a/packages/kbn-plugin-generator/integration_tests/generate_plugin.test.js b/packages/kbn-plugin-generator/integration_tests/generate_plugin.test.js index aa6611f3b6738..6fce379edfbe7 100644 --- a/packages/kbn-plugin-generator/integration_tests/generate_plugin.test.js +++ b/packages/kbn-plugin-generator/integration_tests/generate_plugin.test.js @@ -69,8 +69,8 @@ describe(`running the plugin-generator via 'node scripts/generate_plugin.js plug }); describe(`then running`, () => { - it(`'yarn test:browser' should exit 0`, async () => { - await execa('yarn', ['test:browser'], { + it(`'yarn test:karma' should exit 0`, async () => { + await execa('yarn', ['test:karma'], { cwd: generatedPath, env: { DISABLE_JUNIT_REPORTER: '1', @@ -78,8 +78,8 @@ describe(`running the plugin-generator via 'node scripts/generate_plugin.js plug }); }); - it(`'yarn test:server' should exit 0`, async () => { - await execa('yarn', ['test:server'], { + it(`'yarn test:mocha' should exit 0`, async () => { + await execa('yarn', ['test:mocha'], { cwd: generatedPath, env: { DISABLE_JUNIT_REPORTER: '1', diff --git a/packages/kbn-plugin-generator/sao_template/template/README.md b/packages/kbn-plugin-generator/sao_template/template/README.md index 59c3adf2713c8..454e4a5eb16b4 100755 --- a/packages/kbn-plugin-generator/sao_template/template/README.md +++ b/packages/kbn-plugin-generator/sao_template/template/README.md @@ -28,7 +28,7 @@ See the [kibana contributing guide](https://github.com/elastic/kibana/blob/maste Build a distributable archive of your plugin. - - `yarn test:browser` + - `yarn test:karma` Run the browser tests in a real web browser. diff --git a/packages/kbn-plugin-generator/sao_template/template/package_template.json b/packages/kbn-plugin-generator/sao_template/template/package_template.json index 4b6629fa90268..9f2bf9ee45307 100644 --- a/packages/kbn-plugin-generator/sao_template/template/package_template.json +++ b/packages/kbn-plugin-generator/sao_template/template/package_template.json @@ -13,8 +13,8 @@ "es": "node ../../scripts/es", "lint": "eslint .", "start": "plugin-helpers start", - "test:server": "plugin-helpers test:server", - "test:browser": "plugin-helpers test:browser", + "test:mocha": "plugin-helpers test:mocha", + "test:karma": "plugin-helpers test:karma", "build": "plugin-helpers build" }, <%_ if (generateTranslations) { _%> diff --git a/packages/kbn-plugin-helpers/README.md b/packages/kbn-plugin-helpers/README.md index b1fe525a9c116..4c648fd9bde8c 100644 --- a/packages/kbn-plugin-helpers/README.md +++ b/packages/kbn-plugin-helpers/README.md @@ -30,8 +30,8 @@ $ plugin-helpers help start Start kibana and have it include this plugin build [options] [files...] Build a distributable archive test Run the server and browser tests - test:browser [options] Run the browser tests in a real web browser - test:server [files...] Run the server tests using mocha + test:karma [options] Run the browser tests in a real web browser + test:mocha [files...] Run the server tests using mocha Options: diff --git a/packages/kbn-plugin-helpers/cli.js b/packages/kbn-plugin-helpers/cli.js index da146ae387945..c6fc48bc5be9a 100644 --- a/packages/kbn-plugin-helpers/cli.js +++ b/packages/kbn-plugin-helpers/cli.js @@ -66,24 +66,24 @@ program .action(createCommanderAction('testAll')); program - .command('test:browser') + .command('test:karma') .description('Run the browser tests in a real web browser') .option('--dev', 'Enable dev mode, keeps the test server running') .option('-p, --plugins ', "Manually specify which plugins' test bundles to run") - .on('--help', docs('test/browser')) + .on('--help', docs('test/karma')) .action( - createCommanderAction('testBrowser', command => ({ + createCommanderAction('testKarma', command => ({ dev: Boolean(command.dev), plugins: command.plugins, })) ); program - .command('test:server [files...]') + .command('test:mocha [files...]') .description('Run the server tests using mocha') - .on('--help', docs('test/server')) + .on('--help', docs('test/mocha')) .action( - createCommanderAction('testServer', (command, files) => ({ + createCommanderAction('testMocha', (command, files) => ({ files: files, })) ); diff --git a/packages/kbn-plugin-helpers/lib/index.d.ts b/packages/kbn-plugin-helpers/lib/index.d.ts index 1515bf6b84bfb..6f1eb73505b05 100644 --- a/packages/kbn-plugin-helpers/lib/index.d.ts +++ b/packages/kbn-plugin-helpers/lib/index.d.ts @@ -21,6 +21,6 @@ export function babelRegister(): void; export function resolveKibanaPath(path: string): string; export function readFtrConfigFile(path: string): any; export function run( - task: 'build' | 'start' | 'testAll' | 'testBrowser' | 'testServer' | 'postinstall', + task: 'build' | 'start' | 'testAll' | 'testKarma' | 'testMocha' | 'postinstall', options: any ): Promise; diff --git a/packages/kbn-plugin-helpers/lib/tasks.js b/packages/kbn-plugin-helpers/lib/tasks.js index 608a1617ffdb2..0e33e2086d9c4 100644 --- a/packages/kbn-plugin-helpers/lib/tasks.js +++ b/packages/kbn-plugin-helpers/lib/tasks.js @@ -20,15 +20,15 @@ const buildTask = require('../tasks/build'); const startTask = require('../tasks/start'); const testAllTask = require('../tasks/test/all'); -const testBrowserTask = require('../tasks/test/browser'); -const testServerTask = require('../tasks/test/server'); +const testKarmaTask = require('../tasks/test/karma'); +const testMochaTask = require('../tasks/test/mocha'); const postinstallTask = require('../tasks/postinstall'); module.exports = { build: buildTask, start: startTask, testAll: testAllTask, - testBrowser: testBrowserTask, - testServer: testServerTask, + testKarma: testKarmaTask, + testMocha: testMochaTask, postinstall: postinstallTask, }; diff --git a/packages/kbn-plugin-helpers/tasks/test/all/README.md b/packages/kbn-plugin-helpers/tasks/test/all/README.md index cf34b1dce2869..4f5a72ac0d523 100644 --- a/packages/kbn-plugin-helpers/tasks/test/all/README.md +++ b/packages/kbn-plugin-helpers/tasks/test/all/README.md @@ -1,3 +1,3 @@ -Runs both the server and browser tests, in that order. +Runs both the mocha and karma tests, in that order. -This is just a simple caller to both `test/server` and `test/browser` \ No newline at end of file +This is just a simple caller to both `test/mocha` and `test/karma` \ No newline at end of file diff --git a/packages/kbn-plugin-helpers/tasks/test/all/test_all_action.js b/packages/kbn-plugin-helpers/tasks/test/all/test_all_action.js index da0b46e47a3d3..f16e391b2b211 100644 --- a/packages/kbn-plugin-helpers/tasks/test/all/test_all_action.js +++ b/packages/kbn-plugin-helpers/tasks/test/all/test_all_action.js @@ -18,6 +18,6 @@ */ module.exports = function testAllAction(plugin, run) { - run('testServer'); - run('testBrowser'); + run('testMocha'); + run('testKarma'); }; diff --git a/packages/kbn-plugin-helpers/tasks/test/browser/README.md b/packages/kbn-plugin-helpers/tasks/test/karma/README.md similarity index 88% rename from packages/kbn-plugin-helpers/tasks/test/browser/README.md rename to packages/kbn-plugin-helpers/tasks/test/karma/README.md index 29e748396b6ec..8d921e8312344 100644 --- a/packages/kbn-plugin-helpers/tasks/test/browser/README.md +++ b/packages/kbn-plugin-helpers/tasks/test/karma/README.md @@ -21,12 +21,12 @@ Browser tests are written just like server tests, they are just executed differe starting the test runner ======================== -Under the covers this command uses the `test:browser` task from kibana. This will execute +Under the covers this command uses the `test:karma` task from kibana. This will execute your tasks once and exit when complete. -When run with the `--dev` option, the command uses the `test:dev` task from kibana. -This task sets-up a test runner that will watch your code for changes and rebuild your -tests when necessary. You access the test runner through a browser that it starts itself +When run with the `--dev` option, the command uses the `test:karma:debug` task from kibana. +This task sets-up a test runner that will watch your code for changes and rebuild your +tests when necessary. You access the test runner through a browser that it starts itself (via Karma). If your plugin consists of a number of internal plugins, you may wish to keep the tests diff --git a/packages/kbn-plugin-helpers/tasks/test/server/index.js b/packages/kbn-plugin-helpers/tasks/test/karma/index.js similarity index 94% rename from packages/kbn-plugin-helpers/tasks/test/server/index.js rename to packages/kbn-plugin-helpers/tasks/test/karma/index.js index b95d0321b04fe..0472207948c3d 100644 --- a/packages/kbn-plugin-helpers/tasks/test/server/index.js +++ b/packages/kbn-plugin-helpers/tasks/test/karma/index.js @@ -17,4 +17,4 @@ * under the License. */ -module.exports = require('./test_server_action'); +module.exports = require('./test_karma_action'); diff --git a/packages/kbn-plugin-helpers/tasks/test/browser/test_browser_action.js b/packages/kbn-plugin-helpers/tasks/test/karma/test_karma_action.js similarity index 91% rename from packages/kbn-plugin-helpers/tasks/test/browser/test_browser_action.js rename to packages/kbn-plugin-helpers/tasks/test/karma/test_karma_action.js index 2fa89f0d84349..e1ba8caee7f9a 100644 --- a/packages/kbn-plugin-helpers/tasks/test/browser/test_browser_action.js +++ b/packages/kbn-plugin-helpers/tasks/test/karma/test_karma_action.js @@ -20,7 +20,7 @@ const execFileSync = require('child_process').execFileSync; const winCmd = require('../../../lib/win_cmd'); -module.exports = function testBrowserAction(plugin, run, options) { +module.exports = function testKarmaAction(plugin, run, options) { options = options || {}; const kbnServerArgs = ['--kbnServer.plugin-path=' + plugin.root]; @@ -31,7 +31,7 @@ module.exports = function testBrowserAction(plugin, run, options) { kbnServerArgs.push('--kbnServer.tests_bundle.pluginId=' + plugin.id); } - const task = options.dev ? 'test:dev' : 'test:browser'; + const task = options.dev ? 'test:karma:debug' : 'test:karma'; const args = [task].concat(kbnServerArgs); execFileSync(winCmd('yarn'), args, { cwd: plugin.kibanaRoot, diff --git a/packages/kbn-plugin-helpers/tasks/test/server/README.md b/packages/kbn-plugin-helpers/tasks/test/mocha/README.md similarity index 85% rename from packages/kbn-plugin-helpers/tasks/test/server/README.md rename to packages/kbn-plugin-helpers/tasks/test/mocha/README.md index 4ceb855d165c5..6f5997a40a23b 100644 --- a/packages/kbn-plugin-helpers/tasks/test/server/README.md +++ b/packages/kbn-plugin-helpers/tasks/test/mocha/README.md @@ -20,14 +20,14 @@ Server tests are written just like browser tests, they are just executed differe running the tests ================= -Running the server tests is simple, just execute `yarn test:server` in your terminal +Running the server tests is simple, just execute `yarn test:mocha` in your terminal and all of the tests in your server will be run. By default, the runner will look for tests in `server/**/__tests__/**/*.js`. If you'd prefer to -use a different collection of globs and files, you can specify them after the `yarn test:server` +use a different collection of globs and files, you can specify them after the `yarn test:mocha` task, like so: -`yarn test:server 'plugins/myplugins/server/__tests__/**/*.js'` +`yarn test:mocha 'plugins/myplugins/server/__tests__/**/*.js'` NOTE: quoting the glob pattern is not required, but helps to avoid issues with globbing expansion in your shell. diff --git a/packages/kbn-plugin-helpers/tasks/test/browser/index.js b/packages/kbn-plugin-helpers/tasks/test/mocha/index.js similarity index 94% rename from packages/kbn-plugin-helpers/tasks/test/browser/index.js rename to packages/kbn-plugin-helpers/tasks/test/mocha/index.js index 972da4eca4518..1ab022db588f9 100644 --- a/packages/kbn-plugin-helpers/tasks/test/browser/index.js +++ b/packages/kbn-plugin-helpers/tasks/test/mocha/index.js @@ -17,4 +17,4 @@ * under the License. */ -module.exports = require('./test_browser_action'); +module.exports = require('./test_mocha_action'); diff --git a/packages/kbn-plugin-helpers/tasks/test/server/test_server_action.js b/packages/kbn-plugin-helpers/tasks/test/mocha/test_mocha_action.js similarity index 100% rename from packages/kbn-plugin-helpers/tasks/test/server/test_server_action.js rename to packages/kbn-plugin-helpers/tasks/test/mocha/test_mocha_action.js diff --git a/tasks/config/karma.js b/tasks/config/karma.js index ec37277cae0f8..9992dafed41c5 100644 --- a/tasks/config/karma.js +++ b/tasks/config/karma.js @@ -176,11 +176,11 @@ module.exports = function(grunt) { * (&shard_num=Y), are added to the testing bundle url and read by the * test_harness/setup_test_sharding[1] module. This allows us to use a * different number of shards in different scenarios (ie. running - * `yarn test:browser` runs the tests in a single shard, effectively + * `yarn test:karma` runs the tests in a single shard, effectively * disabling sharding) * * These same parameters can also be defined in the URL/query string of the - * karma debug page (started when you run `yarn test:dev`). + * karma debug page (started when you run `yarn test:karma:debug`). * * ## debugging * diff --git a/tasks/config/run.js b/tasks/config/run.js index 857895d75595c..fb0256f6c07e0 100644 --- a/tasks/config/run.js +++ b/tasks/config/run.js @@ -54,7 +54,7 @@ module.exports = function(grunt) { }; } - const browserTestServerFlags = [ + const karmaTestServerFlags = [ '--env.name=development', '--plugins.initialize=false', '--optimize.bundleFilter=tests', @@ -159,27 +159,27 @@ module.exports = function(grunt) { ], }), - // used by the test:browser task + // used by the test:karma task // runs the kibana server to serve the browser test bundle - browserTestServer: createKbnServerTask({ - flags: [...browserTestServerFlags], + karmaTestServer: createKbnServerTask({ + flags: [...karmaTestServerFlags], }), browserSCSS: createKbnServerTask({ - flags: [...browserTestServerFlags, '--optimize', '--optimize.enabled=false'], + flags: [...karmaTestServerFlags, '--optimize', '--optimize.enabled=false'], }), // used by the test:coverage task // runs the kibana server to serve the instrumented version of the browser test bundle - browserTestCoverageServer: createKbnServerTask({ - flags: [...browserTestServerFlags, '--tests_bundle.instrument=true'], + karmaTestCoverageServer: createKbnServerTask({ + flags: [...karmaTestServerFlags, '--tests_bundle.instrument=true'], }), - // used by the test:dev task + // used by the test:karma:debug task // runs the kibana server to serve the browser test bundle, but listens for changes // to the public/browser code and rebuilds the test bundle on changes - devBrowserTestServer: createKbnServerTask({ + karmaTestDebugServer: createKbnServerTask({ flags: [ - ...browserTestServerFlags, + ...karmaTestServerFlags, '--dev', '--no-dev-config', '--no-watch', @@ -293,7 +293,7 @@ module.exports = function(grunt) { 'test:jest_integration' ), test_projects: gruntTaskWithGithubChecks('Project tests', 'test:projects'), - test_browser_ci: gruntTaskWithGithubChecks('Browser tests', 'test:browser-ci'), + test_karma_ci: gruntTaskWithGithubChecks('Browser tests', 'test:karma-ci'), ...getFunctionalTestGroupRunConfigs({ kibanaInstallDir: KIBANA_INSTALL_DIR, diff --git a/tasks/jenkins.js b/tasks/jenkins.js index 8112b37b47224..d3a8404d7ff78 100644 --- a/tasks/jenkins.js +++ b/tasks/jenkins.js @@ -35,7 +35,7 @@ module.exports = function(grunt) { 'run:test_jest', 'run:test_jest_integration', 'run:test_projects', - 'run:test_browser_ci', + 'run:test_karma_ci', 'run:apiIntegrationTests', ]); }; diff --git a/tasks/test.js b/tasks/test.js index 73257b881c38d..c995502836378 100644 --- a/tasks/test.js +++ b/tasks/test.js @@ -31,21 +31,21 @@ module.exports = function(grunt) { } ); - grunt.registerTask('test:browser', [ + grunt.registerTask('test:karma', [ 'checkPlugins', 'run:browserSCSS', - 'run:browserTestServer', + 'run:karmaTestServer', 'karma:unit', ]); - grunt.registerTask('test:browser-ci', () => { + grunt.registerTask('test:karma-ci', () => { const ciShardTasks = keys(grunt.config.get('karma')) .filter(key => key.startsWith('ciShard-')) .map(key => `karma:${key}`); grunt.log.ok(`Running UI tests in ${ciShardTasks.length} shards`); grunt.task.run(['run:browserSCSS']); - grunt.task.run(['run:browserTestServer', ...ciShardTasks]); + grunt.task.run(['run:karmaTestServer', ...ciShardTasks]); }); grunt.registerTask('test:coverage', ['run:testCoverageServer', 'karma:coverage']); @@ -57,11 +57,11 @@ module.exports = function(grunt) { 'test:jest', 'test:jest_integration', 'test:projects', - 'test:browser', + 'test:karma', 'run:apiIntegrationTests', ]); - grunt.registerTask('test:dev', ['checkPlugins', 'run:devBrowserTestServer', 'karma:dev']); + grunt.registerTask('test:karmaDebug', ['checkPlugins', 'run:karmaDebugServer', 'karma:dev']); grunt.registerTask('test:mochaCoverage', ['run:mochaCoverage']); grunt.registerTask('test', subTask => { diff --git a/test/scripts/jenkins_xpack.sh b/test/scripts/jenkins_xpack.sh index e0055085d9b37..76f9aa04018d6 100755 --- a/test/scripts/jenkins_xpack.sh +++ b/test/scripts/jenkins_xpack.sh @@ -7,29 +7,29 @@ export TEST_BROWSER_HEADLESS=1 if [[ -z "$CODE_COVERAGE" ]] ; then echo " -> Running mocha tests" cd "$XPACK_DIR" - checks-reporter-with-killswitch "X-Pack Karma Tests" yarn test:browser + checks-reporter-with-killswitch "X-Pack Karma Tests" yarn test:karma echo "" echo "" - + echo " -> Running jest tests" cd "$XPACK_DIR" checks-reporter-with-killswitch "X-Pack Jest" node scripts/jest --ci --verbose echo "" echo "" - + echo " -> Running SIEM cyclic dependency test" cd "$XPACK_DIR" checks-reporter-with-killswitch "X-Pack SIEM cyclic dependency test" node legacy/plugins/siem/scripts/check_circular_deps echo "" echo "" - + # FAILING: https://github.com/elastic/kibana/issues/44250 # echo " -> Running jest contracts tests" # cd "$XPACK_DIR" # SLAPSHOT_ONLINE=true CONTRACT_ONLINE=true node scripts/jest_contract.js --ci --verbose # echo "" # echo "" - + # echo " -> Running jest integration tests" # cd "$XPACK_DIR" # node scripts/jest_integration --ci --verbose diff --git a/x-pack/README.md b/x-pack/README.md index e92d6849538bb..42e54aa2f50f9 100644 --- a/x-pack/README.md +++ b/x-pack/README.md @@ -46,17 +46,17 @@ yarn test --plugins [,]* # where is "reporting", etc #### Debugging browser tests ``` -yarn test:browser:dev +yarn test:karma:debug ``` Initializes an environment for debugging the browser tests. Includes an dedicated instance of the kibana server for building the test bundle, and a karma server. When running this task the build is optimized for the first time and then a karma-owned instance of the browser is opened. Click the "debug" button to open a new tab that executes the unit tests. Run single tests by appending `grep` parameter to the end of the URL. For example `http://localhost:9876/debug.html?grep=ML%20-%20Explorer%20Controller` will only run tests with 'ML - Explorer Controller' in the describe block. #### Running server unit tests -You can run server-side unit tests by running: +You can run mocha unit tests by running: ``` -yarn test:server +yarn test:mocha ``` #### Running functional tests diff --git a/x-pack/gulpfile.js b/x-pack/gulpfile.js index d3f93c29e3df8..0118d178f54e5 100644 --- a/x-pack/gulpfile.js +++ b/x-pack/gulpfile.js @@ -8,7 +8,7 @@ require('../src/setup_node_env'); const { buildTask } = require('./tasks/build'); const { devTask } = require('./tasks/dev'); -const { testTask, testBrowserTask, testBrowserDevTask } = require('./tasks/test'); +const { testTask, testKarmaTask, testKarmaDebugTask } = require('./tasks/test'); const { prepareTask } = require('./tasks/prepare'); // export the tasks that are runnable from the CLI @@ -17,6 +17,6 @@ module.exports = { dev: devTask, prepare: prepareTask, test: testTask, - testbrowser: testBrowserTask, - 'testbrowser-dev': testBrowserDevTask, + 'test:karma': testKarmaTask, + 'test:karma:debug': testKarmaDebugTask, }; diff --git a/x-pack/legacy/plugins/canvas/scripts/test_browser.js b/x-pack/legacy/plugins/canvas/scripts/test_browser.js index 971a04d9d97c2..e04fac0615284 100644 --- a/x-pack/legacy/plugins/canvas/scripts/test_browser.js +++ b/x-pack/legacy/plugins/canvas/scripts/test_browser.js @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -require('./_helpers').runGulpTask('canvas:test:browser'); +require('./_helpers').runGulpTask('canvas:test:karma'); diff --git a/x-pack/legacy/plugins/canvas/scripts/test_dev.js b/x-pack/legacy/plugins/canvas/scripts/test_dev.js index 656168b23af4b..8b03d7930d473 100644 --- a/x-pack/legacy/plugins/canvas/scripts/test_dev.js +++ b/x-pack/legacy/plugins/canvas/scripts/test_dev.js @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -require('./_helpers').runGulpTask('canvas:test:dev'); +require('./_helpers').runGulpTask('canvas:karma:debug'); diff --git a/x-pack/legacy/plugins/canvas/scripts/test_server.js b/x-pack/legacy/plugins/canvas/scripts/test_server.js index a05994c4d8606..4eb72b566f988 100644 --- a/x-pack/legacy/plugins/canvas/scripts/test_server.js +++ b/x-pack/legacy/plugins/canvas/scripts/test_server.js @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -require('./_helpers').runGulpTask('canvas:test:server'); +require('./_helpers').runGulpTask('canvas:test:mocha'); diff --git a/x-pack/package.json b/x-pack/package.json index ad0be351483f6..6718e43b2e497 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -11,8 +11,8 @@ "build": "gulp build", "testonly": "echo 'Deprecated, use `yarn test`' && gulp test", "test": "gulp test", - "test:browser:dev": "gulp testbrowser-dev", - "test:browser": "gulp testbrowser", + "test:karma:debug": "gulp test:karma:debug", + "test:karma": "gulp test:karma", "test:jest": "node scripts/jest", "test:mocha": "node scripts/mocha" }, diff --git a/x-pack/tasks/helpers/flags.ts b/x-pack/tasks/helpers/flags.ts index 62a382b02ed22..6c6cdf0d4abb0 100644 --- a/x-pack/tasks/helpers/flags.ts +++ b/x-pack/tasks/helpers/flags.ts @@ -19,7 +19,7 @@ import { findPluginSpecs } from '../../../src/legacy/plugin_discovery'; One of more plugins can be specified, and each one should be command separated, like so: gulp testserver --plugins monitoring,reporting If using with yarn: - yarn test:server --plugins graph + yarn test:mocha --plugins graph */ const opts = Object.freeze( diff --git a/x-pack/tasks/test.ts b/x-pack/tasks/test.ts index 0767d7479724a..78a04413daae7 100644 --- a/x-pack/tasks/test.ts +++ b/x-pack/tasks/test.ts @@ -13,19 +13,19 @@ export const testServerTask = async () => { throw new Error('server mocha tests are now included in the `node scripts/mocha` script'); }; -export const testBrowserTask = async () => { +export const testKarmaTask = async () => { const plugins = await getEnabledPlugins(); - await pluginHelpers.run('testBrowser', { + await pluginHelpers.run('testKarma', { plugins: plugins.join(','), }); }; -export const testBrowserDevTask = async () => { +export const testKarmaDebugTask = async () => { const plugins = await getEnabledPlugins(); - await pluginHelpers.run('testBrowser', { + await pluginHelpers.run('testKarma', { dev: true, plugins: plugins.join(','), }); }; -export const testTask = gulp.series(testBrowserTask, testServerTask); +export const testTask = gulp.series(testKarmaTask, testServerTask);