kibana/packages/kbn-plugin-generator
Spencer 7e94eccc2e
Upgrade to Jest 23.5.0 (#22791)
I'd really like to upgrade to Typescript 3 for its `unknown` type, but we need to upgrade to `jest@23` to support a recent version of `ts-jest@23`. 

The [jest changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md) breaks down the breaking changes in 23.x, but I found it to be slightly incomplete so I've broken down the changes that actually caused breaks for us here, and addressed each in individual commits to make review a little easier:

- the `testURL` config default was changed from `about:blank` to `http://localhost`
    - this cause some XHR requests powered by JSdom to start failing. It seems these requests just do nothing in master but start to fail when JSdom is initialized with an actual URL... I think we would ideally stop sending meaningless XHR requests in the tests, but it was a lot easier to just set the config to `about:blank` for now, and we can worry about cleanup later if necessary
- `expect(...).toThrow()` only passes if an actual error was thrown.
     - In two places in the index pattern code we were throwing strings, which broke the assertions. Fortunately/Unfortunately the errors are not being consumed by anything, so I was able to wrap them in `new Error()` without causing any issues.
- snapshots of mock functions now include a `results` array, detailing the return values of the function
- React fragments are now serialized as `<React.Fragment>` instead of `<UNDEFINED>`
- undefined props in React components are now stripped from snapshots
- minor changes to the ordering of mocks, imports resolution, and before hooks caused the uiSettings API tests to start breaking, but I'm replacing them with totally new tests in #22694 so I just deleted them here
- mocks created with `jest.spyOn()` that are restored now have their `mock.calls` reset, so some of the kbn-pm tests stated failing. This was fixed by restoring them with `jest.restoreAllMocks()` rather than trying to do it before the assertions
2018-09-07 18:36:13 -07:00
..
sao_template Upgrade to Jest 23.5.0 (#22791) 2018-09-07 18:36:13 -07:00
index.js Apache 2.0 license headers (#19383) 2018-05-28 20:06:30 -07:00
package.json Match chalk dependency version on kibana with the one used on x-pack (#20621) 2018-07-13 00:26:57 +01:00
README.md Missing argument for generate_plugin script (#16782) 2018-02-19 10:08:13 +01:00
yarn.lock Match chalk dependency version on kibana with the one used on x-pack (#20621) 2018-07-13 00:26:57 +01:00

Kibana Plugin Generator

This package can be used to generate a Kibana plugin from the Kibana repo.

Setup

Before you can use this plugin generator you must setup your Kibana development environment. If you can successfully run yarn kbn bootstrap then you are ready to generate plugins!

Compatibility

The plugin generator became a part of the Kibana project as of Kibana 6.3. If you are targeting versions before Kibana 6.3 then use the Kibana plugin sao template.

If you are targeting Kibana 6.3 or greater then checkout the corresponding Kibana branch and run the plugin generator.

Quick Start

To target the current development version of Kibana just use the default master branch.

node scripts/generate_plugin my_plugin_name
# generates a plugin in `../kibana-extra/my_plugin_name`

To target 6.3, use the 6.x branch (until the 6.3 branch is created).

git checkout 6.x
yarn kbn bootstrap # always bootstrap when switching branches
node scripts/generate_plugin my_plugin_name
# generates a plugin for Kibana 6.3 in `../kibana-extra/my_plugin_name`

The generate script supports a few flags; run it with the --help flag to learn more.

node scripts/generate_plugin --help

Updating

Since the Plugin Generator is now a part of the Kibana repo, when you update your local checkout of the Kibana repository and bootstrap everything should be up to date!

NOTE: These commands should be run from the Kibana repo, and upstream is our convention for the git remote that references https://github.com/elastic/kibana.git, unless you added this remote you might need to use origin.

git pull upstream master
yarn kbn bootstrap

Plugin Development Scripts

Generated plugins receive a handful of scripts that can be used during development. Those scripts are detailed in the README.md file in each newly generated plugin, and expose the scripts provided by the Kibana plugin helpers, but here is a quick reference in case you need it:

NOTE: All of these scripts should be run from the generated plugin.

  • yarn kbn bootstrap

    Install dependencies and crosslink Kibana and all projects/plugins.

    IMPORTANT: Use this script instead of yarn to install dependencies when switching branches, and re-run it whenever your dependencies change.

  • yarn start

    Start kibana and have it include this plugin. You can pass any arguments that you would normally send to bin/kibana

    yarn start --elasticsearch.url http://localhost:9220
    
  • yarn build

    Build a distributable archive of your plugin.

  • yarn test:browser

    Run the browser tests in a real web browser.

  • yarn test:server

    Run the server tests using mocha.

For more information about any of these commands run yarn ${task} --help. For a full list of tasks run yarn run or take a look in the package.json file.