mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
chore: canvas tasks - local tests
This commit is contained in:
parent
c200854f4a
commit
60ea466b1a
14 changed files with 174 additions and 3 deletions
|
@ -61,6 +61,7 @@ export const LICENSE_WHITELIST = [
|
|||
];
|
||||
|
||||
export const LICENSE_OVERRIDES = {
|
||||
'scriptjs@2.5.8': ['MIT'], // license header appended in the dist
|
||||
'react-lib-adler32@1.0.1': ['BSD'], // adler32 extracted from react source
|
||||
|
||||
// TODO can be removed once we upgrade past elasticsearch-browser@14.0.0
|
||||
|
|
|
@ -34,8 +34,10 @@
|
|||
"axios": "^0.18.0",
|
||||
"babel-jest": "^23.4.2",
|
||||
"babel-plugin-inline-react-svg": "^0.5.4",
|
||||
"babel-plugin-mock-imports": "^0.0.5",
|
||||
"babel-plugin-pegjs-inline-precompile": "^0.1.0",
|
||||
"babel-plugin-transform-react-remove-prop-types": "^0.4.14",
|
||||
"babel-register": "^6.26.0",
|
||||
"chalk": "^2.4.1",
|
||||
"chance": "1.0.10",
|
||||
"checksum": "0.1.1",
|
||||
|
@ -56,6 +58,7 @@
|
|||
"jest": "^23.5.0",
|
||||
"jest-cli": "^23.5.0",
|
||||
"jest-styled-components": "^6.1.1",
|
||||
"jsdom": "9.9.1",
|
||||
"mocha": "3.3.0",
|
||||
"mustache": "^2.3.0",
|
||||
"mutation-observer": "^1.0.3",
|
||||
|
|
|
@ -10,7 +10,12 @@
|
|||
"kbn": "node ../../../scripts/kbn",
|
||||
"start": "../../node_modules/.bin/gulp canvas:dev",
|
||||
"lint": "node ../../../scripts/eslint '*.js' '__tests__/**/*.js' 'tasks/**/*.js' 'server/**/*.js' 'common/**/*.js' 'public/**/*.{js,jsx}' 'canvas_plugin_src/**/*.{js,jsx}' --ignore-pattern 'canvas_plugin_src/lib/flot-charts/**/*' --ignore-pattern 'common/lib/grammar.js' --ignore-pattern 'canvas_plugin/**/*'",
|
||||
"test": "echo NOT READY; exit 1",
|
||||
"test": "../../node_modules/.bin/gulp canvas:test",
|
||||
"test:common": "../../node_modules/.bin/gulp canvas:test:common",
|
||||
"test:server": "../../node_modules/.bin/gulp canvas:test:server",
|
||||
"test:browser": "../../node_modules/.bin/gulp canvas:test:browser",
|
||||
"test:plugins": "../../node_modules/.bin/gulp canvas:test:plugins",
|
||||
"test:dev": "../../node_modules/.bin/gulp canvas:test:dev",
|
||||
"peg:build": "../../node_modules/.bin/gulp canvas:peg:build",
|
||||
"peg:dev": "../../node_modules/.bin/gulp canvas:peg:dev",
|
||||
"build": "echo Run build from x-pack root; exit 1",
|
||||
|
|
48
x-pack/plugins/canvas/tasks/helpers/babelhook.js
Normal file
48
x-pack/plugins/canvas/tasks/helpers/babelhook.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
const { resolve } = require('path');
|
||||
const register = require('babel-register');
|
||||
|
||||
const options = {
|
||||
sourceMaps: false,
|
||||
plugins: [
|
||||
[
|
||||
'mock-imports',
|
||||
[
|
||||
{
|
||||
pattern: 'scriptjs',
|
||||
location: resolve(__dirname, '..', 'mocks', 'noop'),
|
||||
},
|
||||
{
|
||||
pattern: 'ui/chrome',
|
||||
location: resolve(__dirname, '..', 'mocks', 'uiChrome'),
|
||||
},
|
||||
{
|
||||
pattern: 'ui/notify',
|
||||
location: resolve(__dirname, '..', 'mocks', 'uiNotify'),
|
||||
},
|
||||
{
|
||||
pattern: 'ui/url/absolute_to_parsed_url',
|
||||
location: resolve(__dirname, '..', 'mocks', 'absoluteToParsedUrl'),
|
||||
},
|
||||
{
|
||||
pattern: 'socket.io-client',
|
||||
location: resolve(__dirname, '..', 'mocks', 'socketClient'),
|
||||
},
|
||||
{
|
||||
// ugly hack so that importing non-js files works, required for the function docs
|
||||
pattern: '.(less|png|svg)$',
|
||||
location: resolve(__dirname, '..', 'mocks', 'noop'),
|
||||
},
|
||||
{
|
||||
pattern: 'plugins/canvas/apps',
|
||||
location: resolve(__dirname, '..', 'mocks', 'noop'),
|
||||
},
|
||||
{
|
||||
pattern: '/state/store',
|
||||
location: resolve(__dirname, '..', 'mocks', 'stateStore'),
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
};
|
||||
|
||||
register(options);
|
16
x-pack/plugins/canvas/tasks/helpers/dom_setup.js
Normal file
16
x-pack/plugins/canvas/tasks/helpers/dom_setup.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { JSDOM } from 'jsdom';
|
||||
import { APP_ROUTE } from '../../common/lib/constants';
|
||||
import chrome from '../mocks/uiChrome';
|
||||
|
||||
const basePath = chrome.getBasePath();
|
||||
const basename = `${basePath}${APP_ROUTE}`;
|
||||
|
||||
const { window } = new JSDOM('', {
|
||||
url: `http://localhost:5601/${basename}`,
|
||||
pretendToBeVisual: true,
|
||||
});
|
||||
global.window = window;
|
||||
global.document = window.document;
|
||||
global.navigator = window.navigator;
|
||||
global.requestAnimationFrame = window.requestAnimationFrame;
|
||||
global.HTMLElement = window.HTMLElement;
|
4
x-pack/plugins/canvas/tasks/helpers/enzyme_setup.js
Normal file
4
x-pack/plugins/canvas/tasks/helpers/enzyme_setup.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
import { configure } from 'enzyme';
|
||||
import Adapter from 'enzyme-adapter-react-16';
|
||||
|
||||
configure({ adapter: new Adapter() });
|
|
@ -1,13 +1,13 @@
|
|||
import dev from './dev';
|
||||
// import test from './test';
|
||||
import peg from './peg';
|
||||
import plugins from './plugins';
|
||||
import prepare from './prepare';
|
||||
import test from './test';
|
||||
|
||||
export default function canvasTasks(gulp, gulpHelpers) {
|
||||
dev(gulp, gulpHelpers);
|
||||
// test(gulp, gulpHelpers);
|
||||
peg(gulp, gulpHelpers);
|
||||
plugins(gulp, gulpHelpers);
|
||||
prepare(gulp, gulpHelpers);
|
||||
test(gulp, gulpHelpers);
|
||||
}
|
||||
|
|
4
x-pack/plugins/canvas/tasks/mocks/absoluteToParsedUrl.js
Normal file
4
x-pack/plugins/canvas/tasks/mocks/absoluteToParsedUrl.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export const absoluteToParsedUrl = () => {
|
||||
getAbsoluteUrl: () =>
|
||||
'http://localhost:5601/kbp/app/canvas#/workpad/workpad-24d56dad-ae70-42b8-9ef1-c5350ecd426c/page/1';
|
||||
}; // noop
|
1
x-pack/plugins/canvas/tasks/mocks/noop.js
Normal file
1
x-pack/plugins/canvas/tasks/mocks/noop.js
Normal file
|
@ -0,0 +1 @@
|
|||
export default function() {}
|
11
x-pack/plugins/canvas/tasks/mocks/socketClient.js
Normal file
11
x-pack/plugins/canvas/tasks/mocks/socketClient.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const noop = () => {};
|
||||
|
||||
// arguments: url, options
|
||||
// https://github.com/socketio/socket.io-client/blob/master/docs/API.md#iourl-options
|
||||
export default function mockIo() {
|
||||
return {
|
||||
on: noop,
|
||||
emit: noop,
|
||||
once: noop,
|
||||
};
|
||||
}
|
7
x-pack/plugins/canvas/tasks/mocks/stateStore.js
Normal file
7
x-pack/plugins/canvas/tasks/mocks/stateStore.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
export function getState() {
|
||||
return {
|
||||
assets: {
|
||||
yay: { value: 'here is your image' },
|
||||
},
|
||||
};
|
||||
}
|
4
x-pack/plugins/canvas/tasks/mocks/uiChrome.js
Normal file
4
x-pack/plugins/canvas/tasks/mocks/uiChrome.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export default {
|
||||
getBasePath: () => '/abc',
|
||||
trackSubUrlForApp: () => undefined, // noop
|
||||
};
|
11
x-pack/plugins/canvas/tasks/mocks/uiNotify.js
Normal file
11
x-pack/plugins/canvas/tasks/mocks/uiNotify.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const notifierProto = {
|
||||
error: msg => `error: ${msg}`,
|
||||
warning: msg => `warning: ${msg}`,
|
||||
info: msg => `info: ${msg}`,
|
||||
};
|
||||
|
||||
export class Notifier {
|
||||
constructor() {
|
||||
Object.assign(this, notifierProto);
|
||||
}
|
||||
}
|
56
x-pack/plugins/canvas/tasks/test.js
Normal file
56
x-pack/plugins/canvas/tasks/test.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { resolve, join } from 'path';
|
||||
|
||||
export default function testTasks(gulp, { mocha }) {
|
||||
const canvasRoot = resolve(__dirname, '..');
|
||||
|
||||
function runMocha(globs, { withEnzyme = false, withDOM = false } = {}) {
|
||||
const requires = [join(canvasRoot, 'tasks/helpers/babelhook')];
|
||||
|
||||
if (withDOM) requires.push(join(canvasRoot, 'tasks/helpers/dom_setup'));
|
||||
if (withEnzyme) requires.push(join(canvasRoot, 'tasks/helpers/enzyme_setup'));
|
||||
|
||||
return gulp.src(globs, { read: false }).pipe(
|
||||
mocha({
|
||||
ui: 'bdd',
|
||||
require: requires,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const getTestGlobs = rootPath => [
|
||||
join(canvasRoot, `${rootPath}/**/__tests__/**/*.js`),
|
||||
join(canvasRoot, `!${rootPath}/**/__tests__/fixtures/**/*.js`),
|
||||
];
|
||||
|
||||
const getRootGlobs = rootPath => [join(canvasRoot, `${rootPath}/**/*.js`)];
|
||||
|
||||
gulp.task('canvas:test:common', () => {
|
||||
return runMocha(getTestGlobs('common'), { withDOM: true });
|
||||
});
|
||||
|
||||
gulp.task('canvas:test:server', () => {
|
||||
return runMocha(getTestGlobs('server'));
|
||||
});
|
||||
|
||||
gulp.task('canvas:test:browser', () => {
|
||||
return runMocha(getTestGlobs('public'), { withEnzyme: true, withDOM: true });
|
||||
});
|
||||
|
||||
gulp.task('canvas:test:plugins', () => {
|
||||
return runMocha(getTestGlobs('canvas_plugin_src'));
|
||||
});
|
||||
|
||||
gulp.task('canvas:test', [
|
||||
'canvas:test:plugins',
|
||||
'canvas:test:common',
|
||||
'canvas:test:server',
|
||||
'canvas:test:browser',
|
||||
]);
|
||||
|
||||
gulp.task('canvas:test:dev', () => {
|
||||
gulp.watch(getRootGlobs('common'), ['canvas:test:common']);
|
||||
gulp.watch(getRootGlobs('server'), ['canvas:test:server']);
|
||||
gulp.watch(getRootGlobs('public'), ['canvas:test:browser']);
|
||||
gulp.watch(getRootGlobs('canvas_plugin_src'), ['canvas:test:plugins']);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue