wdio-lambdatest-service-sdk 5.1.3 → 5.1.4

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.
package/index.js CHANGED
@@ -1,10 +1,17 @@
1
1
  /**
2
2
  * WDIO LambdaTest service entry point.
3
3
  * Exposes the service class and launcher for WebdriverIO.
4
+ * Export shape supports both CommonJS and WDIO plugin resolution (default + launcher).
4
5
  */
5
6
  const LambdaTestService = require('./src/service');
6
7
  const LambdaTestLauncher = require('./src/launcher');
7
8
 
8
- module.exports = LambdaTestService;
9
- module.exports.default = LambdaTestService;
10
- module.exports.launcher = LambdaTestLauncher;
9
+ // Primary export: the worker service class (used by WDIO in worker process)
10
+ const Service = LambdaTestService;
11
+
12
+ // Attach launcher so WDIO can read plugin.launcher (main process)
13
+ Service.launcher = LambdaTestLauncher;
14
+ // ESM interop: some loaders expect plugin.default
15
+ Service.default = Service;
16
+
17
+ module.exports = Service;
@@ -163,19 +163,41 @@ function buildCapabilitiesMulti(config) {
163
163
  return capabilities;
164
164
  }
165
165
 
166
+ /**
167
+ * Resolve LambdaTest service path: try package name first (npm install), then sibling (reference repo).
168
+ * Reference repo layout: LT_Test/ (configs) and wdio-lambdatest-service/ as siblings.
169
+ */
170
+ function getServicePathSnippet() {
171
+ return `(function () {
172
+ try { return require.resolve('wdio-lambdatest-service'); } catch (e) {}
173
+ return path.join(__dirname, '../wdio-lambdatest-service');
174
+ })()`;
175
+ }
176
+
166
177
  /**
167
178
  * Build config file template string.
179
+ * Reference: LT_Test/ for configs, ../specs/ for specs, ../wdio-lambdatest-service or npm package for SDK.
168
180
  */
