wdio-lambdatest-service-sdk 5.0.0 → 5.1.0
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/README.md +339 -36
- package/bin/cli.js +86 -0
- package/bin/generate-config.js +14 -166
- package/bin/setup.js +14 -128
- package/bin/wdio-lt.js +39 -0
- package/bun.lock +875 -0
- package/index.js +4 -5
- package/lib/cli/generate.js +526 -0
- package/lib/cli/setup.js +174 -0
- package/lib/cli/style.js +57 -0
- package/package.json +24 -4
- package/src/launcher.js +52 -29
- package/src/service.js +36 -40
package/bin/setup.js
CHANGED
|
@@ -1,129 +1,15 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
console.
|
|
14
|
-
|
|
15
|
-
const rl = readline.createInterface({
|
|
16
|
-
input: process.stdin,
|
|
17
|
-
output: process.stdout
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
rl.question('Where are your test scripts located? (e.g. ./android-sample): ', (answer) => {
|
|
21
|
-
if (!answer || answer.trim() === '') {
|
|
22
|
-
console.error('No directory provided. Exiting.');
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const resolvedPath = path.resolve(answer.trim());
|
|
27
|
-
console.log(`Scanning: ${resolvedPath}`);
|
|
28
|
-
|
|
29
|
-
traverseDirectory(resolvedPath);
|
|
30
|
-
console.log('Done scanning directories.');
|
|
31
|
-
rl.close();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function traverseDirectory(dir) {
|
|
37
|
-
if (!fs.existsSync(dir)) {
|
|
38
|
-
console.error(`Directory not found: ${dir}`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const files = fs.readdirSync(dir);
|
|
43
|
-
|
|
44
|
-
files.forEach(file => {
|
|
45
|
-
const fullPath = path.join(dir, file);
|
|
46
|
-
const stat = fs.statSync(fullPath);
|
|
47
|
-
|
|
48
|
-
if (stat.isDirectory()) {
|
|
49
|
-
if (file !== 'node_modules' && file !== '.git') {
|
|
50
|
-
traverseDirectory(fullPath);
|
|
51
|
-
}
|
|
52
|
-
} else if (file.endsWith('.conf.js')) {
|
|
53
|
-
updateConfigFile(fullPath);
|
|
54
|
-
}
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* LambdaTest WDIO Setup - Backward-compatible entry point.
|
|
4
|
+
* Delegates to lib/cli/setup.js
|
|
5
|
+
*
|
|
6
|
+
* Usage: wdio-lambdatest-setup [path]
|
|
7
|
+
*/
|
|
8
|
+
const chalk = require('chalk');
|
|
9
|
+
const { runSetup } = require('../lib/cli/setup');
|
|
10
|
+
|
|
11
|
+
runSetup(process.argv[2])
|
|
12
|
+
.catch((e) => {
|
|
13
|
+
console.error(chalk.red.bold('\n✖ Error:'), e.message);
|
|
14
|
+
process.exit(1);
|
|
55
15
|
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function updateConfigFile(filePath) {
|
|
59
|
-
let content = fs.readFileSync(filePath, 'utf8');
|
|
60
|
-
|
|
61
|
-
console.log(`Processing: ${filePath}`);
|
|
62
|
-
|
|
63
|
-
// Extract credentials (either active or commented out)
|
|
64
|
-
let userVal = "process.env.LT_USERNAME";
|
|
65
|
-
let keyVal = "process.env.LT_ACCESS_KEY";
|
|
66
|
-
|
|
67
|
-
const userMatch = content.match(/^\s*\/{0,2}\s*user:\s*(.*?),/m);
|
|
68
|
-
if (userMatch) userVal = userMatch[1].trim();
|
|
69
|
-
|
|
70
|
-
const keyMatch = content.match(/^\s*\/{0,2}\s*key:\s*(.*?),/m);
|
|
71
|
-
if (keyMatch) keyVal = keyMatch[1].trim();
|
|
72
|
-
|
|
73
|
-
// Calculate relative path
|
|
74
|
-
let relativeSdkPath = path.relative(path.dirname(filePath), sdkPath);
|
|
75
|
-
relativeSdkPath = relativeSdkPath.replace(/\\/g, '/');
|
|
76
|
-
|
|
77
|
-
// Construct the correct service entry with credentials
|
|
78
|
-
const serviceEntry = `[path.join(__dirname, '${relativeSdkPath}'), { user: ${userVal}, key: ${keyVal} }]`;
|
|
79
|
-
|
|
80
|
-
// Check if already updated (but maybe with missing credentials)
|
|
81
|
-
if (content.includes('wdio-lambdatest-service')) {
|
|
82
|
-
// Fix empty options if present: [path..., {}]
|
|
83
|
-
const emptyOptionsRegex = /\[path\.join\(__dirname, '.*?wdio-lambdatest-service'\), \{\}\]/;
|
|
84
|
-
if (emptyOptionsRegex.test(content)) {
|
|
85
|
-
console.log(`Fixing missing credentials in: ${filePath}`);
|
|
86
|
-
content = content.replace(emptyOptionsRegex, serviceEntry);
|
|
87
|
-
|
|
88
|
-
// Ensure logLevel is error
|
|
89
|
-
content = content.replace(/logLevel: ['"]info['"]/, "logLevel: 'error'");
|
|
90
|
-
|
|
91
|
-
fs.writeFileSync(filePath, content);
|
|
92
|
-
console.log(`Successfully repaired ${filePath}`);
|
|
93
|
-
} else {
|
|
94
|
-
console.log(`Skipping (already correct): ${filePath}`);
|
|
95
|
-
}
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
console.log(`Updating: ${filePath}`);
|
|
100
|
-
|
|
101
|
-
// 1. Ensure 'path' module is required
|
|
102
|
-
if (!content.includes("require('path')")) {
|
|
103
|
-
content = "const path = require('path');\n" + content;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// 3. Inject Services
|
|
107
|
-
if (content.includes('services: [')) {
|
|
108
|
-
content = content.replace('services: [', `services: [\n ${serviceEntry},`);
|
|
109
|
-
} else {
|
|
110
|
-
content = content.replace('exports.config = {', `exports.config = {\n services: [\n ${serviceEntry}\n ],`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// 4. Set logLevel to 'error'
|
|
114
|
-
if (content.includes('logLevel:')) {
|
|
115
|
-
content = content.replace(/logLevel:.*,/, "logLevel: 'error',");
|
|
116
|
-
} else {
|
|
117
|
-
content = content.replace('exports.config = {', `exports.config = {\n logLevel: 'error',`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 5. Comment out hardcoded user/key
|
|
121
|
-
// Use replace with callback to avoid re-commenting
|
|
122
|
-
content = content.replace(/^(\s*)user:/gm, '$1// user:');
|
|
123
|
-
content = content.replace(/^(\s*)key:/gm, '$1// key:');
|
|
124
|
-
|
|
125
|
-
fs.writeFileSync(filePath, content);
|
|
126
|
-
console.log(`Successfully updated ${filePath}`);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
start();
|
package/bin/wdio-lt.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawn } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
const command = args[0];
|
|
7
|
+
|
|
8
|
+
if (!command || command === '--help' || command === '-h') {
|
|
9
|
+
console.log(`
|
|
10
|
+
Usage: wdio-lt <command> [options]
|
|
11
|
+
|
|
12
|
+
Commands:
|
|
13
|
+
init Initialize LambdaTest SDK in existing config files
|
|
14
|
+
generate Generate a new WebdriverIO configuration file
|
|
15
|
+
|
|
16
|
+
Options:
|
|
17
|
+
--help, -h Show help
|
|
18
|
+
`);
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let scriptPath;
|
|
23
|
+
|
|
24
|
+
if (command === 'init') {
|
|
25
|
+
scriptPath = path.join(__dirname, 'setup.js');
|
|
26
|
+
} else if (command === 'generate') {
|
|
27
|
+
scriptPath = path.join(__dirname, 'generate-config.js');
|
|
28
|
+
} else {
|
|
29
|
+
console.error(`Unknown command: ${command}`);
|
|
30
|
+
console.log('Run "wdio-lt --help" for available commands');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// execute the script
|
|
35
|
+
const child = spawn('node', [scriptPath, ...args.slice(1)], { stdio: 'inherit' });
|
|
36
|
+
|
|
37
|
+
child.on('close', (code) => {
|
|
38
|
+
process.exit(code);
|
|
39
|
+
});
|