Skip to content

Commit

Permalink
Autoload plugin : #562
Browse files Browse the repository at this point in the history
          - Throw error when more than one plugin tries to override the same taiko API
  • Loading branch information
negiDharmendra committed May 30, 2019
1 parent 374ef52 commit 2c8618a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/taiko.js
Expand Up @@ -2239,13 +2239,19 @@ const loadPlugin = (id, clientHandler) => {
module.exports.loadPlugin = loadPlugin;


const overriddenAPIs = {};
getPlugins().forEach( (pluginName) => {
let plugin = require(path.resolve(`node_modules/${pluginName}`));
loadPlugin(plugin.ID, plugin.clientHandler);
module.exports[plugin.ID] = plugin;
for( var api in plugin) {
if(module.exports.hasOwnProperty(api))
const isApiOverridden = overriddenAPIs.hasOwnProperty(api);
if(!isApiOverridden && module.exports.hasOwnProperty(api)) {
module.exports[api] = plugin[api];
overriddenAPIs[api] = pluginName;
} else if (isApiOverridden) {
throw new Error(`${pluginName} cannot override ${api} API as it has already been overridden by ${overriddenAPIs[api]}`);
}
}
});

Expand Down

0 comments on commit 2c8618a

Please sign in to comment.