MCPcopy Create free account
hub / github.com/webdriverio/webdriverio / initializePlugin

Function initializePlugin

packages/wdio-utils/src/initializePlugin.ts:13–51  ·  view source on GitHub ↗
(name: string, type?: string)

Source from the content-addressed store, hash-verified

11 * 3. otherwise try to require "wdio-<name>-<type>"
12 */
13export default async function initializePlugin (name: string, type?: string): Promise<Services.ServicePlugin | Services.RunnerPlugin> {
14 /**
15 * directly import packages that are scoped or start with an absolute path
16 */
17 if (name[0] === '@' || isAbsolute(name)) {
18 const fileUrl = name[0] === '@' ? name : ensureFileURL(name)
19 const service = await safeImport(fileUrl)
20
21 if (service) {
22 return service
23 }
24 }
25
26 if (typeof type !== 'string') {
27 throw new Error('No plugin type provided')
28 }
29
30 /**
31 * check for scoped version of plugin first (e.g. @wdio/sauce-service)
32 */
33 const scopedPlugin = await safeImport(`@wdio/${name.toLowerCase()}-${type}`)
34 if (scopedPlugin) {
35 return scopedPlugin
36 }
37
38 /**
39 * check for old type of
40 */
41 const plugin = await safeImport(`wdio-${name.toLowerCase()}-${type}`)
42 if (plugin) {
43 return plugin
44 }
45
46 throw new Error(
47 `Couldn't find plugin "${name}" ${type}, neither as wdio scoped package `+
48 `"@wdio/${name.toLowerCase()}-${type}" nor as community package ` +
49 `"wdio-${name.toLowerCase()}-${type}". Please make sure you have it installed!`
50 )
51}
52
53function ensureFileURL(path:string) {
54 if (path.startsWith(FILE_PROTOCOL)) {

Callers 5

runMethod · 0.90
#initFrameworkMethod · 0.90
_loadReporterMethod · 0.90
initializeServicesFunction · 0.85

Calls 3

isAbsoluteFunction · 0.85
ensureFileURLFunction · 0.85
safeImportFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…