mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* [plugin helpers] Use Kibana's Jest * Remove outer 'describe' * Async/await in tests * Assertion improvements
This commit is contained in:
parent
5856dd2d85
commit
059a8a34ee
8 changed files with 174 additions and 2099 deletions
|
@ -9,10 +9,6 @@
|
|||
},
|
||||
"author": "Spencer Alger <email@spalger.com>",
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"test:dev": "jest --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": "^2.9.0",
|
||||
"del": "^2.2.2",
|
||||
|
@ -23,8 +19,5 @@
|
|||
"through2": "^2.0.3",
|
||||
"through2-map": "^3.0.0",
|
||||
"vinyl-fs": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^17.0.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
/*eslint-env jest*/
|
||||
const resolve = require('path').resolve;
|
||||
const fs = require('fs');
|
||||
const del = require('del');
|
||||
|
||||
const PLUGIN_FIXTURE = resolve(__dirname, '__fixtures__/build_action_test_plugin');
|
||||
const PLUGIN_BUILD_DIR = resolve(PLUGIN_FIXTURE, 'build');
|
||||
const PLUGIN = require('../../lib/plugin_config')(PLUGIN_FIXTURE);
|
||||
const noop = function () {};
|
||||
|
||||
describe('build_action', () => {
|
||||
describe('creating build zip', function () {
|
||||
const buildAction = require('./build_action');
|
||||
|
||||
beforeEach(() => del(PLUGIN_BUILD_DIR));
|
||||
afterEach(() => del(PLUGIN_BUILD_DIR));
|
||||
|
||||
it('creates a zip in the build directory', () => {
|
||||
return buildAction(PLUGIN).then(() => {
|
||||
const buildFile = resolve(PLUGIN_BUILD_DIR, PLUGIN.id + '-' + PLUGIN.version + '.zip');
|
||||
if (!fs.existsSync(buildFile)) {
|
||||
throw new Error('Build file not found: ' + buildFile);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('skips zip creation based on flag', function () {
|
||||
return buildAction(PLUGIN, noop, { skipArchive: true }).then(() => {
|
||||
const buildFile = resolve(PLUGIN_BUILD_DIR, PLUGIN.id + '-' + PLUGIN.version + '.zip');
|
||||
if (fs.existsSync(buildFile)) {
|
||||
throw new Error('Build file not found: ' + buildFile);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('calling create_build', () => {
|
||||
let mockBuild;
|
||||
let buildAction;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
mockBuild = jest.fn(() => Promise.resolve());
|
||||
jest.mock('./create_build', () => mockBuild);
|
||||
buildAction = require('./build_action');
|
||||
});
|
||||
|
||||
it('takes optional build version', function () {
|
||||
const options = {
|
||||
buildVersion: '1.2.3',
|
||||
kibanaVersion: '4.5.6',
|
||||
};
|
||||
|
||||
return buildAction(PLUGIN, noop, options).then(() => {
|
||||
expect(mockBuild.mock.calls).toHaveLength(1);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
|
||||
expect(buildVersion).toBe('1.2.3');
|
||||
expect(kibanaVersion).toBe('4.5.6');
|
||||
});
|
||||
});
|
||||
|
||||
it('uses default file list without files option', function () {
|
||||
return buildAction(PLUGIN).then(() => {
|
||||
expect(mockBuild.mock.calls).toHaveLength(1);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
|
||||
PLUGIN.buildSourcePatterns.forEach(file => expect(files).toContain(file));
|
||||
});
|
||||
});
|
||||
|
||||
it('uses only files passed in', function () {
|
||||
const options = {
|
||||
files: [
|
||||
'index.js',
|
||||
'LICENSE.txt',
|
||||
'plugins/**/*',
|
||||
'{server,public}/**/*'
|
||||
]
|
||||
};
|
||||
|
||||
return buildAction(PLUGIN, noop, options).then(() => {
|
||||
expect(mockBuild.mock.calls).toHaveLength(1);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
|
||||
options.files.forEach(file => expect(files).toContain(file));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
87
packages/kbn-plugin-helpers/tasks/build/build_action.test.js
Normal file
87
packages/kbn-plugin-helpers/tasks/build/build_action.test.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
const resolve = require('path').resolve;
|
||||
const fs = require('fs');
|
||||
const del = require('del');
|
||||
|
||||
const PLUGIN_FIXTURE = resolve(__dirname, '__fixtures__/build_action_test_plugin');
|
||||
const PLUGIN_BUILD_DIR = resolve(PLUGIN_FIXTURE, 'build');
|
||||
const PLUGIN = require('../../lib/plugin_config')(PLUGIN_FIXTURE);
|
||||
const noop = () => {};
|
||||
|
||||
describe('creating build zip', () => {
|
||||
const buildAction = require('./build_action');
|
||||
|
||||
beforeEach(() => del(PLUGIN_BUILD_DIR));
|
||||
afterEach(() => del(PLUGIN_BUILD_DIR));
|
||||
|
||||
it('creates a zip in the build directory', async () => {
|
||||
await buildAction(PLUGIN);
|
||||
|
||||
const buildFile = resolve(PLUGIN_BUILD_DIR, PLUGIN.id + '-' + PLUGIN.version + '.zip');
|
||||
if (!fs.existsSync(buildFile)) {
|
||||
throw new Error('Build file not found: ' + buildFile);
|
||||
}
|
||||
});
|
||||
|
||||
it('skips zip creation based on flag', async () => {
|
||||
await buildAction(PLUGIN, noop, { skipArchive: true });
|
||||
|
||||
const buildFile = resolve(PLUGIN_BUILD_DIR, PLUGIN.id + '-' + PLUGIN.version + '.zip');
|
||||
if (fs.existsSync(buildFile)) {
|
||||
throw new Error('Build file not found: ' + buildFile);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('calling create_build', () => {
|
||||
let mockBuild;
|
||||
let buildAction;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
mockBuild = jest.fn(() => Promise.resolve());
|
||||
jest.mock('./create_build', () => mockBuild);
|
||||
buildAction = require('./build_action');
|
||||
});
|
||||
|
||||
it('takes optional build version', async () => {
|
||||
const options = {
|
||||
buildVersion: '1.2.3',
|
||||
kibanaVersion: '4.5.6',
|
||||
};
|
||||
|
||||
await buildAction(PLUGIN, noop, options);
|
||||
|
||||
expect(mockBuild.mock.calls).toHaveLength(1);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
|
||||
expect(buildVersion).toBe('1.2.3');
|
||||
expect(kibanaVersion).toBe('4.5.6');
|
||||
});
|
||||
|
||||
it('uses default file list without files option', async () => {
|
||||
await buildAction(PLUGIN);
|
||||
|
||||
expect(mockBuild.mock.calls).toHaveLength(1);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
|
||||
PLUGIN.buildSourcePatterns.forEach(file => expect(files).toContain(file));
|
||||
});
|
||||
|
||||
it('uses only files passed in', async () => {
|
||||
const options = {
|
||||
files: [
|
||||
'index.js',
|
||||
'LICENSE.txt',
|
||||
'plugins/**/*',
|
||||
'{server,public}/**/*'
|
||||
]
|
||||
};
|
||||
|
||||
await buildAction(PLUGIN, noop, options);
|
||||
|
||||
expect(mockBuild.mock.calls).toHaveLength(1);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
|
||||
options.files.forEach(file => expect(files).toContain(file));
|
||||
});
|
||||
});
|
|
@ -1,45 +0,0 @@
|
|||
/*eslint-env jest*/
|
||||
const { resolve } = require('path');
|
||||
const del = require('del');
|
||||
const createBuild = require('./create_build');
|
||||
|
||||
const PLUGIN_FIXTURE = resolve(__dirname, '__fixtures__/create_build_test_plugin');
|
||||
const PLUGIN = require('../../lib/plugin_config')(PLUGIN_FIXTURE);
|
||||
const PLUGIN_BUILD_DIR = resolve(PLUGIN_FIXTURE, 'build');
|
||||
const PLUGIN_BUILD_TARGET = resolve(PLUGIN_BUILD_DIR, 'kibana', PLUGIN.id);
|
||||
|
||||
describe('create_build', () => {
|
||||
beforeEach(() => del(PLUGIN_BUILD_DIR));
|
||||
afterEach(() => del(PLUGIN_BUILD_DIR));
|
||||
|
||||
describe('creating the build', function () {
|
||||
const buildTarget = resolve(PLUGIN.root, 'build');
|
||||
const buildVersion = PLUGIN.version;
|
||||
const kibanaVersion = PLUGIN.version;
|
||||
const buildFiles = PLUGIN.buildSourcePatterns;
|
||||
|
||||
it('removes development properties from package.json', function () {
|
||||
expect(PLUGIN.pkg.scripts).not.toBeUndefined();
|
||||
expect(PLUGIN.pkg.devDependencies).not.toBeUndefined();
|
||||
|
||||
return createBuild(PLUGIN, buildTarget, buildVersion, kibanaVersion, buildFiles)
|
||||
.then(() => {
|
||||
const pkg = require(resolve(PLUGIN_BUILD_TARGET, 'package.json'));
|
||||
expect(pkg.scripts).toBeUndefined();
|
||||
expect(pkg.devDependencies).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('adds build metadata to package.json', function () {
|
||||
expect(PLUGIN.pkg.build).toBeUndefined();
|
||||
|
||||
return createBuild(PLUGIN, buildTarget, buildVersion, kibanaVersion, buildFiles)
|
||||
.then(() => {
|
||||
const pkg = require(resolve(PLUGIN_BUILD_TARGET, 'package.json'));
|
||||
expect(pkg.build).not.toBeUndefined();
|
||||
expect(pkg.build.git).not.toBeUndefined();
|
||||
expect(pkg.build.date).not.toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
40
packages/kbn-plugin-helpers/tasks/build/create_build.test.js
Normal file
40
packages/kbn-plugin-helpers/tasks/build/create_build.test.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
const { resolve } = require('path');
|
||||
const del = require('del');
|
||||
const createBuild = require('./create_build');
|
||||
|
||||
const PLUGIN_FIXTURE = resolve(__dirname, '__fixtures__/create_build_test_plugin');
|
||||
const PLUGIN = require('../../lib/plugin_config')(PLUGIN_FIXTURE);
|
||||
const PLUGIN_BUILD_DIR = resolve(PLUGIN_FIXTURE, 'build');
|
||||
const PLUGIN_BUILD_TARGET = resolve(PLUGIN_BUILD_DIR, 'kibana', PLUGIN.id);
|
||||
|
||||
beforeEach(() => del(PLUGIN_BUILD_DIR));
|
||||
afterEach(() => del(PLUGIN_BUILD_DIR));
|
||||
|
||||
describe('creating the build', () => {
|
||||
const buildTarget = resolve(PLUGIN.root, 'build');
|
||||
const buildVersion = PLUGIN.version;
|
||||
const kibanaVersion = PLUGIN.version;
|
||||
const buildFiles = PLUGIN.buildSourcePatterns;
|
||||
|
||||
it('removes development properties from package.json', async () => {
|
||||
expect(PLUGIN.pkg.scripts).not.toBeUndefined();
|
||||
expect(PLUGIN.pkg.devDependencies).not.toBeUndefined();
|
||||
|
||||
await createBuild(PLUGIN, buildTarget, buildVersion, kibanaVersion, buildFiles);
|
||||
|
||||
const pkg = require(resolve(PLUGIN_BUILD_TARGET, 'package.json'));
|
||||
expect(pkg).not.toHaveProperty('scripts');
|
||||
expect(pkg).not.toHaveProperty('devDependencies');
|
||||
});
|
||||
|
||||
it('adds build metadata to package.json', async () => {
|
||||
expect(PLUGIN.pkg.build).toBeUndefined();
|
||||
|
||||
await createBuild(PLUGIN, buildTarget, buildVersion, kibanaVersion, buildFiles);
|
||||
|
||||
const pkg = require(resolve(PLUGIN_BUILD_TARGET, 'package.json'));
|
||||
expect(pkg).toHaveProperty('build');
|
||||
expect(pkg.build.git).not.toBeUndefined();
|
||||
expect(pkg.build.date).not.toBeUndefined();
|
||||
});
|
||||
});
|
|
@ -1,32 +0,0 @@
|
|||
/*eslint-env jest*/
|
||||
const { resolve } = require('path');
|
||||
const { statSync } = require('fs');
|
||||
const del = require('del');
|
||||
const createBuild = require('./create_build');
|
||||
const createPackage = require('./create_package');
|
||||
|
||||
const PLUGIN_FIXTURE = resolve(__dirname, '__fixtures__/create_package_test_plugin');
|
||||
const PLUGIN = require('../../lib/plugin_config')(PLUGIN_FIXTURE);
|
||||
const PLUGIN_BUILD_DIR = resolve(PLUGIN_FIXTURE, 'build-custom');
|
||||
|
||||
describe('create_build', () => {
|
||||
const buildVersion = PLUGIN.version;
|
||||
const kibanaVersion = PLUGIN.version;
|
||||
const buildFiles = PLUGIN.buildSourcePatterns;
|
||||
const packageFile = `${PLUGIN.id}-${buildVersion}.zip`;
|
||||
const doBuild = () => createBuild(PLUGIN, PLUGIN_BUILD_DIR, buildVersion, kibanaVersion, buildFiles);
|
||||
|
||||
beforeAll(() => del(PLUGIN_BUILD_DIR).then(doBuild));
|
||||
afterAll(() => del(PLUGIN_BUILD_DIR));
|
||||
|
||||
describe('creating the package', function () {
|
||||
it('creates zip file in build target path', function () {
|
||||
return createPackage(PLUGIN, PLUGIN_BUILD_DIR, buildVersion)
|
||||
.then(() => {
|
||||
const zipFile = resolve(PLUGIN_BUILD_DIR, packageFile);
|
||||
const stats = statSync(zipFile);
|
||||
expect(stats.isFile()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,28 @@
|
|||
const { resolve } = require('path');
|
||||
const { statSync } = require('fs');
|
||||
const del = require('del');
|
||||
const createBuild = require('./create_build');
|
||||
const createPackage = require('./create_package');
|
||||
|
||||
const PLUGIN_FIXTURE = resolve(__dirname, '__fixtures__/create_package_test_plugin');
|
||||
const PLUGIN = require('../../lib/plugin_config')(PLUGIN_FIXTURE);
|
||||
const PLUGIN_BUILD_DIR = resolve(PLUGIN_FIXTURE, 'build-custom');
|
||||
|
||||
const buildVersion = PLUGIN.version;
|
||||
const kibanaVersion = PLUGIN.version;
|
||||
const buildFiles = PLUGIN.buildSourcePatterns;
|
||||
const packageFile = `${PLUGIN.id}-${buildVersion}.zip`;
|
||||
|
||||
beforeAll(() => del(PLUGIN_BUILD_DIR));
|
||||
afterAll(() => del(PLUGIN_BUILD_DIR));
|
||||
|
||||
describe('creating the package', () => {
|
||||
it('creates zip file in build target path', async () => {
|
||||
await createBuild(PLUGIN, PLUGIN_BUILD_DIR, buildVersion, kibanaVersion, buildFiles);
|
||||
await createPackage(PLUGIN, PLUGIN_BUILD_DIR, buildVersion);
|
||||
|
||||
const zipFile = resolve(PLUGIN_BUILD_DIR, packageFile);
|
||||
const stats = statSync(zipFile);
|
||||
expect(stats.isFile()).toBe(true);
|
||||
});
|
||||
});
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue