mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[plugin-generator] rewrite tests to match new generated plugins (#61571)
Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
parent
a9a9776b39
commit
5a537d16a5
2 changed files with 36 additions and 152 deletions
|
@ -491,6 +491,7 @@ module.exports = {
|
|||
'x-pack/dev-tools/mocha/setup_mocha.js',
|
||||
'x-pack/scripts/*.js',
|
||||
],
|
||||
excludedFiles: ['**/integration_tests/**/*'],
|
||||
rules: {
|
||||
'import/no-commonjs': 'off',
|
||||
'prefer-object-spread/prefer-object-spread': 'off',
|
||||
|
|
|
@ -17,163 +17,46 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
import { spawn } from 'child_process';
|
||||
import Fs from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import util from 'util';
|
||||
import { stat, readFileSync } from 'fs';
|
||||
import { snakeCase } from 'lodash';
|
||||
import { promisify } from 'util';
|
||||
|
||||
import del from 'del';
|
||||
import { ProcRunner, ToolingLog } from '@kbn/dev-utils';
|
||||
import { createLegacyEsTestCluster } from '@kbn/test';
|
||||
import execa from 'execa';
|
||||
import { snakeCase } from 'lodash';
|
||||
|
||||
const statP = util.promisify(stat);
|
||||
const statAsync = promisify(Fs.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
|
||||
const pluginName = 'ispec-plugin';
|
||||
const snakeCased = snakeCase(pluginName);
|
||||
const generatedPath = resolve(ROOT_DIR, `plugins/${snakeCased}`);
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
// skipped until internationalization is re-introduced
|
||||
it.skip(`should create an internationalization config file with a blank line appended to satisfy the parser`, async () => {
|
||||
// Link to the error that happens when the blank line is not there:
|
||||
// https://github.com/elastic/kibana/pull/45044#issuecomment-530092627
|
||||
const intlFile = `${generatedPath}/.i18nrc.json`;
|
||||
expect(readFileSync(intlFile, 'utf8').endsWith('\n\n')).toBe(true);
|
||||
});
|
||||
|
||||
describe(`then running`, () => {
|
||||
it(`'yarn test:karma' should exit 0`, async () => {
|
||||
await execa('yarn', ['test:karma'], {
|
||||
cwd: generatedPath,
|
||||
env: {
|
||||
DISABLE_JUNIT_REPORTER: '1',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it.skip(`'yarn build' should exit 0`, async () => {
|
||||
await execa('yarn', ['build'], { cwd: generatedPath });
|
||||
});
|
||||
|
||||
describe('with es instance', () => {
|
||||
const log = new ToolingLog({
|
||||
level: 'verbose',
|
||||
writeTo: process.stdout,
|
||||
});
|
||||
const pr = new ProcRunner(log);
|
||||
|
||||
const es = createLegacyEsTestCluster({ license: 'basic', log });
|
||||
beforeAll(es.start);
|
||||
afterAll(es.stop);
|
||||
afterAll(() => pr.teardown());
|
||||
|
||||
it(`'yarn start' should result in the spec plugin being initialized on kibana's stdout`, async () => {
|
||||
await pr.run('kibana', {
|
||||
cmd: 'yarn',
|
||||
args: [
|
||||
'start',
|
||||
'--optimize.enabled=false',
|
||||
'--logging.json=false',
|
||||
'--logging.verbose=true',
|
||||
'--migrations.skip=true',
|
||||
],
|
||||
cwd: generatedPath,
|
||||
wait: new RegExp('\\[ispecPlugin\\]\\[plugins\\] Setting up plugin'),
|
||||
});
|
||||
await pr.stop('kibana');
|
||||
});
|
||||
});
|
||||
|
||||
it(`'yarn preinstall' should exit 0`, async () => {
|
||||
await execa('yarn', ['preinstall'], { cwd: generatedPath });
|
||||
});
|
||||
|
||||
it.skip(`'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();
|
||||
});
|
||||
});
|
||||
});
|
||||
beforeAll(async () => {
|
||||
await del(generatedPath, { force: true });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await del(generatedPath, { force: true });
|
||||
});
|
||||
|
||||
it('generates a plugin', async () => {
|
||||
await new Promise((resolve, reject) => {
|
||||
const proc = spawn(process.execPath, ['scripts/generate_plugin.js', pluginName], {
|
||||
cwd: ROOT_DIR,
|
||||
stdio: 'pipe',
|
||||
});
|
||||
|
||||
proc.stdout.on('data', function selectDefaults() {
|
||||
proc.stdin.write('\n'); // Generate a plugin with default options.
|
||||
});
|
||||
|
||||
proc.on('close', resolve);
|
||||
proc.on('error', reject);
|
||||
});
|
||||
|
||||
const stats = await statAsync(generatedPath);
|
||||
if (!stats.isDirectory()) {
|
||||
throw new Error(`Expected [${generatedPath}] to be a directory`);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue