Skip to content

Commit 5a537d1

Browse files
Spencerspalger
andauthored
[plugin-generator] rewrite tests to match new generated plugins (#61571)
Co-authored-by: spalger <spalger@users.noreply.github.com>
1 parent a9a9776 commit 5a537d1

File tree

2 files changed

+29
-145
lines changed

2 files changed

+29
-145
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ module.exports = {
491491
'x-pack/dev-tools/mocha/setup_mocha.js',
492492
'x-pack/scripts/*.js',
493493
],
494+
excludedFiles: ['**/integration_tests/**/*'],
494495
rules: {
495496
'import/no-commonjs': 'off',
496497
'prefer-object-spread/prefer-object-spread': 'off',

packages/kbn-plugin-generator/integration_tests/generate_plugin.test.js

Lines changed: 28 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -17,163 +17,46 @@
1717
* under the License.
1818
*/
1919

20-
/* eslint-disable no-restricted-syntax */
2120
import { spawn } from 'child_process';
21+
import Fs from 'fs';
2222
import { resolve } from 'path';
23-
import util from 'util';
24-
import { stat, readFileSync } from 'fs';
25-
import { snakeCase } from 'lodash';
23+
import { promisify } from 'util';
24+
2625
import del from 'del';
27-
import { ProcRunner, ToolingLog } from '@kbn/dev-utils';
28-
import { createLegacyEsTestCluster } from '@kbn/test';
29-
import execa from 'execa';
26+
import { snakeCase } from 'lodash';
3027

31-
const statP = util.promisify(stat);
28+
const statAsync = promisify(Fs.stat);
3229
const ROOT_DIR = resolve(__dirname, '../../../');
33-
const oneMinute = 60000;
34-
35-
describe(`running the plugin-generator via 'node scripts/generate_plugin.js plugin-name' with default config`, () => {
36-
const pluginName = 'ispec-plugin';
37-
const snakeCased = snakeCase(pluginName);
38-
const generatedPath = resolve(ROOT_DIR, `plugins/${snakeCased}`);
39-
const collect = xs => data => xs.push(data + ''); // Coerce from Buffer to String
40-
41-
beforeAll(() => {
42-
jest.setTimeout(oneMinute * 10);
43-
});
44-
45-
beforeAll(done => {
46-
const create = spawn(process.execPath, ['scripts/generate_plugin.js', pluginName], {
47-
cwd: ROOT_DIR,
48-
});
49-
create.stdout.on('data', function selectDefaults() {
50-
create.stdin.write('\n'); // Generate a plugin with default options.
51-
});
52-
create.on('close', done);
53-
});
54-
55-
afterAll(() => {
56-
del.sync(generatedPath, { force: true });
57-
});
58-
59-
it(`should succeed on creating a plugin in a directory named 'plugins/${snakeCased}`, async () => {
60-
const stats = await statP(generatedPath);
61-
expect(stats.isDirectory()).toBe(true);
62-
});
6330

64-
// skipped until internationalization is re-introduced
65-
it.skip(`should create an internationalization config file with a blank line appended to satisfy the parser`, async () => {
66-
// Link to the error that happens when the blank line is not there:
67-
// https://github.com/elastic/kibana/pull/45044#issuecomment-530092627
68-
const intlFile = `${generatedPath}/.i18nrc.json`;
69-
expect(readFileSync(intlFile, 'utf8').endsWith('\n\n')).toBe(true);
70-
});
71-
72-
describe(`then running`, () => {
73-
it(`'yarn test:karma' should exit 0`, async () => {
74-
await execa('yarn', ['test:karma'], {
75-
cwd: generatedPath,
76-
env: {
77-
DISABLE_JUNIT_REPORTER: '1',
78-
},
79-
});
80-
});
81-
82-
it.skip(`'yarn build' should exit 0`, async () => {
83-
await execa('yarn', ['build'], { cwd: generatedPath });
84-
});
31+
const pluginName = 'ispec-plugin';
32+
const snakeCased = snakeCase(pluginName);
33+
const generatedPath = resolve(ROOT_DIR, `plugins/${snakeCased}`);
8534

86-
describe('with es instance', () => {
87-
const log = new ToolingLog({
88-
level: 'verbose',
89-
writeTo: process.stdout,
90-
});
91-
const pr = new ProcRunner(log);
92-
93-
const es = createLegacyEsTestCluster({ license: 'basic', log });
94-
beforeAll(es.start);
95-
afterAll(es.stop);
96-
afterAll(() => pr.teardown());
35+
beforeAll(async () => {
36+
await del(generatedPath, { force: true });
37+
});
9738

98-
it(`'yarn start' should result in the spec plugin being initialized on kibana's stdout`, async () => {
99-
await pr.run('kibana', {
100-
cmd: 'yarn',
101-
args: [
102-
'start',
103-
'--optimize.enabled=false',
104-
'--logging.json=false',
105-
'--logging.verbose=true',
106-
'--migrations.skip=true',
107-
],
108-
cwd: generatedPath,
109-
wait: new RegExp('\\[ispecPlugin\\]\\[plugins\\] Setting up plugin'),
110-
});
111-
await pr.stop('kibana');
112-
});
113-
});
39+
afterAll(async () => {
40+
await del(generatedPath, { force: true });
41+
});
11442

115-
it(`'yarn preinstall' should exit 0`, async () => {
116-
await execa('yarn', ['preinstall'], { cwd: generatedPath });
43+
it('generates a plugin', async () => {
44+
await new Promise((resolve, reject) => {
45+
const proc = spawn(process.execPath, ['scripts/generate_plugin.js', pluginName], {
46+
cwd: ROOT_DIR,
47+
stdio: 'pipe',
11748
});
11849

119-
it.skip(`'yarn lint' should exit 0`, async () => {
120-
await execa('yarn', ['lint'], { cwd: generatedPath });
50+
proc.stdout.on('data', function selectDefaults() {
51+
proc.stdin.write('\n'); // Generate a plugin with default options.
12152
});
12253

123-
it(`'yarn kbn --help' should print out the kbn help msg`, done => {
124-
const helpMsg = `
125-
usage: kbn <command> [<args>]
126-
127-
By default commands are run for Kibana itself, all packages in the 'packages/'
128-
folder and for all plugins in './plugins' and '../kibana-extra'.
129-
130-
Available commands:
131-
132-
bootstrap - Install dependencies and crosslink projects
133-
clean - Remove the node_modules and target directories from all projects.
134-
run - Run script defined in package.json in each package that contains that script.
135-
watch - Runs \`kbn:watch\` script for every project.
136-
137-
Global options:
138-
139-
-e, --exclude Exclude specified project. Can be specified multiple times to exclude multiple projects, e.g. '-e kibana -e @kbn/pm'.
140-
-i, --include Include only specified projects. If left unspecified, it defaults to including all projects.
141-
--oss Do not include the x-pack when running command.
142-
--skip-kibana-plugins Filter all plugins in ./plugins and ../kibana-extra when running command.
143-
`;
144-
const outData = [];
145-
const kbnHelp = spawn('yarn', ['kbn', '--help'], { cwd: generatedPath });
146-
kbnHelp.stdout.on('data', collect(outData));
147-
kbnHelp.on('close', () => {
148-
expect(outData.join('\n')).toContain(helpMsg);
149-
done();
150-
});
151-
});
152-
153-
it(`'yarn es --help' should print out the es help msg`, done => {
154-
const helpMsg = `
155-
usage: es <command> [<args>]
156-
157-
Assists with running Elasticsearch for Kibana development
158-
159-
Available commands:
160-
161-
snapshot - Downloads and run from a nightly snapshot
162-
source - Build and run from source
163-
archive - Install and run from an Elasticsearch tar
164-
build_snapshots - Build and collect ES snapshots
165-
166-
Global options:
167-
168-
--help
169-
`;
170-
const outData = [];
171-
const kbnHelp = spawn('yarn', ['es', '--help'], { cwd: generatedPath });
172-
kbnHelp.stdout.on('data', collect(outData));
173-
kbnHelp.on('close', () => {
174-
expect(outData.join('\n')).toContain(helpMsg);
175-
done();
176-
});
177-
});
54+
proc.on('close', resolve);
55+
proc.on('error', reject);
17856
});
57+
58+
const stats = await statAsync(generatedPath);
59+
if (!stats.isDirectory()) {
60+
throw new Error(`Expected [${generatedPath}] to be a directory`);
61+
}
17962
});

0 commit comments

Comments
 (0)