How can i test my custom Kibana Plugin?

I have generated Kibana plugin using Yo. It consists of test file inside server/test. I have looked in test cases in kibana-dev\test\functional\apps\visualize for different visualizations too.
In kibana dev, it seems it requires Services and page objects to test the plugin. Here are my few doubts:

  1. npm run test:server is not executing any test inside export default function ({ getService, getPageObjects }) {}

     import { expect } from 'chai';
     describe('simple test', function simpleTest() {
     		it('must be true', function() {
     			expect(1).to.equal(1);
     		});
     });
     export default function ({ getService, getPageObjects }) {
     	const log = getService('log');
     	const retry = getService('retry');
     	const remote = getService('remote');
     	const config = getService('config');
     	const testSubjects = getService('testSubjects');
     	const defaultFindTimeout = config.get('timeouts.find');
     	const PageObjects = getPageObjects(['common', 'visualize', 'header']);
     	
     	describe('simple test', function simpleTest() {
     		it('must be false', function() {
     			expect(1).to.equal(2);
     		});
     	});
     	describe('visualize app', function describeIndexTests() {
     		const fromTime = '2015-09-19 06:31:44.000';
     		const toTime = '2015-09-23 18:31:44.000';		
     	});
     }
    
  2. If i have to write test cases according to kibana-dev\test\functional\apps\visualize tests, should i add methods like clickCircle(), getCircle() inside page_objects\visualize_page.js for my plugin or such methods can be implemented in my test file itself?

    clickCircle() {
        return remote
       .setFindTimeout(defaultFindTimeout)
       .findByPartialLinkText('Circle')
       .click();
    }
    
  3. How can i see test coverage for my custom plugin?

First, the yo generator is deprecated. If you want to create a plugin, use the template-kibana-plugin instead. The yo generator is no longer actively maintained.

Second, I'm not sure what you're trying to accomplish in your first code snippet. This looks like you've added code to the server/tests/index.js file, but I am not sure why there are tests within export default function. The way that tests are structured in kibana plugins, is the tests and code that is being tested are defined in separate files. For example:

/some_function.js

export default function({ getService, getPageObjects }) {
  return 'something cool';
}

/tests/some_function.js

import someFunction from '../some_function';
describe('somefunction', () => {
  it('does something cool', () => {
    expect(someFunction()).to.be('something cool');
  }
});

Third, there seems to be some confusion about the nature of the tests you're trying to write. You claim that you're trying to write server-side tests, but mention concepts related to client-side tests. These are two separate ideas and use different logic.

Last, There is no out-of-the-box test coverage library included in the plugin template, or yo generated plugin. That is up to you.

Thanks for your reply/clarification.

Yeah, I looked at server/tests/index.js and referred https://www.elastic.co/guide/en/kibana/current/development-functional-tests.html . Enlightment: I thought i need to do server side functional testing but client-side testing was required for my work.

Few more doubts:

  1. Is karma testing used? or Mocha.js
  2. Where should I pass/create mock data for custom plugin? How can I mock the data as, we are developing a plugin which doesn't use schema rather uses a custom es query?

Most of our functional UI tests (Selenium tests) load test data into Elasticsearch using the es_archiver

For example, in this discover test it uses
await esArchiver.load('discover');

Which is loading the set of data which is checked-in here; https://github.com/elastic/kibana/tree/master/test/functional/fixtures/es_archiver/discover

You can run the es_archiver from the command line to save some data you created in Elasticsearch by whatever means you want. And then in your test you would load that data. If it's time-based data (typically is) then in your test you would always set the Kibana timepicker to the same exact time so you always get the same results on that data. Like await PageObjects.header.setAbsoluteRange(fromTime, toTime);

If you're creating a new plugin, I would create a new Page Object file for the methods needed to access the objects in your plugin page.

You would typically run the UI tests by starting the Elasticsearch and Kibana server like
npm run test:ui:server
and then running the tests like;
node scripts/functional_test_runner

See https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md

Regards,
Lee

Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.