Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plugin Generator] Add integration test #43219

Merged
merged 74 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
c347097
Add first test + confs for babel and jest,
wayneseymour Aug 13, 2019
36f2219
Add cleanup using del.
wayneseymour Aug 13, 2019
664fed0
Add missing commit
wayneseymour Aug 13, 2019
02766dd
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 13, 2019
8acb3ff
Add first fail case.
wayneseymour Aug 13, 2019
c5fc55b
Add a list of currently failing yarn commands.
wayneseymour Aug 13, 2019
87706a9
Drop locally added deps to fixup the 'git changes' check
wayneseymour Aug 14, 2019
782a5af
Increase timeout for running in ci
wayneseymour Aug 14, 2019
fafcdeb
Drop fail cases per review,
wayneseymour Aug 14, 2019
4aa9dfd
Update name and bump timeout
wayneseymour Aug 14, 2019
d59a178
Change the src code to make "yarn lint"
wayneseymour Aug 15, 2019
bdb210c
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 15, 2019
c7d021c
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 15, 2019
5a65866
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 16, 2019
7f7ad32
Add verification for (yarn run kbn --help).
wayneseymour Aug 16, 2019
ef89d20
Fixup the code for packages/kbn-eslint-import-resolver-kibana,
wayneseymour Aug 16, 2019
de7568a
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 19, 2019
52de4a9
A little less code.
wayneseymour Aug 19, 2019
1af2bef
Add es help msg verifcation.
wayneseymour Aug 19, 2019
3dc9363
Verify stderr on running yarn preinstall
wayneseymour Aug 19, 2019
ae0eda3
Add verification for yarn build
wayneseymour Aug 19, 2019
97b3675
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 19, 2019
091c9a8
Drop resolver conditional in favor
wayneseymour Aug 21, 2019
53138e2
Switching to setup per Contributing guide.
wayneseymour Aug 21, 2019
a2a7f4e
Drop local babel config
wayneseymour Aug 21, 2019
2dd54df
Use global jest integration config
wayneseymour Aug 21, 2019
655bda3
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 21, 2019
43f2706
Fixup default plugin path, and
wayneseymour Aug 21, 2019
d1d2105
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 22, 2019
5c410f2
Refactor per the tips Spencer
wayneseymour Aug 22, 2019
616ff81
Fixup jest test,
wayneseymour Aug 22, 2019
493cf66
Verify yarn test:server.
wayneseymour Aug 22, 2019
f3c91e3
Block all but the tests for the plugin.
wayneseymour Aug 23, 2019
1c82504
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 26, 2019
9c6ecc7
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 27, 2019
c246ac3
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 27, 2019
09afb7e
Change arr init to empty,
wayneseymour Aug 27, 2019
20558ed
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 27, 2019
7961c66
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 28, 2019
1859a87
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 28, 2019
67a68a1
Merge branch 'master' into plugin-generator/integration-test
wayneseymour Aug 28, 2019
6221bac
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 29, 2019
d17e1b7
Escape the space in the path name.
wayneseymour Aug 29, 2019
aa3ea77
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 29, 2019
51b3298
Temporarily skip my test
wayneseymour Aug 29, 2019
b1dac60
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 29, 2019
f8b308e
Re-add my tests
wayneseymour Aug 29, 2019
1af8eb6
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 29, 2019
1cf5226
Put my test on top
wayneseymour Aug 29, 2019
47fae84
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 30, 2019
62eb30f
Bump default timeout.
wayneseymour Aug 30, 2019
5d2140a
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 30, 2019
daaf46c
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 30, 2019
9b7ad80
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Aug 30, 2019
9f7d809
Temporarily add more debug info to
wayneseymour Aug 30, 2019
5549a12
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 3, 2019
9717afc
Run the integration tests only.
wayneseymour Sep 3, 2019
6ce4dae
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 3, 2019
30fef0b
Add back all the tests and run in band.
wayneseymour Sep 3, 2019
0adcae3
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 3, 2019
40957c7
Following a hunch...now writing to a no-op stream,
wayneseymour Sep 3, 2019
8545167
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 3, 2019
9a58642
Run in band
wayneseymour Sep 3, 2019
1caf0c6
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 3, 2019
3cd03dd
Drop the no-op stream, and
wayneseymour Sep 3, 2019
57c3bd9
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 3, 2019
0c7ba8c
Drop reduntant root, and
wayneseymour Sep 3, 2019
86a9d35
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 5, 2019
d127721
Switch no_restricted_paths back to original.
wayneseymour Sep 5, 2019
92b2e29
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 6, 2019
aa0c8e6
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 6, 2019
c7fb74e
Testing a theory.
wayneseymour Sep 6, 2019
aae5216
Merge branch 'master' of github.com:elastic/kibana into plugin-genera…
wayneseymour Sep 6, 2019
d22f61d
Only add all if we are not focused on specific plugins for testing.
wayneseymour Sep 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { resolve } = require('path');

