New

The executive guide to generative AI

Read more

Kibana 仓库外部插件的功能测试

编辑

Kibana 仓库外部插件的功能测试

编辑

插件通过在 Kibana 仓库外部运行 FunctionalTestRunner 来使用它。请确保在继续之前正确设置了 Kibana 开发环境。

编写自己的配置

编辑

每个项目或插件都应该有自己的 FunctionalTestRunner 配置文件。就像 Kibana 的配置文件一样,此配置文件将定义要加载的所有测试文件、服务和 PageObject 的提供程序,以及某些服务的配置选项。

首先,将此示例复制粘贴到 test/functional/config.js

import { resolve } from 'path';
import { REPO_ROOT } from '@kbn/utils';

import { MyServiceProvider } from './services/my_service';
import { MyAppPageProvider } from './services/my_app_page';

// the default export of config files must be a config provider
// that returns an object with the projects config values
export default async function ({ readConfigFile }) {

  // read the Kibana config file so that we can utilize some of
  // its services and PageObjects
  const kibanaConfig = await readConfigFile(resolve(REPO_ROOT, 'test/functional/config.base.js'));

  return {
    // list paths to the files that contain your plugins tests
    testFiles: [
      resolve(__dirname, './my_test_file.js'),
    ],

    // define the name and providers for services that should be
    // available to your tests. If you don't specify anything here
    // only the built-in services will be available
    services: {
      ...kibanaConfig.get('services'),
      myService: MyServiceProvider,
    },

    // just like services, PageObjects are defined as a map of
    // names to Providers. Merge in Kibana's or pick specific ones
    pageObjects: {
      management: kibanaConfig.get('pageObjects.management'),
      myApp: MyAppPageProvider,
    },

    // the apps section defines the urls that
    // `PageObjects.common.navigateTo(appKey)` will use.
    // Merge urls for your plugin with the urls defined in
    // Kibana's config in order to use this helper
    apps: {
      ...kibanaConfig.get('apps'),
      myApp: {
        pathname: '/app/my_app',
      }
    },

    // choose where screenshots should be saved
    screenshots: {
      directory: resolve(__dirname, './tmp/screenshots'),
    }

    // more settings, like timeouts, mochaOpts, etc are
    // defined in the config schema.
    // See https://github.com/elastic/kibana/blob/8.17/packages/kbn-test/src/functional_test_runner/lib/config/schema.ts
  };
}

现在,你应该能够从插件项目的根目录运行 FunctionalTestRunner 脚本。

node ../../kibana/scripts/functional_test_runner

使用 esArchiver

编辑

我们正在编写相关的文档,但目前最好的参考是原始的 pull request

Was this helpful?
Feedback