Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from elastic/enh/control-tests
Browse files Browse the repository at this point in the history
Allow users to pass options to test runners to control which tests to run
  • Loading branch information
w33ble authored Dec 16, 2016
2 parents 846855e + 139221e commit 3bfc713
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
5 changes: 3 additions & 2 deletions bin/plugin-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ program

program
.command('test:browser')
.option('--dev', 'Enable dev mode, keeps the test server running')
.description('Run the browser tests in a real web browser')
.option('--dev', 'Enable dev mode, keeps the test server running')
.option('-p, --plugins <plugin-ids>', 'Manually specify which plugins\' test bundles to run')
.on('--help', docs('test/browser'))
.action(run('test/browser'));

program
.command('test:server')
.command('test:server [files...]')
.description('Run the server tests using mocha')
.on('--help', docs('test/server'))
.action(run('test/server'));
Expand Down
4 changes: 3 additions & 1 deletion lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports = function run(name) {
// call the action function with the plugin, then all
// renaining arguments from commander
var plugin = pluginConfig();
action.apply(null, [plugin, run].concat([].slice.apply(arguments)));
var args = [].slice.apply(arguments);

action.apply(null, [plugin, run].concat(args));
};
};
15 changes: 12 additions & 3 deletions tasks/test/browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ Browser tests are written just like server tests, they are just executed differe
starting the test runner
========================

Under the covers this command uses the `test:dev` task from kibana. This task sets-up
a test runner that will watch your code for changes and rebuild your tests when necessary.
You access the test runner through a browser that it starts itself (via Karma).
Under the covers this command uses the `test:browser` task from kibana. This will execute
your tasks once and exit when complete.

When run with the `--dev` option, the command uses the `test:dev` task from kibana.
This task sets-up a test runner that will watch your code for changes and rebuild your
tests when necessary. You access the test runner through a browser that it starts itself
(via Karma).

If your plugin consists of a number of internal plugins, you may wish to keep the tests
isolated to a specific plugin or plugins, instead of executing all of the tests. To do this,
use `--plugins` and passing the plugins you would like to test. Muliple plugins can be
specified by separating them with commas.


running the tests
Expand Down
7 changes: 6 additions & 1 deletion tasks/test/browser/test_browser_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ module.exports = function testBrowserAction(plugin, run, command) {
command = command || {};

var kbnServerArgs = [
'--kbnServer.testsBundle.pluginId=' + plugin.id,
'--kbnServer.plugin-path=' + plugin.root
];

if (command.plugins) {
kbnServerArgs.push('--kbnServer.testsBundle.pluginId=' + command.plugins);
} else {
kbnServerArgs.push('--kbnServer.testsBundle.pluginId=' + plugin.id);
}

var cmd = 'npm';
var task = (command.dev) ? 'test:dev' : 'test:browser';
var args = ['run', task, '--'].concat(kbnServerArgs);
Expand Down
9 changes: 9 additions & 0 deletions tasks/test/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ running the tests
Running the server tests is simple, just execute `npm run test:server` in your terminal
and all of the tests in your server will be run.

By default, the runner will look for tests in `server/**/__tests__/**/*.js`. If you'd prefer to
use a different collection of globs and files, you can specify them after the `npm run test:server`
task, like so:
`npm run test:server 'plugins/myplugins/server/__tests__/**/*.js'`
NOTE: quoting the glob pattern is not required, but helps to avoid issues with globbing expansion
in your shell.
focus on the task at hand
=========================
Expand Down
6 changes: 4 additions & 2 deletions tasks/test/server/test_server_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ var resolve = require('path').resolve;
var delimiter = require('path').delimiter;
var execFileSync = require('child_process').execFileSync;

module.exports = function (plugin) {
module.exports = function (plugin, run, files) {
var kibanaBins = resolve(plugin.kibanaRoot, 'node_modules/.bin');
var mochaSetupJs = resolve(plugin.kibanaRoot, 'test/mocha_setup.js');

var cmd = 'mocha';
var args = ['--require', mochaSetupJs, 'server/**/__tests__/**/*.js'];
var testPaths = (files.length) ? files : 'server/**/__tests__/**/*.js';
var args = ['--require', mochaSetupJs].concat(testPaths);
var path = `${kibanaBins}${delimiter}${process.env.PATH}`;

execFileSync(cmd, args, {
cwd: plugin.root,
stdio: ['ignore', 1, 2],
Expand Down

0 comments on commit 3bfc713

Please sign in to comment.