Testing

To ensure that your changes will not break other functionality, please run the test suite and build (Building a Kibana distributable) before submitting your Pull Request.

Running specific Kibana tests

The following table outlines possible test file locations and how to invoke them:

Test runnerTest locationRunner command (working directory is Kibana root)

Jest

src//*.test.js src//.test.ts

yarn test:jest -t regexp [test path]

Jest (integration)

/integration_tests//.test.js

yarn test:jestintegration -t regexp [test path]

Mocha

src//tests//.js !src/**/public/tests/.jspackages/kbn-datemath/test/**/*.js</code> <code>packages/kbn-dev-utils/src/**/__tests__/**/*.js</code> <code>tasks/**/__tests__/**/*.js</code></p></td><td valign="top"><p><code>node scripts/mocha --grep=regexp [test path]</code></p></td></tr><tr><td valign="top"><p>Functional</p></td><td valign="top"><p><code>test/*integration/**/config.js</code> <code>test/*functional/**/config.js</code> <code>test/accessibility/config.js</code></p></td><td valign="top"><p><code>yarn test:ftr:server --config test/[directory]/config.jsyarn 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

Test runner arguments: - Where applicable, the optional arguments -t=regexp or --grep=regexp will only run tests or test suites whose descriptions matches the regular expression. - [test path] is the relative path to the test file.

