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

Commit

Permalink
feat(plugins): inline plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
sjelin committed Mar 18, 2015
1 parent 1d8f14e commit 0f80696
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
21 changes: 18 additions & 3 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,29 @@ 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: [{
package: 'example-protractor-plugin',
}]
```

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
---------------

Expand Down Expand Up @@ -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).

Expand Down
12 changes: 8 additions & 4 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
};

Expand Down
4 changes: 0 additions & 4 deletions spec/plugins/basic_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
9 changes: 9 additions & 0 deletions spec/plugins/bigger_spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
8 changes: 7 additions & 1 deletion spec/pluginsFullConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,5 +25,11 @@ exports.config = {
path: 'plugins/basic_plugin.js'
}, {
path: 'plugins/test_plugin.js'
}, {
inline: {
setup: function() {
protractor.__INLINE_PLUGIN_RAN = true;
}
}
}]
};

0 comments on commit 0f80696

Please sign in to comment.