169
181
  function buildConfigTemplate(config, commonCaps, capabilities) {
182
+ const servicePathExpr = getServicePathSnippet();
183
+ const safeSpecPath = config.specPath.replace(/\\/g, '/');
184
+ const mergeSnippet = capabilities.length > 0
185
+ ? `
186
+ // Merge commonCapabilities into each capability
187
+ exports.config.capabilities.forEach(function (caps) {
188
+ for (const i in exports.config.commonCapabilities) {
189
+ caps[i] = caps[i] || exports.config.commonCapabilities[i];
190
+ }
191
+ });
192
+ `
193
+ : '';
194
+
170
195
  return `const path = require('path');
171
196
 
197
+ // LambdaTest WDIO config (generated). Layout: LT_Test/ for configs, ../specs/ for specs (see LT-appium-nodejs-webdriverio).
172
198
  exports.config = {
173
- // Authentication handled by SDK
174
- // user: "${config.username}",
175
- // key: "${config.key}",
176
-
177
199
  updateJob: false,
178
- specs: ["${config.specPath}"],
200
+ specs: ["${safeSpecPath}"],
179
201
  exclude: [],
180
202
 
181
203
  maxInstances: ${config.parallel > 0 ? config.parallel : 1},
@@ -196,9 +218,9 @@ exports.config = {
196
218
  port: 80,
197
219
 
198
220
  services: [
199
- [path.join(__dirname, '../wdio-lambdatest-service'), {
200
- user: "${config.username}",
201
- key: "${config.key}"
221
+ [${servicePathExpr}, {
222
+ user: "${(config.username || '').replace(/"/g, '\\"')}",
223
+ key: "${(config.key || '').replace(/"/g, '\\"')}"
202
224
  }]
203
225
  ],
204
226
 
@@ -208,14 +230,7 @@ exports.config = {
208
230
  timeout: 20000,
209
231
  },
210
232
  };
211
-
212
- // Merge commonCapabilities into each capability
213
- exports.config.capabilities.forEach(function (caps) {
214
- for (const i in exports.config.commonCapabilities) {
215
- caps[i] = caps[i] || exports.config.commonCapabilities[i];
216
- }
217
- });
218
- `;
233
+ ${mergeSnippet}`;
219
234
  }
220
235
 
221
236
  function printBanner() {
@@ -425,34 +440,33 @@ async function runGenerate() {
425
440
  ]);
426
441
  config.parallel = parallelAnswer.parallel || 0;
427
442
 
428
- // Spec file path
443
+ // Spec file path (reference repo: LT_Test and specs/ are siblings, so ../specs/ from LT_Test)
444
+ const defaultSpecPath = '../specs/android-test.js';
429
445
  const specAnswer = await inquirer.default.prompt([
430
446
  {
431
447
  type: 'input',
432
448
  name: 'specPath',
433
- message: 'Spec file path:',
434
- default: './specs/test.js'
449
+ message: 'Spec file path (relative to config dir, e.g. ../specs/android-test.js):',
450
+ default: defaultSpecPath
435
451
  }
436
452
  ]);
437
453
 
438
- let rawSpec = specAnswer.specPath.trim() || './specs/test.js';
454
+ let rawSpec = specAnswer.specPath.trim() || defaultSpecPath;
439
455
 
440
- // Smart resolve spec path relative to LT_Test
441
- if (fs.existsSync(path.resolve(outputDir, rawSpec))) {
442
- config.specPath = rawSpec;
456
+ // Resolve spec path relative to outputDir (LT_Test). Reference: specs/ at repo root = ../specs/ from LT_Test.
457
+ const fromOutputDir = path.resolve(outputDir, rawSpec);
458
+ if (fs.existsSync(fromOutputDir)) {
459
+ config.specPath = path.relative(outputDir, fromOutputDir).replace(/\\/g, '/') || rawSpec;
443
460
  } else {
444
461
  const rootPath = path.resolve(outputDir, '..');
445
462
  const relativeToRoot = rawSpec.replace(/^\.\//, '');
446
463
  const pathFromRoot = path.join(rootPath, relativeToRoot);
447
-
448
464
  if (fs.existsSync(pathFromRoot)) {
449
465
  config.specPath = path.relative(outputDir, pathFromRoot).replace(/\\/g, '/');
450
466
  } else {
451
- if (!path.isAbsolute(rawSpec) && !rawSpec.startsWith('../')) {
452
- config.specPath = '../' + relativeToRoot;
453
- } else {
454
- config.specPath = rawSpec;
455
- }
467
+ config.specPath = !path.isAbsolute(rawSpec) && !rawSpec.startsWith('../')
468
+ ? '../' + relativeToRoot
469
+ : rawSpec;
456
470
  }
457
471
  }
458
472
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wdio-lambdatest-service-sdk",
3
- "version": "5.1.3",
3
+ "version": "5.1.4",
4
4
  "description": "WebdriverIO service and CLI for LambdaTest Appium & browser automation",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/launcher.js CHANGED
@@ -47,22 +47,21 @@ function applyCredentialsToCapabilities(capabilities, credentials) {
47
47
  module.exports = class LambdaTestLauncher {
48
48
  constructor(serviceOptions, capabilities, config) {
49
49
  this.options = serviceOptions || {};
50
- console.log('[LambdaTest Service] Launcher initialized with options:', JSON.stringify(this.options));
51
50
  }
52
51
 
53
52
  onPrepare(config, capabilities) {
54
- console.log('[LambdaTest Service] Processing credentials...');
53
+ if (!config) return;
54
+ const capsList = Array.isArray(capabilities) ? capabilities : capabilities ? [capabilities] : [];
55
+ if (capsList.length === 0) return;
55
56
 
56
57
  const credentials = resolveCredentials(this.options, config);
57
58
  applyCredentialsToConfig(config, credentials);
58
-
59
- const capsList = Array.isArray(capabilities) ? capabilities : [capabilities];
60
59
  applyCredentialsToCapabilities(capsList, credentials);
61
60
 
62
61
  if (credentials.user && credentials.key) {
63
62
  console.log('[LambdaTest Service] Credentials injected into config and capabilities.');
64
63
  } else {
65
- console.error('[LambdaTest Service] Credentials not found! Please check service options or env vars.');
64
+ console.warn('[LambdaTest Service] Credentials not set. Use service options or LT_USERNAME / LT_ACCESS_KEY.');
66
65
  }
67
66
  }
68
67
  };