Examples: - Run the entire elasticsearch_service test suite: 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: 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: ``` yarn test:ftr:server –config test/api_integration/config.js yarn test:ftr:runner –config test/api_integration/config

Cross-browser compatibility

Testing IE on OS X

  • Download VMWare Fusion.
  • Download IE virtual machines for VMWare.
  • Open VMWare and go to Window > Virtual Machine Library. Unzip the virtual machine and drag the .vmx file into your Virtual Machine Library.
  • Right-click on the virtual machine you just added to your library and select “Snapshots…“, and then click the “Take“ button in the modal that opens. You can roll back to this snapshot when the VM expires in 90 days.
  • In System Preferences > Sharing, change your computer name to be something simple, e.g. “computer“.
  • Run Kibana with yarn start --host=computer.local (substituting your computer name).
  • Now you can run your VM, open the browser, and navigate to http://computer.local:5601 to test Kibana.
  • Alternatively you can use browserstack

Running browser automation tests

Check out Functional Testing to learn more about how you can run and develop functional tests for Kibana core and plugins.

You can also look into the Scripts README.md to learn more about using the node scripts we provide for building Kibana, running integration tests, and starting up Kibana and Elasticsearch while you develop.

More testing information:edit

Functional Testing

We use functional tests to make sure the Kibana UI works as expected. It replaces hours of manual testing by automating user interaction. To have better control over our functional test environment, and to make it more accessible to plugin authors, Kibana uses a tool called the FunctionalTestRunner.

Running functional testsedit

The FunctionalTestRunner is very bare bones and gets most of its functionality from its config file, located at {kib-repo}blob/7.9/test/functional/config.js[test/functional/config.js]. If you’re writing a plugin outside the Kibana repo, you will have your own config file. See Functional Tests for Plugins outside the Kibana repo for more info.

There are three ways to run the tests depending on your goals:

  1. Easiest option:

    • Description: Starts up Kibana & Elasticsearch servers, followed by running tests. This is much slower when running the tests multiple times because slow startup time for the servers. Recommended for single-runs.
    • node scripts/functional_tests

      • does everything in a single command, including running Elasticsearch and Kibana locally
      • tears down everything after the tests run
      • exit code reports success/failure of the tests
  1. Best for development:

    • Description: Two commands, run in separate terminals, separate the components that are long-running and slow from those that are ephemeral and fast. Tests can be re-run much faster, and this still runs Elasticsearch & Kibana locally.
    • node scripts/functional_tests_server

      • starts Elasticsearch and Kibana servers
      • slow to start
      • can be reused for multiple executions of the tests, thereby saving some time when re-running tests
      • automatically restarts the Kibana server when relevant changes are detected
    • node scripts/functional_test_runner

      • runs the tests against Kibana & Elasticsearch servers that were started by node scripts/functional_tests_server
      • exit code reports success or failure of the tests
  1. Custom option:

    • Description: Runs tests against instances of Elasticsearch & Kibana started some other way (like Elastic Cloud, or an instance you are managing in some other way).
    • just executes the functional tests
    • url, credentials, etc. for Elasticsearch and Kibana are specified via environment variables
    • Here’s an example that runs against an Elastic Cloud instance. Note that you must run the same branch of tests as the version of Kibana you’re testing.

      1. export TEST_KIBANA_URL=https://kibana:password@my-kibana-instance.internal.net:443
      2. export TEST_ES_URL=https://elastic:password@my-es-cluster.internal.net:9200
      3. node scripts/functional_test_runner
    • Or you can override any or all of these individual parts of the URL and leave the others to the default values.

      1. export TEST_KIBANA_PROTOCOL=https
      2. export TEST_KIBANA_HOSTNAME=my-kibana-instance.internal.net
      3. export TEST_KIBANA_PORT=443
      4. export TEST_KIBANA_USER=kibana
      5. export TEST_KIBANA_PASS=<password>
      6. export TEST_ES_PROTOCOL=http
      7. export TEST_ES_HOSTNAME=my-es-cluster.internal.net
      8. export TEST_ES_PORT=9200
      9. export TEST_ES_USER=elastic
      10. export TEST_ES_PASS=<password>
      11. node scripts/functional_test_runner
    • If you are running x-pack functional tests, start server and runner from {kib-repo}blob/7.9/xpack[x-pack] folder:

      1. node scripts/functional_tests_server.js
      2. node ../scripts/functional_test_runner.js
    • 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:

      1. export TEST_BROWSER_HEADLESS=1
    • If you are using Google Chrome, you can slow down the local network connection to verify test stability:

      1. export TEST_THROTTLE_NETWORK=1
    • When running against a Cloud deployment, some tests are not applicable. To skip tests that do not apply, use —exclude-tag. An example shell file can be found at: {kib-repo}blob/7.9/test/scripts/jenkins_cloud.sh[test/scripts/jenkins_cloud.sh]

      1. node scripts/functional_test_runner --exclude-tag skipCloud
More about node scripts/functional_test_runneredit

When run without any arguments the FunctionalTestRunner automatically loads the configuration in the standard location, but you can override that behavior with the --config flag. List configs with multiple —config arguments.

  • --config test/functional/config.js starts Elasticsearch and Kibana servers with the WebDriver tests configured to run in Chrome.
  • --config test/functional/config.firefox.js starts Elasticsearch and Kibana servers with the WebDriver tests configured to run in Firefox.
  • --config test/api_integration/config.js starts Elasticsearch and Kibana servers with the api integration tests configuration.
  • --config test/accessibility/config.ts starts Elasticsearch and Kibana servers with the WebDriver tests configured to run an accessibility audit using axe.

There are also command line flags for --bail and --grep, which behave just like their mocha counterparts. For instance, use --grep=foo to run only tests that match a regular expression.

Logging can also be customized with --quiet, --debug, or --verbose flags.

Use the --help flag for more options.

Writing functional testsedit
Environmentedit

The tests are written in mocha using @kbn/expect for assertions.

We use WebDriver Protocol to run tests in both Chrome and Firefox with the help of chromedriver and geckodriver. When the FunctionalTestRunner launches, remote service creates a new webdriver session, which starts the driver and a stripped-down browser instance. We use browser service and webElementWrapper class to wrap up Webdriver API.

The FunctionalTestRunner automatically transpiles functional tests using babel, so that tests can use the same ECMAScript features that Kibana source code uses. See {kib-repo}blob/7.9/style_guides/js_style_guide.md[style_guides/js_style_guide.md].

Definitionsedit

Provider:

Code run by the FunctionalTestRunner is wrapped in a function so it can be passed around via config files and be parameterized. Any of these Provider functions may be asynchronous and should return/resolve-to the value they are meant to provide. Provider functions will always be called with a single argument: a provider API (see the Provider API Section).

A config provider:

  1. // config and test files use `export default`
  2. export default function (/* { providerAPI } */) {
  3. return {
  4. // ...
  5. }
  6. }

Services

Services are named singleton values produced by a Service Provider. Tests and other services can retrieve service instances by asking for them by name. All functionality except the mocha API is exposed via services.\

Page objects

Page objects are a special type of service that encapsulate behaviors common to a particular page or plugin. When you write your own plugin, you’ll likely want to add a page object (or several) that describes the common interactions your tests need to execute.

Test Files

The FunctionalTestRunner‘s primary purpose is to execute test files. These files export a Test Provider that is called with a Provider API but is not expected to return a value. Instead Test Providers define a suite using mocha’s BDD interface.

Test Suite

A test suite is a collection of tests defined by calling describe(), and then populated with tests and setup/teardown hooks by calling it(), before(), beforeEach(), etc. Every test file must define only one top level test suite, and test suites can have as many nested test suites as they like.

Tags

Use tags in describe() function to group functional tests. Tags include:

  • ciGroup{id} - Assigns test suite to a specific CI worker
  • skipCloud and skipFirefox - Excludes test suite from running on Cloud or Firefox
  • includeFirefox - Groups tests that run on Chrome and Firefox

Cross-browser testing

On CI, all the functional tests are executed in Chrome by default. To also run a suite against Firefox, assign the includeFirefox tag:

  1. // on CI test suite will be run twice: in Chrome and Firefox
  2. describe('My Cross-browser Test Suite', function () {
  3. this.tags('includeFirefox');
  4. it('My First Test');
  5. }

If the tests do not apply to Firefox, assign the skipFirefox tag.

To run tests on Firefox locally, use config.firefox.js:

  1. node scripts/functional_test_runner --config test/functional/config.firefox.js
Using the test_user serviceedit

Tests should run at the positive security boundry condition, meaning that they should be run with the mimimum privileges required (and documented) and not as the superuser. This prevents the type of regression where additional privleges accidentally become required to perform the same action.

The functional UI tests now default to logging in with a user named test_user and the roles of this user can be changed dynamically without logging in and out.

In order to achieve this a new service was introduced called createTestUserService (see test/common/services/security/test_user.ts). The purpose of this test user service is to create roles defined in the test config files and setRoles() or restoreDefaults().

An example of how to set the role like how its defined below:

await security.testUser.setRoles(['kibana_user', 'kibana_date_nanos']);

Here we are setting the test_user to have the kibana_user role and also role access to a specific data index (kibana_date_nanos).

Tests should normally setRoles() in the before() and restoreDefaults() in the after().

Anatomy of a test fileedit

This annotated example file shows the basic structure every test suite uses. It starts by importing @kbn/expect and defining its default export: an anonymous Test Provider. The test provider then destructures the Provider API for the getService() and getPageObjects() functions. It uses these functions to collect the dependencies of this suite. The rest of the test file will look pretty normal to mocha.js users. describe(), it(), before() and the lot are used to define suites that happen to automate a browser via services and objects of type PageObject.

  1. import expect from '@kbn/expect';
  2. // test files must `export default` a function that defines a test suite
  3. export default function ({ getService, getPageObject }) {
  4. // most test files will start off by loading some services
  5. const retry = getService('retry');
  6. const testSubjects = getService('testSubjects');
  7. const esArchiver = getService('esArchiver');
  8. // for historical reasons, PageObjects are loaded in a single API call
  9. // and returned on an object with a key/value for each requested PageObject
  10. const PageObjects = getPageObjects(['common', 'visualize']);
  11. // every file must define a top-level suite before defining hooks/tests
  12. describe('My Test Suite', () => {
  13. // most suites start with a before hook that navigates to a specific
  14. // app/page and restores some archives into {es} with esArchiver
  15. before(async () => {
  16. await Promise.all([
  17. // start with an empty .kibana index
  18. esArchiver.load('empty_kibana'),
  19. // load some basic log data only if the index doesn't exist
  20. esArchiver.loadIfNeeded('makelogs')
  21. ]);
  22. // go to the page described by `apps.visualize` in the config
  23. await PageObjects.common.navigateTo('visualize');
  24. });
  25. // right after the before() hook definition, add the teardown steps
  26. // that will tidy up {es} for other test suites
  27. after(async () => {
  28. // we unload the empty_kibana archive but not the makelogs
  29. // archive because we don't make any changes to it, and subsequent
  30. // suites could use it if they call `.loadIfNeeded()`.
  31. await esArchiver.unload('empty_kibana');
  32. });
  33. // This series of tests illustrate how tests generally verify
  34. // one step of a larger process and then move on to the next in
  35. // a new test, each step building on top of the previous
  36. it('Vis Listing Page is empty');
  37. it('Create a new vis');
  38. it('Shows new vis in listing page');
  39. it('Opens the saved vis');
  40. it('Respects time filter changes');
  41. it(...
  42. });
  43. }
Provider APIedit

The first and only argument to all providers is a Provider API Object. This object can be used to load service/page objects and config/test files.

Within config files the API has the following properties

log

An instance of the {kib-repo}blob/7.9/packages/kbn-dev-utils/src/tooling_log/tooling_log.js[ToolingLog] that is ready for use

readConfigFile(path)

Returns a promise that will resolve to a Config instance that provides the values from the config file at path

Within service and PageObject Providers the API is:

getService(name)

Load and return the singleton instance of a service by name

getPageObjects(names)

Load the singleton instances of PageObjects and collect them on an object where each name is the key to the singleton instance of that PageObject

Within a test Provider the API is exactly the same as the service providers API but with an additional method:

loadTestFile(path)

Load the test file at path in place. Use this method to nest suites from other files into a higher-level suite

Service Indexedit
Built-in Servicesedit

The FunctionalTestRunner comes with three built-in services:

config:

  • Source: {kib-repo}blob/7.9/src/functional_test_runner/lib/config/config.ts[src/functional_test_runner/lib/config/config.ts]
  • Schema: {kib-repo}blob/7.9/src/functional_test_runner/lib/config/schema.ts[src/functional_test_runner/lib/config/schema.ts]
  • Use config.get(path) to read any value from the config file

log:

  • Source: {kib-repo}blob/7.9/packages/kbn-dev-utils/src/tooling_log/tooling_log.js[packages/kbn-dev-utils/src/tooling_log/tooling_log.js]
  • ToolingLog instances are readable streams. The instance provided by this service is automatically piped to stdout by the FunctionalTestRunner CLI
  • log.verbose(), log.debug(), log.info(), log.warning() all work just like console.log but produce more organized output

lifecycle:

  • Source: {kib-repo}blob/7.9/src/functional_test_runner/lib/lifecycle.ts[src/functional_test_runner/lib/lifecycle.ts]
  • Designed primary for use in services
  • Exposes lifecycle events for basic coordination. Handlers can return a promise and resolve/fail asynchronously
  • Phases include: beforeLoadTests, beforeTests, beforeEachTest, cleanup
Kibana Servicesedit

The Kibana functional tests define the vast majority of the actual functionality used by tests.

browser

  • Source: {kib-repo}blob/7.9/test/functional/services/browser.ts[test/functional/services/browser.ts]
  • Higher level wrapper for remote service, which exposes available browser actions
  • Popular methods:

    • browser.getWindowSize()
    • browser.refresh()

testSubjects:

  • Source: {kib-repo}blob/7.9/test/functional/services/test_subjects.ts[test/functional/services/test_subjects.ts]
  • Test subjects are elements that are tagged specifically for selecting from tests
  • Use testSubjects over CSS selectors when possible
  • Usage:

    • Tag your test subject with a data-test-subj attribute:

      1. <div id="container”>
      2. <button id="clickMe” data-test-subj=”containerButton” />
      3. </div>
    • Click this button using the testSubjects helper:

      1. await testSubjects.click(‘containerButton’);
  • Popular methods:

    • testSubjects.find(testSubjectSelector) - Find a test subject in the page; throw if it can’t be found after some time
    • testSubjects.click(testSubjectSelector) - Click a test subject in the page; throw if it can’t be found after some time

find:

  • Source: {kib-repo}blob/7.9/test/functional/services/find.ts[test/functional/services/find.ts]
  • Helpers for remote.findBy* methods that log and manage timeouts
  • Popular methods:

    • find.byCssSelector()
    • find.allByCssSelector()

retry:

  • Source: {kib-repo}blob/7.9/test/common/services/retry/retry.ts[test/common/services/retry/retry.ts]
  • Helpers for retrying operations
  • Popular methods:

    • retry.try(fn, onFailureBlock) - Execute fn in a loop until it succeeds or the default timeout elapses. The optional onFailureBlock is executed before each retry attempt.
    • retry.tryForTime(ms, fn, onFailureBlock) - Execute fn in a loop until it succeeds or ms milliseconds elapses. The optional onFailureBlock is executed before each retry attempt.

kibanaServer:

  • Source: {kib-repo}blob/7.9/test/common/services/kibana_server/kibana_server.js[test/common/services/kibana_server/kibana_server.js]
  • Helpers for interacting with Kibana’s server
  • Commonly used methods:

    • kibanaServer.uiSettings.update()
    • kibanaServer.version.get()
    • kibanaServer.status.getOverallState()

esArchiver:

  • Source: {kib-repo}blob/7.9/test/common/services/es_archiver.ts[test/common/services/es_archiver.ts]
  • Load/unload archives created with the esArchiver
  • Popular methods:

    • esArchiver.load(name)
    • esArchiver.loadIfNeeded(name)
    • esArchiver.unload(name)

Full list of services that are used in functional tests can be found here: {kib-repo}blob/7.9/test/functional/services[test/functional/services]

Low-level utilities:

  • es

    • Source: {kib-repo}blob/7.9/test/common/services/es.ts[test/common/services/es.ts]
    • Elasticsearch client
    • Higher level options: kibanaServer.uiSettings or esArchiver
  • remote

    • Source: {kib-repo}blob/7.9/test/functional/services/remote/remote.ts[test/functional/services/remote/remote.ts]
    • Instance of WebDriver class
    • Responsible for all communication with the browser
    • To perform browser actions, use remote service
    • For searching and manipulating with DOM elements, use testSubjects and find services
    • See the selenium-webdriver docs for the full API.
Custom Servicesedit

Services are intentionally generic. They can be literally anything (even nothing). Some services have helpers for interacting with a specific types of UI elements, like pointSeriesVis, and others are more foundational, like log or config. Whenever you want to provide some functionality in a reusable package, consider making a custom service.

To create a custom service somethingUseful:

  • Create a test/functional/services/something_useful.js file that looks like this:

    1. // Services are defined by Provider functions that receive the ServiceProviderAPI
    2. export function SomethingUsefulProvider({ getService }) {
    3. const log = getService('log');
    4. class SomethingUseful {
    5. doSomething() {
    6. }
    7. }
    8. return new SomethingUseful();
    9. }
  • Re-export your provider from services/index.js

  • Import it into src/functional/config.js and add it to the services config:

    1. import { SomethingUsefulProvider } from './services';
    2. export default function () {
    3. return {
    4. // … truncated ...
    5. services: {
    6. somethingUseful: SomethingUsefulProvider
    7. }
    8. }
    9. }
PageObjectsedit

The purpose for each PageObject is pretty self-explanatory. The visualize PageObject provides helpers for interacting with the visualize app, dashboard is the same for the dashboard app, and so on.

One exception is the “common” PageObject. A holdover from the intern implementation, the common PageObject is a collection of helpers useful across pages. Now that we have shareable services, and those services can be shared with other FunctionalTestRunner configurations, we will continue to move functionality out of the common PageObject and into services.

Please add new methods to existing or new services rather than further expanding the CommonPage class.

Gotchasedit

Remember that you can’t run an individual test in the file (it block) because the whole describe needs to be run in order. There should only be one top level describe in a file.

Functional Test Timingedit

Another important gotcha is writing stable tests by being mindful of timing. All methods on remote run asynchronously. It’s better to write interactions that wait for changes on the UI to appear before moving onto the next step.

For example, rather than writing an interaction that simply clicks a button, write an interaction with the a higher-level purpose in mind:

Bad example: PageObjects.app.clickButton()

  1. class AppPage {
  2. // what can people who call this method expect from the
  3. // UI after the promise resolves? Since the reaction to most
  4. // clicks is asynchronous the behavior is dependant on timing
  5. // and likely to cause test that fail unexpectedly
  6. async clickButton () {
  7. await testSubjects.click(‘menuButton’);
  8. }
  9. }

Good example: PageObjects.app.openMenu()

  1. class AppPage {
  2. // unlike `clickButton()`, callers of `openMenu()` know
  3. // the state that the UI will be in before they move on to
  4. // the next step
  5. async openMenu () {
  6. await testSubjects.click(‘menuButton’);
  7. await testSubjects.exists(‘menu’);
  8. }
  9. }

Writing in this way will ensure your test timings are not flaky or based on assumptions about UI updates after interactions.

Debuggingedit

From the command line run:

  1. node --debug-brk --inspect scripts/functional_test_runner

This prints out a URL that you can visit in Chrome and debug your functional tests in the browser.

You can also see additional logs in the terminal by running the FunctionalTestRunner with the --debug or --verbose flag. Add more logs with statements in your tests like

  1. // load the log service
  2. const log = getService(‘log’);
  3. // log.debug only writes when using the `--debug` or `--verbose` flag.
  4. log.debug(‘done clicking menu’);
MacOS testing performance tipedit

macOS users on a machine with a discrete graphics card may see significant speedups (up to 2x) when running tests by changing your terminal emulator’s GPU settings. In iTerm2: * Open Preferences (Command + ,) * In the General tab, under the “Magic” section, ensure “GPU rendering” is checked * Open “Advanced GPU Settings…​” * Uncheck the “Prefer integrated to discrete GPU” option * Restart iTerm

Unit testing frameworks

Kibana 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.

Mocha (legacy)edit

Mocha tests are contained in __tests__ directories.

Running Mocha Unit Tests

  1. yarn test:mocha

Jest

Jest tests are stored in the same directory as source code files with the .test.{js,mjs,ts,tsx} suffix.

Running Jest Unit Tests

  1. yarn test:jest
Writing Jest Unit Testsedit

In order to write those tests there are two main things you need to be aware of. The first one is the different between jest.mock and jest.doMock and the second one our jest mocks file pattern. As we are running js and ts test files with babel-jest both techniques are needed specially for the tests implemented on Typescript in order to benefit from the auto-inference types feature.

Jest.mock vs Jest.doMockedit

Both methods are essentially the same on their roots however the jest.mock calls will get hoisted to the top of the file and can only reference variables prefixed with mock. On the other hand, jest.doMock won’t be hoisted and can reference pretty much any variable we want, however we have to assure those referenced variables are instantiated at the time we need them which lead us to the next section where we’ll talk about our jest mock files pattern.

Jest Mock Files Patternedit

Specially on typescript it is pretty common to have in unit tests jest.doMock calls which reference for example imported types. Any error will thrown from doing that however the test will fail. The reason behind that is because despite the jest.doMock isn’t being hoisted by babel-jest the import with the types we are referencing will be hoisted to the top and at the time we’ll call the function that variable would not be defined.

In order to prevent that we develop a protocol that should be followed:

  • Each module could provide a standard mock in mymodule.mock.ts in case there are other tests that could benefit from using definitions here. This file would not have any jest.mock calls, just dummy objects.
  • Each test defines its mocks in mymodule.test.mocks.ts. This file could import relevant mocks from the generalised module’s mocks file (*.mock.ts) and call jest.mock for each of them. If there is any relevant dummy mock objects to generalise (and to be used by other tests), the dummy objects could be defined directly on this file.
  • Each test would import its mocks from the test mocks file mymodule.test.mocks.ts. mymodule.test.ts has an import like: import * as Mocks from './mymodule.test.mocks', import { mockX } from './mymodule.test.mocks' or just import './mymodule.test.mocks' if there isn’t anything exported to be used.
Debugging Unit Testsedit

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.

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 to proceed in this mode.

  1. node scripts/mocha --debug <file>

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.

  1. yarn test:karma

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.

  1. 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.

Browser test debugging

Unit Testing Pluginsedit

This should work super if you’re using the 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:

  1. yarn test:mocha
  2. yarn test:karma:debug # remove the debug flag to run them once and close

Automated Accessibility Testing

To run the tests locally:

  1. In one terminal window run node scripts/functional_tests_server --config test/accessibility/config.ts
  2. In another terminal window run node scripts/functional_test_runner.js --config test/accessibility/config.ts

To run the x-pack tests, swap the config file out for x-pack/test/accessibility/config.ts.

After the server is up, you can go to this instance of Kibana at localhost:5620.

The testing is done using axe. The same thing that runs in CI, can be run locally using their browser plugins:

Most Popular