kibana/packages/kbn-plugin-helpers/lib/run.spec.js
Joe Fleming 0d621e778a Separate the task runner and the command line parser (elastic/kibana-plugin-helpers#25)
* remove conditionl require in runner

add tasks module to load all tasks, throw if task does not exist

* change task signatures and action handlers

- tasks get plugin, run, and an options object
- action handler controls what goes into each task
- taskRunner wrapper moves the command object to the first argument

* change test command signature

allow files to be passed in, and pass all options to test:server and test:browser

* simplify the task runner

* fix typo in unknownOptions

* expose the task runner as the module's main

this way tasks can be run programatically without going through a cli parser

* add tests for task runner

* remove file passing for testAll

* add serverTestPaths to the plugin config

useful for overriding the value via a config file

* [config] plugin.serverTestPaths -> plugin.serverTestPatterns

Original commit: elastic/kibana-plugin-helpers@82af4df64e
2016-12-16 01:06:02 -07:00

30 lines
No EOL
769 B
JavaScript

/*eslint-env jest*/
const testTask = jest.fn();
const plugin = { id: 'testPlugin' };
jest.mock('./plugin_config', () => () => plugin);
jest.mock('./tasks', () => {
return { testTask };
});
const run = require('./run');
describe('task runner', () => {
beforeEach(() => jest.resetAllMocks());
it('throw given an invalid task', function () {
const invalidTaskName = 'thisisnotavalidtasknameandneverwillbe';
const runner = () => run(invalidTaskName);
expect(runner).toThrow(/invalid task/i);
});
it('runs specified task with plugin and runner', function () {
run('testTask');
const args = testTask.mock.calls[0];
expect(testTask.mock.calls).toHaveLength(1);
expect(args[0]).toBe(plugin);
expect(args[1]).toBe(run);
});
});