const { debug } = require('./debug');

const DEFAULT_PLUGIN_PATH = '../../kibana';
const DEFAULT_PLUGIN_PATH = '../..';

/*
* Resolves the path to Kibana, either from default setting or config
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/* eslint-disable no-restricted-syntax */
import { spawn } from 'child_process';
import { resolve } from 'path';
import util from 'util';
import { stat } from 'fs';
import { snakeCase } from 'lodash';
import del from 'del';
import { withProcRunner, ToolingLog } from '@kbn/dev-utils';
import { createEsTestCluster } from '@kbn/test';
import execa from 'execa';

const statP = util.promisify(stat);
const ROOT_DIR = resolve(__dirname, '../../../');
const oneMinute = 60000;

describe(`running the plugin-generator via 'node scripts/generate_plugin.js plugin-name' with default config`, () => {
const pluginName = 'ispec-plugin';
const snakeCased = snakeCase(pluginName);
const generatedPath = resolve(ROOT_DIR, `plugins/${snakeCased}`);
const collect = xs => data => xs.push(data + ''); // Coerce from Buffer to String

beforeAll(() => {
jest.setTimeout(oneMinute * 10);
});

beforeAll(done => {
const create = spawn(process.execPath, ['scripts/generate_plugin.js', pluginName], {
cwd: ROOT_DIR,
});
create.stdout.on('data', function selectDefaults() {
create.stdin.write('\n'); // Generate a plugin with default options.
});
create.on('close', done);
});

afterAll(() => {
del.sync(generatedPath, { force: true });
});

it(`should succeed on creating a plugin in a directory named 'plugins/${snakeCased}`, async () => {
const stats = await statP(generatedPath);
expect(stats.isDirectory()).toBe(true);
});

describe(`then running`, () => {
it(`'yarn test:browser' should exit 0`, async () => {
await execa('yarn', ['test:browser'], { cwd: generatedPath });
});

it(`'yarn test:server' should exit 0`, async () => {
await execa('yarn', ['test:server'], { cwd: generatedPath });
});

it(`'yarn build' should exit 0`, async () => {
await execa('yarn', ['build'], { cwd: generatedPath });
});

it(`'yarn start' should result in the spec plugin being initialized on kibana's stdout`, async () => {
const log = new ToolingLog();
const es = createEsTestCluster({ license: 'basic', log });
await es.start();
await withProcRunner(log, async proc => {
await proc.run('kibana', {
cmd: 'yarn',
args: ['start', '--optimize.enabled=false', '--logging.json=false'],
cwd: generatedPath,
wait: /ispec_plugin.+Status changed from uninitialized to green - Ready/,
});
await proc.stop('kibana');
});
await es.stop();
});

it(`'yarn preinstall' should exit 0`, async () => {
await execa('yarn', ['preinstall'], { cwd: generatedPath });
});

it(`'yarn lint' should exit 0`, async () => {
await execa('yarn', ['lint'], { cwd: generatedPath });
});

it(`'yarn kbn --help' should print out the kbn help msg`, done => {
const helpMsg = `
usage: kbn <command> [<args>]

By default commands are run for Kibana itself, all packages in the 'packages/'
folder and for all plugins in './plugins' and '../kibana-extra'.

Available commands:

bootstrap - Install dependencies and crosslink projects
clean - Remove the node_modules and target directories from all projects.
run - Run script defined in package.json in each package that contains that script.
watch - Runs \`kbn:watch\` script for every project.

Global options:

-e, --exclude Exclude specified project. Can be specified multiple times to exclude multiple projects, e.g. '-e kibana -e @kbn/pm'.
-i, --include Include only specified projects. If left unspecified, it defaults to including all projects.
--oss Do not include the x-pack when running command.
--skip-kibana-plugins Filter all plugins in ./plugins and ../kibana-extra when running command.
`;
const outData = [];
const kbnHelp = spawn('yarn', ['kbn', '--help'], { cwd: generatedPath });
kbnHelp.stdout.on('data', collect(outData));
kbnHelp.on('close', () => {
expect(outData.join('\n')).toContain(helpMsg);
done();
});
});

it(`'yarn es --help' should print out the es help msg`, done => {
const helpMsg = `
usage: es <command> [<args>]

Assists with running Elasticsearch for Kibana development

Available commands:

snapshot - Downloads and run from a nightly snapshot
source - Build and run from source
archive - Install and run from an Elasticsearch tar
build_snapshots - Build and collect ES snapshots

Global options:

--help
`;
const outData = [];
const kbnHelp = spawn('yarn', ['es', '--help'], { cwd: generatedPath });
kbnHelp.stdout.on('data', collect(outData));
kbnHelp.on('close', () => {
expect(outData.join('\n')).toContain(helpMsg);
done();
});
});
});
});
2 changes: 1 addition & 1 deletion packages/kbn-plugin-generator/sao_template/sao.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = function({ name }) {
},
move: {
gitignore: '.gitignore',
eslintrc: '.eslintrc',
'eslintrc.js': '.eslintrc.js',
'package_template.json': 'package.json',
},
data: answers =>
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-plugin-generator/sao_template/sao.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ describe('plugin generator sao integration', () => {
it('includes dotfiles', async () => {
const res = await sao.mockPrompt(template);
expect(res.files['.gitignore']).toBeTruthy();
expect(res.files['.eslintrc']).toBeTruthy();
expect(res.files['.eslintrc.js']).toBeTruthy();
});
});
7 changes: 0 additions & 7 deletions packages/kbn-plugin-generator/sao_template/template/eslintrc

This file was deleted.

24 changes: 24 additions & 0 deletions packages/kbn-plugin-generator/sao_template/template/eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
root: true,
extends: ['@elastic/eslint-config-kibana', 'plugin:@elastic/eui/recommended'],
settings: {
'import/resolver': {
'@kbn/eslint-import-resolver-kibana': {
rootPackageName: '<%= snakeCase(name) %>',
},
},
},
overrides: [
{
files: ['**/public/**/*'],
settings: {
'import/resolver': {
'@kbn/eslint-import-resolver-kibana': {
forceNode: false,
rootPackageName: '<%= snakeCase(name) %>',
},
},
},
},
]
};
58 changes: 29 additions & 29 deletions packages/kbn-plugin-generator/sao_template/template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,39 @@ export default function (kibana) {

init(server, options) { // eslint-disable-line no-unused-vars
<%_ if (generateApp) { -%>
const xpackMainPlugin = server.plugins.xpack_main;
if (xpackMainPlugin) {
const featureId = '<%= snakeCase(name) %>';
const xpackMainPlugin = server.plugins.xpack_main;
if (xpackMainPlugin) {
const featureId = '<%= snakeCase(name) %>';

xpackMainPlugin.registerFeature({
id: featureId,
name: i18n.translate('<%= camelCase(name) %>.featureRegistry.featureName', {
defaultMessage: '<%= name %>',
}),
navLinkId: featureId,
icon: 'questionInCircle',
app: [featureId, 'kibana'],
catalogue: [],
privileges: {
all: {
api: [],
savedObject: {
all: [],
read: [],
},
ui: ['show'],
xpackMainPlugin.registerFeature({
id: featureId,
name: i18n.translate('<%= camelCase(name) %>.featureRegistry.featureName', {
defaultMessage: '<%= name %>',
}),
navLinkId: featureId,
icon: 'questionInCircle',
app: [featureId, 'kibana'],
catalogue: [],
privileges: {
all: {
api: [],
savedObject: {
all: [],
read: [],
},
read: {
api: [],
savedObject: {
all: [],
read: [],
},
ui: ['show'],
ui: ['show'],
},
read: {
api: [],
savedObject: {
all: [],
read: [],
},
ui: ['show'],
},
});
}
},
});
}
<%_ } -%>

<%_ if (generateApi) { -%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Main } from './main';
export { Main } from './main';
1 change: 1 addition & 0 deletions scripts/jest_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

var resolve = require('path').resolve;
process.argv.push('--config', resolve(__dirname, '../src/dev/jest/config.integration.js'));
process.argv.push('--runInBand');

require('../src/setup_node_env');
require('../src/dev/jest/cli');
4 changes: 2 additions & 2 deletions src/dev/jest/setup/after_env.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
/* eslint-env jest */

/**
* Set the default timeout for the integration test suite to 30 seconds
* Set the default timeout for the integration test suite to 10 minutes
*/
jest.setTimeout(30 * 1000);
jest.setTimeout(10 * 60 * 1000);
12 changes: 5 additions & 7 deletions src/legacy/core_plugins/tests_bundle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@ export default (kibana) => {
}
} = kbnServer;

const testGlobs = [
'src/legacy/ui/public/**/*.js',
'!src/legacy/ui/public/flot-charts/**/*',
];
const testGlobs = [];

const testingPluginIds = config.get('tests_bundle.pluginId');

if (testingPluginIds) {
testGlobs.push('!src/legacy/ui/public/**/__tests__/**/*');
testingPluginIds.split(',').forEach((pluginId) => {
const plugin = plugins
.find(plugin => plugin.id === pluginId);
const plugin = plugins.find(plugin => plugin.id === pluginId);

if (!plugin) {
throw new Error('Invalid testingPluginId :: unknown plugin ' + pluginId);
Expand All @@ -78,6 +74,8 @@ export default (kibana) => {
testGlobs.push(`${plugin.publicDir}/**/__tests__/**/*.js`);
});
} else {
// add all since we are not just focused on specific plugins
testGlobs.push('src/legacy/ui/public/**/*.js', '!src/legacy/ui/public/flot-charts/**/*');
// add the modules from all of the apps
for (const app of uiApps) {
modules.add(app.getMainModuleId());
Expand Down