diff --git a/docs/plugins.md b/docs/plugins.md index 2b65610e2..cefe73305 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -51,9 +51,9 @@ using the 'ngHint' plugin is shown below. }] ``` -Finally, if your plugin is a node module, you may use it with the `package` -option. For example, if you did `npm install example-protractor-plugin` your -config would look like: +If your plugin is a node module, you may use it with the `package` option. For +example, if you did `npm install example-protractor-plugin` your config would +look like: ```javascript plugins: [{ @@ -61,6 +61,19 @@ config would look like: }] ``` +Finally, if you are writing a small plugin which will only be used by one config +file, you can write the plugin inline into the config: + +```javascript + plugins: [{ + inline: { + setup: function() { ... }, + teardown: function() { ... }, + ... + } + }] +``` + Writing Plugins --------------- @@ -124,6 +137,8 @@ exports.postTest = function(config, passed) {}; exports.name = ''; ``` +Each of these exported properties are totally optional. + The protractor results object follows the format specified in the [Framework documentation](../lib/frameworks/README.md). diff --git a/lib/plugins.js b/lib/plugins.js index b921c946a..baa677d66 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -35,11 +35,15 @@ var Plugins = function(config) { } else { path = pluginConf.package; } - if (!path) { - throw new Error('Plugin configuration did not contain a valid path.'); + if (path) { + pluginConf.name = path; + self.pluginObjs.push(require(path)); + } else if(pluginConf.inline) { + self.pluginObjs.push(pluginConf.inline); + } else { + throw new Error('Plugin configuration did not contain a valid path or ' + + 'inline definition.'); } - pluginConf.name = path; - self.pluginObjs.push(require(path)); }); }; diff --git a/spec/plugins/basic_spec.js b/spec/plugins/basic_spec.js index 71d1d928d..d7cc1d1d0 100644 --- a/spec/plugins/basic_spec.js +++ b/spec/plugins/basic_spec.js @@ -2,8 +2,4 @@ describe('check if plugin setup ran', function() { it('should have set protractor.__BASIC_PLUGIN_RAN', function() { expect(protractor.__BASIC_PLUGIN_RAN).toBe(true); }); - - it('should run multiple tests', function() { - expect(true).toBe(true); - }); }); diff --git a/spec/plugins/bigger_spec.js b/spec/plugins/bigger_spec.js new file mode 100644 index 000000000..43d624c02 --- /dev/null +++ b/spec/plugins/bigger_spec.js @@ -0,0 +1,9 @@ +describe('check if plugin setup ran', function() { + it('should have set protractor.__BASIC_PLUGIN_RAN', function() { + expect(protractor.__BASIC_PLUGIN_RAN).toBe(true); + }); + + it('should have set protractor.__INLINE_PLUGIN_RAN', function() { + expect(protractor.__INLINE_PLUGIN_RAN).toBe(true); + }); +}); diff --git a/spec/pluginsFullConf.js b/spec/pluginsFullConf.js index e4cda91bf..7b36faabb 100644 --- a/spec/pluginsFullConf.js +++ b/spec/pluginsFullConf.js @@ -8,7 +8,7 @@ exports.config = { // Spec patterns are relative to this directory. specs: [ - 'plugins/basic_spec.js' + 'plugins/bigger_spec.js' ], capabilities: env.capabilities, @@ -25,5 +25,11 @@ exports.config = { path: 'plugins/basic_plugin.js' }, { path: 'plugins/test_plugin.js' + }, { + inline: { + setup: function() { + protractor.__INLINE_PLUGIN_RAN = true; + } + } }] };