This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): basic tools for adding plugins
- Loading branch information
Showing
2 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var q = require('q'); | ||
|
||
/** | ||
* The plugin API for Protractor. Note that this API is extremely unstable | ||
* and current consists of only two functions: | ||
* <plugin>.setup - called before tests | ||
* <plugin>.teardown - called after tests | ||
* More information on plugins coming in the future | ||
* @constructor | ||
*/ | ||
var Plugins = function(config) { | ||
this.pluginConfs = config.plugins || {}; | ||
this.pluginObjs = {}; | ||
for (var name in this.pluginConfs) { | ||
this.pluginObjs[name] = require(this.pluginConfs[name].path); | ||
} | ||
}; | ||
|
||
var noop = function() {}; | ||
|
||
function pluginFunFactory(funName) { | ||
return function() { | ||
var promises = []; | ||
for (var name in this.pluginConfs) { | ||
var pluginConf = this.pluginConfs[name]; | ||
var pluginObj = this.pluginObjs[name]; | ||
promises.push((pluginObj[funName] || noop)(pluginConf)); | ||
} | ||
return q.all(promises); | ||
}; | ||
} | ||
|
||
/** | ||
* Sets up plugins before tests are run. | ||
* @return {q.Promise} A promise which resolves when the plugins have all been | ||
* set up. | ||
*/ | ||
Plugins.prototype.setup = pluginFunFactory('setup'); | ||
|
||
/** | ||
* Tears down plugins after tests are run. | ||
* @return {q.Promise} A promise which resolves when the plugins have all been | ||
* torn down. | ||
*/ | ||
Plugins.prototype.teardown = pluginFunFactory('teardown'); | ||
|
||
module.exports = Plugins; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters