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

Commit 0f80696

Browse files
committed
feat(plugins): inline plugins
1 parent 1d8f14e commit 0f80696

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

docs/plugins.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,29 @@ using the 'ngHint' plugin is shown below.
5151
}]
5252
```
5353

54-
Finally, if your plugin is a node module, you may use it with the `package`
55-
option. For example, if you did `npm install example-protractor-plugin` your
56-
config would look like:
54+
If your plugin is a node module, you may use it with the `package` option. For
55+
example, if you did `npm install example-protractor-plugin` your config would
56+
look like:
5757

5858
```javascript
5959
plugins: [{
6060
package: 'example-protractor-plugin',
6161
}]
6262
```
6363

64+
Finally, if you are writing a small plugin which will only be used by one config
65+
file, you can write the plugin inline into the config:
66+
67+
```javascript
68+
plugins: [{
69+
inline: {
70+
setup: function() { ... },
71+
teardown: function() { ... },
72+
...
73+
}
74+
}]
75+
```
76+
6477
Writing Plugins
6578
---------------
6679

@@ -124,6 +137,8 @@ exports.postTest = function(config, passed) {};
124137
exports.name = '';
125138
```
126139

140+
Each of these exported properties are totally optional.
141+
127142
The protractor results object follows the format specified in
128143
the [Framework documentation](../lib/frameworks/README.md).
129144

lib/plugins.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ var Plugins = function(config) {
3535
} else {
3636
path = pluginConf.package;
3737
}
38-
if (!path) {
39-
throw new Error('Plugin configuration did not contain a valid path.');
38+
if (path) {
39+
pluginConf.name = path;
40+
self.pluginObjs.push(require(path));
41+
} else if(pluginConf.inline) {
42+
self.pluginObjs.push(pluginConf.inline);
43+
} else {
44+
throw new Error('Plugin configuration did not contain a valid path or ' +
45+
'inline definition.');
4046
}
41-
pluginConf.name = path;
42-
self.pluginObjs.push(require(path));
4347
});
4448
};
4549

spec/plugins/basic_spec.js

-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@ describe('check if plugin setup ran', function() {
22
it('should have set protractor.__BASIC_PLUGIN_RAN', function() {
33
expect(protractor.__BASIC_PLUGIN_RAN).toBe(true);
44
});
5-
6-
it('should run multiple tests', function() {
7-
expect(true).toBe(true);
8-
});
95
});

spec/plugins/bigger_spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
describe('check if plugin setup ran', function() {
2+
it('should have set protractor.__BASIC_PLUGIN_RAN', function() {
3+
expect(protractor.__BASIC_PLUGIN_RAN).toBe(true);
4+
});
5+
6+
it('should have set protractor.__INLINE_PLUGIN_RAN', function() {
7+
expect(protractor.__INLINE_PLUGIN_RAN).toBe(true);
8+
});
9+
});

spec/pluginsFullConf.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exports.config = {
88

99
// Spec patterns are relative to this directory.
1010
specs: [
11-
'plugins/basic_spec.js'
11+
'plugins/bigger_spec.js'
1212
],
1313

1414
capabilities: env.capabilities,
@@ -25,5 +25,11 @@ exports.config = {
2525
path: 'plugins/basic_plugin.js'
2626
}, {
2727
path: 'plugins/test_plugin.js'
28+
}, {
29+
inline: {
30+
setup: function() {
31+
protractor.__INLINE_PLUGIN_RAN = true;
32+
}
33+
}
2834
}]
2935
};

0 commit comments

Comments
 (0)