(config, options = {})
| 715 | } |
| 716 | |
| 717 | async function createPlugins(config, options = {}) { |
| 718 | const plugins = {} |
| 719 | |
| 720 | const pluginOptionMap = new Map() |
| 721 | for (const token of (options.plugins || '').split(',').filter(Boolean)) { |
| 722 | const parts = token.split(':') |
| 723 | pluginOptionMap.set(parts[0], parts.slice(1)) |
| 724 | } |
| 725 | |
| 726 | for (const [name] of pluginOptionMap) { |
| 727 | if (!config[name]) config[name] = {} |
| 728 | } |
| 729 | |
| 730 | for (const pluginName in config) { |
| 731 | if (!config[pluginName]) config[pluginName] = {} |
| 732 | const pluginConfig = config[pluginName] |
| 733 | const enabledByCli = pluginOptionMap.has(pluginName) |
| 734 | if (!pluginConfig.enabled && !enabledByCli) { |
| 735 | continue // plugin is disabled |
| 736 | } |
| 737 | |
| 738 | if (enabledByCli && pluginOptionMap.get(pluginName).length > 0) { |
| 739 | pluginConfig._args = pluginOptionMap.get(pluginName) |
| 740 | } |
| 741 | |
| 742 | // Generic workers gate: |
| 743 | // - runInWorker / runInWorkers controls plugin execution inside worker threads. |
| 744 | // - runInParent / runInMain can disable plugin in workers parent process. |
| 745 | const runInWorker = pluginConfig.runInWorker ?? pluginConfig.runInWorkers ?? (pluginName === 'testomatio' ? false : true) |
| 746 | const runInParent = pluginConfig.runInParent ?? pluginConfig.runInMain ?? true |
| 747 | |
| 748 | if (!isMainThread && !runInWorker) { |
| 749 | continue |
| 750 | } |
| 751 | |
| 752 | if (isMainThread && store.workerMode && !runInParent) { |
| 753 | continue |
| 754 | } |
| 755 | let module |
| 756 | try { |
| 757 | if (pluginConfig.require) { |
| 758 | module = pluginConfig.require |
| 759 | if (module.startsWith('.')) { |
| 760 | // local |
| 761 | module = path.resolve(store.codeceptDir, module) // custom plugin |
| 762 | } |
| 763 | } else { |
| 764 | module = `./plugin/${pluginName}.js` |
| 765 | } |
| 766 | |
| 767 | // Use async loading for all plugins (ESM and CJS) |
| 768 | plugins[pluginName] = await loadPluginAsync(module, pluginConfig) |
| 769 | debug(`plugin ${pluginName} loaded via async import`) |
| 770 | } catch (err) { |
| 771 | throw new Error(`Could not load plugin ${pluginName} from module '${module}':\n${err.message}\n${err.stack}`) |
| 772 | } |
| 773 | } |
| 774 | return plugins |
no test coverage detected