@wdio/utils 8.0.8 → 8.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"initialiseServices.d.ts","sourceRoot":"","sources":["../src/initialiseServices.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAqFlE;;;;;;;GAOG;AACH,wBAAsB,yBAAyB,CAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,cAAc,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,mBAAmB;;;GAiDvK;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CACzC,MAAM,EAAE,OAAO,CAAC,UAAU,EAC1B,IAAI,EAAE,YAAY,CAAC,mBAAmB,EACtC,qBAAqB,GAAE,MAAM,EAAO,GACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,CA6BrC"}
1
+ {"version":3,"file":"initialiseServices.d.ts","sourceRoot":"","sources":["../src/initialiseServices.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAqFlE;;;;;;;GAOG;AACH,wBAAsB,yBAAyB,CAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,cAAc,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,mBAAmB;;;GAmDvK;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CACzC,MAAM,EAAE,OAAO,CAAC,UAAU,EAC1B,IAAI,EAAE,YAAY,CAAC,mBAAmB,EACtC,qBAAqB,GAAE,MAAM,EAAO,GACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,CA+BrC"}
@@ -76,6 +76,7 @@ function sanitizeServiceArray(service) {
76
76
  export async function initialiseLauncherService(config, caps) {
77
77
  const ignoredWorkerServices = [];
78
78
  const launcherServices = [];
79
+ let serviceLabelToBeInitialised = 'unknown';
79
80
  try {
80
81
  const services = await initialiseServices(config.services.map(sanitizeServiceArray));
81
82
  for (const [service, serviceConfig, serviceName] of services) {
@@ -83,6 +84,7 @@ export async function initialiseLauncherService(config, caps) {
83
84
  * add custom services as object or function
84
85
  */
85
86
  if (typeof service === 'object' && !serviceName) {
87
+ serviceLabelToBeInitialised = 'object';
86
88
  launcherServices.push(service);
87
89
  continue;
88
90
  }
@@ -91,16 +93,19 @@ export async function initialiseLauncherService(config, caps) {
91
93
  */
92
94
  const Launcher = service.launcher;
93
95
  if (typeof Launcher === 'function' && serviceName) {
96
+ serviceLabelToBeInitialised = `"${serviceName}"`;
94
97
  launcherServices.push(new Launcher(serviceConfig, caps, config));
95
98
  }
96
99
  /**
97
100
  * add class service from passed in class
98
101
  */
99
102
  if (typeof service === 'function' && !serviceName) {
103
+ serviceLabelToBeInitialised = `"${service.constructor?.name || service.toString()}"`;
100
104
  launcherServices.push(new service(serviceConfig, caps, config));
101
105
  }
102
106
  /**
103
- * check if service has a default export
107
+ * check if service has a default export, if not we can later filter it out so the
108
+ * service module is not even loaded in the worker process
104
109
  */
105
110
  if (serviceName &&
106
111
  typeof service.default !== 'function' &&
@@ -110,10 +115,7 @@ export async function initialiseLauncherService(config, caps) {
110
115
  }
111
116
  }
112
117
  catch (err) {
113
- /**
114
- * don't break if service can't be initiated
115
- */
116
- log.error(err);
118
+ throw new Error(`Failed to initilialise launcher service ${serviceLabelToBeInitialised}: ${err.stack}`);
117
119
  }
118
120
  return { ignoredWorkerServices, launcherServices };
119
121
  }
@@ -126,29 +128,32 @@ export async function initialiseLauncherService(config, caps) {
126
128
  * @return {Object[]} list if worker initiated worker services
127
129
  */
128
130
  export async function initialiseWorkerService(config, caps, ignoredWorkerServices = []) {
131
+ let serviceLabelToBeInitialised = 'unknown';
132
+ const initialisedServices = [];
129
133
  const workerServices = config.services
130
134
  .map(sanitizeServiceArray)
131
135
  .filter(([serviceName]) => !ignoredWorkerServices.includes(serviceName));
132
136
  try {
133
137
  const services = await initialiseServices(workerServices);
134
- return services.map(([service, serviceConfig, serviceName]) => {
138
+ for (const [service, serviceConfig, serviceName] of services) {
135
139
  /**
136
140
  * add object service
137
141
  */
138
142
  if (typeof service === 'object' && !serviceName) {
139
- return service;
143
+ serviceLabelToBeInitialised = 'object';
144
+ initialisedServices.push(service);
145
+ continue;
140
146
  }
141
147
  const Service = service.default || service;
142
148
  if (typeof Service === 'function') {
143
- return new Service(serviceConfig, caps, config);
149
+ serviceLabelToBeInitialised = serviceName || Service.constructor?.name || Service.toString();
150
+ initialisedServices.push(new Service(serviceConfig, caps, config));
151
+ continue;
144
152
  }
145
- }).filter((service) => Boolean(service));
153
+ }
154
+ return initialisedServices;
146
155
  }
147
156
  catch (err) {
148
- /**
149
- * don't break if service can't be initiated
150
- */
151
- log.error(err);
152
- return [];
157
+ throw new Error(`Failed to initilialise service ${serviceLabelToBeInitialised}: ${err.stack}`);
153
158
  }
154
159
  }
package/build/shim.d.ts CHANGED
@@ -13,7 +13,7 @@ declare global {
13
13
  }
14
14
  }
15
15
  }
16
- declare let executeHooksWithArgs: <T>(hookName: string, hooks?: Function | Function[], args?: any[]) => Promise<(Error | T)[]>;
16
+ declare let executeHooksWithArgs: <T>(this: any, hookName: string, hooks?: Function | Function[], args?: any[]) => Promise<(Error | T)[]>;
17
17
  /**
18
18
  * wrap command to enable before and after command to be executed
19
19
  * @param commandName name of the command (e.g. getTitle)
@@ -1 +1 @@
1
- {"version":3,"file":"shim.d.ts","sourceRoot":"","sources":["../src/shim.ts"],"names":[],"mappings":"AAQA,UAAU,OAAO;IACb,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,OAAO,CAAC,MAAM,CAAC;IACX,IAAI,WAAW,EAAE,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AAG,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAmBzG;AAED,OAAO,EACH,oBAAoB,EACpB,WAAW,EACX,YAAY,GACf,CAAA"}
package/build/shim.js CHANGED
@@ -28,7 +28,7 @@ let executeHooksWithArgs = async function executeHooksWithArgsShim(hookName, hoo
28
28
  const hooksPromises = hooks.map((hook) => new Promise((resolve) => {
29
29
  let result;
30
30
  try {
31
- result = hook.apply(null, args);
31
+ result = hook.apply(this, args);
32
32
  }
33
33
  catch (e) {
34
34
  log.error(e.stack);
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAW,MAAM,aAAa,CAAA;AAQpD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE;IAAE,sBAAsB,CAAC,EAAE;QAAE,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,QAsCzH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,UA+BrE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAE,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;;;EAapF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,WA8B/D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAE,GAAG,EAAE,GAAG,wGAExC;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,aAAa,GAAG,IAAI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;;;GAGG;AACH,wBAAgB,cAAc,CAAE,IAAI,EAAE,GAAG,EAAE,SAE1C;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,WAanC;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,UAAW,MAAM,YAWtC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,mCAAoD,CAAA"}
package/build/utils.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
- import { createRequire } from 'node:module';
5
- const require = createRequire(import.meta.url);
4
+ import { resolve } from 'import-meta-resolve';
6
5
  const SCREENSHOT_REPLACEMENT = '"<Screenshot[base64]>"';
7
6
  const SCRIPT_PLACEHOLDER = '"<Script[base64]>"';
8
7
  const REGEX_SCRIPT_NAME = /return \(function (\w+)/;
@@ -149,44 +148,43 @@ export function getArgumentType(arg) {
149
148
  * @return {object} package content
150
149
  */
151
150
  export async function safeImport(name) {
152
- let requirePath = name;
151
+ console.info('AHHH', name);
152
+ let importPath = name;
153
153
  try {
154
154
  /**
155
- * Check if cli command was called from local directory, if not require
156
- * the plugin from the place where the command is called. This avoids
157
- * issues where user have the @wdio/cli package installed globally
158
- * but run on a project where wdio packages are installed locally. It
159
- * also allows to link the package to a random place and have plugins
160
- * imported correctly (for dev purposes).
155
+ * Initially we will search for the package by using the standard package
156
+ * resolution starting from the path given by 'import.meta.url' (which
157
+ * returns the path to this file). The default mechanism will then search
158
+ * upwards through the hierarchy in the file system in node_modules directories
159
+ * until it finds the package or reaches the root of the file system.
160
+ *
161
+ * In the case where a user has installed the @wdio/cli package globally,
162
+ * then clearly the search will be performed in the global area and not
163
+ * in the project specific area. Consequently, if the package we are
164
+ * looking for is installed within the project it will not be found and
165
+ * then we also need to search in the project, we do that by defining
166
+ * 'localNodeModules' and searching from that also.
167
+ *
168
+ * Note that import-meta-resolve will resolve to CJS no ESM export is found
161
169
  */
162
170
  const localNodeModules = path.join(process.cwd(), 'node_modules');
163
- /* istanbul ignore if */
164
- if (!require.resolve.paths(name)?.includes(localNodeModules)) {
165
- const resolveLocation = [
166
- ...(require.resolve.paths(name) || []),
167
- localNodeModules
168
- ];
169
- /**
170
- * don't set requireOpts when running unit tests as it
171
- * confuses Jest require magic
172
- */
173
- const requireOpts = process.env.VITEST_WORKER_ID
174
- ? {}
175
- : { paths: resolveLocation };
176
- requirePath = require.resolve(name, requireOpts);
177
- }
178
- else {
179
- requirePath = require.resolve(name);
171
+ try {
172
+ importPath = await resolve(name, import.meta.url);
180
173
  }
181
- if (!requirePath.startsWith('file://')) {
182
- requirePath = pathToFileURL(requirePath).href;
174
+ catch (err) {
175
+ try {
176
+ importPath = await resolve(name, pathToFileURL(localNodeModules).toString());
177
+ }
178
+ catch (err) {
179
+ return null;
180
+ }
183
181
  }
184
182
  }
185
183
  catch (err) {
186
184
  return null;
187
185
  }
188
186
  try {
189
- const pkg = await import(requirePath);
187
+ const pkg = await import(importPath);
190
188
  /**
191
189
  * CJS packages build with TS imported through an ESM context can end up being this:
192
190
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/utils",
3
- "version": "8.0.8",
3
+ "version": "8.0.10",
4
4
  "description": "A WDIO helper utility to provide several utility functions used across the project.",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-utils",
@@ -28,11 +28,12 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@wdio/logger": "8.0.0",
31
- "@wdio/types": "8.0.8",
31
+ "@wdio/types": "8.0.10",
32
+ "import-meta-resolve": "^2.2.0",
32
33
  "p-iteration": "^1.1.8"
33
34
  },
34
35
  "publishConfig": {
35
36
  "access": "public"
36
37
  },
37
- "gitHead": "c07255fefc67137fd27f23da5f0792c10157f8c0"
38
+ "gitHead": "1c350a14144ecc5f1ebc598c385bae6aa80739c3"
38
39
  }