@wdio/cli 7.20.7 → 7.20.8-alpha.504

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/bin/wdio.js CHANGED
@@ -8,4 +8,10 @@ if (process.env.NODE_ENV == null) {
8
8
  process.env.NODE_ENV = 'test'
9
9
  }
10
10
 
11
- require('../build').run()
11
+ /**
12
+ * use IIFE to allow running this within CJS and ESM context
13
+ */
14
+ (async () => {
15
+ const cli = await import('../build/index.js')
16
+ return cli.run()
17
+ })()
@@ -1,5 +1,5 @@
1
- import { ConfigCommandArguments, ParsedAnswers } from '../types';
2
- import yargs from 'yargs';
1
+ import type { Argv } from 'yargs';
2
+ import type { ConfigCommandArguments, ParsedAnswers } from '../types';
3
3
  export declare const command = "config";
4
4
  export declare const desc = "Initialize WebdriverIO and setup configuration in your current project.";
5
5
  export declare const cmdArgs: {
@@ -15,7 +15,7 @@ export declare const cmdArgs: {
15
15
  readonly default: false;
16
16
  };
17
17
  };
18
- export declare const builder: (yargs: yargs.Argv<{}>) => yargs.Argv<yargs.Omit<{}, "yarn" | "yes"> & yargs.InferredOptionTypes<{
18
+ export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "yarn" | "yes"> & import("yargs").InferredOptionTypes<{
19
19
  readonly yarn: {
20
20
  readonly type: "boolean";
21
21
  readonly desc: "Install packages via yarn package manager.";
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAChE,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAO,MAAM,OAAO,WAAW,CAAA;AAC/B,eAAO,MAAM,IAAI,4EAA4E,CAAA;AAE7F,eAAO,MAAM,OAAO;;;;;;;;;;;;CAYV,CAAA;AAEV,eAAO,MAAM,OAAO;;;;;;;;;;;;GAKnB,CAAA;AA4MD,wBAAgB,OAAO,CAAC,IAAI,EAAE,sBAAsB;;;;;;;;GAEnD;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,UAAQ,EAAE,YAAY;;;;;;;;EAAY;;;;;;;;GAqB3H"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAcjC,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAErE,eAAO,MAAM,OAAO,WAAW,CAAA;AAC/B,eAAO,MAAM,IAAI,4EAA4E,CAAA;AAE7F,eAAO,MAAM,OAAO;;;;;;;;;;;;CAYV,CAAA;AAEV,eAAO,MAAM,OAAO,UAAW,IAAI;;;;;;;;;;;;GAKlC,CAAA;AAiMD,wBAAgB,OAAO,CAAC,IAAI,EAAE,sBAAsB;;;;;;;;GAEnD;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,UAAQ,EAAE,YAAY;;;;;;;;EAAY;;;;;;;;GA4B3H"}
@@ -1,24 +1,17 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.missingConfigurationPrompt = exports.handler = exports.builder = exports.cmdArgs = exports.desc = exports.command = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
9
- const util_1 = __importDefault(require("util"));
10
- const inquirer_1 = __importDefault(require("inquirer"));
11
- const yarn_install_1 = __importDefault(require("yarn-install"));
12
- const constants_1 = require("../constants");
13
- const utils_1 = require("../utils");
14
- const pkg = require('../../package.json');
15
- exports.command = 'config';
16
- exports.desc = 'Initialize WebdriverIO and setup configuration in your current project.';
17
- exports.cmdArgs = {
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import util from 'node:util';
4
+ import inquirer from 'inquirer';
5
+ import yarnInstall from 'yarn-install';
6
+ import { CONFIG_HELPER_INTRO, CLI_EPILOGUE, COMPILER_OPTIONS, TS_COMPILER_INSTRUCTIONS, SUPPORTED_PACKAGES, CONFIG_HELPER_SUCCESS_MESSAGE, DEPENDENCIES_INSTALLATION_MESSAGE, pkg } from '../constants.js';
7
+ import { addServiceDeps, convertPackageHashToObject, renderConfigurationFile, hasFile, generateTestFiles, getAnswers, getPathForFileGeneration, hasPackage, specifyVersionIfNeeded } from '../utils.js';
8
+ export const command = 'config';
9
+ export const desc = 'Initialize WebdriverIO and setup configuration in your current project.';
10
+ export const cmdArgs = {
18
11
  yarn: {
19
12
  type: 'boolean',
20
13
  desc: 'Install packages via yarn package manager.',
21
- default: (0, utils_1.hasFile)('yarn.lock')
14
+ default: hasFile('yarn.lock')
22
15
  },
23
16
  yes: {
24
17
  alias: 'y',
@@ -27,21 +20,20 @@ exports.cmdArgs = {
27
20
  default: false
28
21
  }
29
22
  };
30
- const builder = (yargs) => {
23
+ export const builder = (yargs) => {
31
24
  return yargs
32
- .options(exports.cmdArgs)
33
- .epilogue(constants_1.CLI_EPILOGUE)
25
+ .options(cmdArgs)
26
+ .epilogue(CLI_EPILOGUE)
34
27
  .help();
35
28
  };
36
- exports.builder = builder;
37
29
  const runConfig = async function (useYarn, yes, exit = false) {
38
- console.log(constants_1.CONFIG_HELPER_INTRO);
39
- const answers = await (0, utils_1.getAnswers)(yes);
40
- const frameworkPackage = (0, utils_1.convertPackageHashToObject)(answers.framework);
41
- const runnerPackage = (0, utils_1.convertPackageHashToObject)(answers.runner || constants_1.SUPPORTED_PACKAGES.runner[0].value);
42
- const servicePackages = answers.services.map((service) => (0, utils_1.convertPackageHashToObject)(service));
43
- const pluginPackages = answers.plugins.map((plugin) => (0, utils_1.convertPackageHashToObject)(plugin));
44
- const reporterPackages = answers.reporters.map((reporter) => (0, utils_1.convertPackageHashToObject)(reporter));
30
+ console.log(CONFIG_HELPER_INTRO);
31
+ const answers = await getAnswers(yes);
32
+ const frameworkPackage = convertPackageHashToObject(answers.framework);
33
+ const runnerPackage = convertPackageHashToObject(answers.runner || SUPPORTED_PACKAGES.runner[0].value);
34
+ const servicePackages = answers.services.map((service) => convertPackageHashToObject(service));
35
+ const pluginPackages = answers.plugins.map((plugin) => convertPackageHashToObject(plugin));
36
+ const reporterPackages = answers.reporters.map((reporter) => convertPackageHashToObject(reporter));
45
37
  let packagesToInstall = [
46
38
  runnerPackage.package,
47
39
  frameworkPackage.package,
@@ -52,7 +44,7 @@ const runConfig = async function (useYarn, yes, exit = false) {
52
44
  /**
53
45
  * find relative paths between tests and pages
54
46
  */
55
- const parsedPaths = (0, utils_1.getPathForFileGeneration)(answers);
47
+ const parsedPaths = getPathForFileGeneration(answers);
56
48
  const parsedAnswers = {
57
49
  ...answers,
58
50
  runner: runnerPackage.short,
@@ -61,21 +53,21 @@ const runConfig = async function (useYarn, yes, exit = false) {
61
53
  plugins: pluginPackages.map(({ short }) => short),
62
54
  services: servicePackages.map(({ short }) => short),
63
55
  packagesToInstall,
64
- isUsingTypeScript: answers.isUsingCompiler === constants_1.COMPILER_OPTIONS.ts,
65
- isUsingBabel: answers.isUsingCompiler === constants_1.COMPILER_OPTIONS.babel,
56
+ isUsingTypeScript: answers.isUsingCompiler === COMPILER_OPTIONS.ts,
57
+ isUsingBabel: answers.isUsingCompiler === COMPILER_OPTIONS.babel,
66
58
  isSync: false,
67
59
  _async: 'async ',
68
60
  _await: 'await ',
69
61
  destSpecRootPath: parsedPaths.destSpecRootPath,
70
62
  destPageObjectRootPath: parsedPaths.destPageObjectRootPath,
71
63
  relativePath: parsedPaths.relativePath,
72
- tsConfigFilePath: path_1.default.join(process.cwd(), 'test', 'tsconfig.json')
64
+ tsConfigFilePath: path.join(process.cwd(), 'test', 'tsconfig.json')
73
65
  };
74
66
  /**
75
67
  * add ts-node if TypeScript is desired but not installed
76
68
  */
77
69
  if (parsedAnswers.isUsingTypeScript) {
78
- if (!(0, utils_1.hasPackage)('ts-node')) {
70
+ if (!hasPackage('ts-node')) {
79
71
  packagesToInstall.push('ts-node', 'typescript');
80
72
  }
81
73
  const config = {
@@ -83,34 +75,34 @@ const runConfig = async function (useYarn, yes, exit = false) {
83
75
  moduleResolution: 'node',
84
76
  types: [
85
77
  'node',
86
- 'webdriverio/async',
78
+ '@wdio/globals/types',
87
79
  frameworkPackage.package,
88
80
  'expect-webdriverio'
89
81
  ],
90
82
  target: 'es2019',
91
83
  }
92
84
  };
93
- fs_extra_1.default.ensureDirSync(path_1.default.join(process.cwd(), 'test'));
94
- await fs_extra_1.default.promises.writeFile(parsedAnswers.tsConfigFilePath, JSON.stringify(config, null, 4));
85
+ await fs.mkdir(path.join(process.cwd(), 'test'), { recursive: true });
86
+ await fs.writeFile(parsedAnswers.tsConfigFilePath, JSON.stringify(config, null, 4));
95
87
  }
96
88
  /**
97
89
  * add @babel/register package if not installed
98
90
  */
99
91
  if (parsedAnswers.isUsingBabel) {
100
- if (!(0, utils_1.hasPackage)('@babel/register')) {
92
+ if (!hasPackage('@babel/register')) {
101
93
  packagesToInstall.push('@babel/register');
102
94
  }
103
95
  /**
104
96
  * setup Babel if no config file exists
105
97
  */
106
- if (!(0, utils_1.hasFile)('babel.config.js')) {
107
- if (!(0, utils_1.hasPackage)('@babel/core')) {
98
+ if (!hasFile('babel.config.js')) {
99
+ if (!hasPackage('@babel/core')) {
108
100
  packagesToInstall.push('@babel/core');
109
101
  }
110
- if (!(0, utils_1.hasPackage)('@babel/preset-env')) {
102
+ if (!hasPackage('@babel/preset-env')) {
111
103
  packagesToInstall.push('@babel/preset-env');
112
104
  }
113
- await fs_extra_1.default.promises.writeFile(path_1.default.join(process.cwd(), 'babel.config.js'), `module.exports = ${JSON.stringify({
105
+ await fs.writeFile(path.join(process.cwd(), 'babel.config.js'), `module.exports = ${JSON.stringify({
114
106
  presets: [
115
107
  ['@babel/preset-env', {
116
108
  targets: {
@@ -124,23 +116,17 @@ const runConfig = async function (useYarn, yes, exit = false) {
124
116
  /**
125
117
  * add packages that are required by services
126
118
  */
127
- (0, utils_1.addServiceDeps)(servicePackages, packagesToInstall);
119
+ addServiceDeps(servicePackages, packagesToInstall);
128
120
  /**
129
- * ensure wdio packages have the same dist tag as cli
121
+ * update package version if CLI is a pre release
130
122
  */
131
- if (pkg._requested && pkg._requested.fetchSpec) {
132
- const { fetchSpec } = pkg._requested;
133
- packagesToInstall = packagesToInstall.map((p) => (p.startsWith('@wdio') || ['devtools', 'webdriver', 'webdriverio'].includes(p)) &&
134
- (fetchSpec.match(/(v)?\d+\.\d+\.\d+/) === null)
135
- ? `${p}@${fetchSpec}`
136
- : p);
137
- }
123
+ packagesToInstall = specifyVersionIfNeeded(packagesToInstall, pkg.version);
138
124
  /**
139
125
  * run npm install only if required by the user
140
126
  */
141
127
  if (parsedAnswers.npmInstall) {
142
128
  console.log('\nInstalling wdio packages:\n-', packagesToInstall.join('\n- '));
143
- const result = (0, yarn_install_1.default)({ deps: packagesToInstall, dev: true, respectNpm5: !useYarn });
129
+ const result = yarnInstall({ deps: packagesToInstall, dev: true, respectNpm5: !useYarn });
144
130
  if (result.status !== 0) {
145
131
  const customError = 'An unknown error happened! Please retry ' +
146
132
  `installing dependencies via "${useYarn ? 'yarn add --dev' : 'npm i --save-dev'} ` +
@@ -149,7 +135,7 @@ const runConfig = async function (useYarn, yes, exit = false) {
149
135
  /**
150
136
  * don't exit if running unit tests
151
137
  */
152
- if (exit /* istanbul ignore next */ && !process.env.JEST_WORKER_ID) {
138
+ if (exit /* istanbul ignore next */ && !process.env.VITEST_WORKER_ID) {
153
139
  /* istanbul ignore next */
154
140
  process.exit(1);
155
141
  }
@@ -159,13 +145,13 @@ const runConfig = async function (useYarn, yes, exit = false) {
159
145
  }
160
146
  else {
161
147
  const installationCommand = `${useYarn ? 'yarn add --dev' : 'npm i --save-dev'} ${packagesToInstall.join(' ')}`;
162
- console.log(util_1.default.format(constants_1.DEPENDENCIES_INSTALLATION_MESSAGE, installationCommand));
148
+ console.log(util.format(DEPENDENCIES_INSTALLATION_MESSAGE, installationCommand));
163
149
  }
164
150
  try {
165
- await (0, utils_1.renderConfigurationFile)(parsedAnswers);
151
+ await renderConfigurationFile(parsedAnswers);
166
152
  if (answers.generateTestFiles) {
167
153
  console.log('\nConfig file installed successfully, creating test files...');
168
- await (0, utils_1.generateTestFiles)(parsedAnswers);
154
+ await generateTestFiles(parsedAnswers);
169
155
  }
170
156
  }
171
157
  catch (err) {
@@ -174,9 +160,9 @@ const runConfig = async function (useYarn, yes, exit = false) {
174
160
  /**
175
161
  * print TypeScript configuration message
176
162
  */
177
- if (answers.isUsingCompiler === constants_1.COMPILER_OPTIONS.ts) {
163
+ if (answers.isUsingCompiler === COMPILER_OPTIONS.ts) {
178
164
  const tsPkgs = `"${[
179
- 'webdriverio/async',
165
+ '@wdio/globals/types',
180
166
  frameworkPackage.package,
181
167
  'expect-webdriverio',
182
168
  ...servicePackages
@@ -187,13 +173,13 @@ const runConfig = async function (useYarn, yes, exit = false) {
187
173
  */
188
174
  .filter(service => service.startsWith('@wdio'))
189
175
  ].join('", "')}"`;
190
- console.log(util_1.default.format(constants_1.TS_COMPILER_INSTRUCTIONS, tsPkgs));
176
+ console.log(util.format(TS_COMPILER_INSTRUCTIONS, tsPkgs));
191
177
  }
192
- console.log(util_1.default.format(constants_1.CONFIG_HELPER_SUCCESS_MESSAGE, parsedAnswers.isUsingTypeScript ? 'test/' : '', parsedAnswers.isUsingTypeScript ? 'ts' : 'js'));
178
+ console.log(util.format(CONFIG_HELPER_SUCCESS_MESSAGE, parsedAnswers.isUsingTypeScript ? 'test/' : '', parsedAnswers.isUsingTypeScript ? 'ts' : 'js'));
193
179
  /**
194
180
  * don't exit if running unit tests
195
181
  */
196
- if (exit /* istanbul ignore next */ && !process.env.JEST_WORKER_ID) {
182
+ if (exit /* istanbul ignore next */ && !process.env.VITEST_WORKER_ID) {
197
183
  /* istanbul ignore next */
198
184
  process.exit(0);
199
185
  }
@@ -203,10 +189,9 @@ const runConfig = async function (useYarn, yes, exit = false) {
203
189
  installedPackages: packagesToInstall.map((pkg) => pkg.split('--')[0])
204
190
  };
205
191
  };
206
- function handler(argv) {
192
+ export function handler(argv) {
207
193
  return runConfig(argv.yarn, argv.yes);
208
194
  }
209
- exports.handler = handler;
210
195
  /**
211
196
  * Helper utility used in `run` and `install` command to create config if none exist
212
197
  * @param {string} command to be executed by user
@@ -214,24 +199,28 @@ exports.handler = handler;
214
199
  * @param {boolean} useYarn parameter set to true if yarn is used
215
200
  * @param {Function} runConfigCmd runConfig method to be replaceable for unit testing
216
201
  */
217
- async function missingConfigurationPrompt(command, message, useYarn = false, runConfigCmd = runConfig) {
218
- const { config } = await inquirer_1.default.prompt([
202
+ export async function missingConfigurationPrompt(command, message, useYarn = false, runConfigCmd = runConfig) {
203
+ const configMessage = command === 'run'
204
+ ? `Error: Could not execute "run" due to missing configuration, file "${message}" not found! Would you like to create one?`
205
+ : `Error: Could not execute "${command}" due to missing configuration. Would you like to create one?`;
206
+ const { config } = await inquirer.prompt([
219
207
  {
220
208
  type: 'confirm',
221
209
  name: 'config',
222
- message: `Error: Could not execute "${command}" due to missing configuration. Would you like to create one?`,
210
+ message: configMessage,
223
211
  default: false
224
212
  }
225
213
  ]);
226
214
  /**
227
215
  * don't exit if running unit tests
228
216
  */
229
- if (!config && !process.env.JEST_WORKER_ID) {
217
+ if (!config && !process.env.VITEST_WORKER_ID) {
230
218
  /* istanbul ignore next */
231
- console.log(message);
219
+ console.log(command === 'run'
220
+ ? `No WebdriverIO configuration found in "${process.cwd()}"`
221
+ : message);
232
222
  /* istanbul ignore next */
233
223
  return process.exit(0);
234
224
  }
235
225
  return await runConfigCmd(useYarn, false, true);
236
226
  }
237
- exports.missingConfigurationPrompt = missingConfigurationPrompt;
@@ -0,0 +1,2 @@
1
+ export declare const commands: any;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ,EAAE,GAAkC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import * as config from './config.js';
2
+ import * as install from './install.js';
3
+ import * as repl from './repl.js';
4
+ import * as run from './run.js';
5
+ export const commands = [config, install, repl, run];
@@ -1,5 +1,5 @@
1
- import { InstallCommandArguments } from '../types';
2
- import yargs from 'yargs';
1
+ import type { Argv } from 'yargs';
2
+ import type { InstallCommandArguments } from '../types';
3
3
  export declare const command = "install <type> <name>";
4
4
  export declare const desc: string;
5
5
  export declare const cmdArgs: {
@@ -13,6 +13,6 @@ export declare const cmdArgs: {
13
13
  readonly default: "./wdio.conf.js";
14
14
  };
15
15
  };
16
- export declare const builder: (yargs: yargs.Argv<{}>) => yargs.Argv<{}>;
16
+ export declare const builder: (yargs: Argv) => Argv<{}>;
17
17
  export declare function handler(argv: InstallCommandArguments): Promise<void>;
18
18
  //# sourceMappingURL=install.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/commands/install.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,uBAAuB,EAAoB,MAAM,UAAU,CAAA;AAEpE,OAAO,KAAK,MAAM,OAAO,CAAA;AASzB,eAAO,MAAM,OAAO,0BAA0B,CAAA;AAC9C,eAAO,MAAM,IAAI,QAIN,CAAA;AAEX,eAAO,MAAM,OAAO;;;;;;;;;;CAUV,CAAA;AAEV,eAAO,MAAM,OAAO,2CAanB,CAAA;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,uBAAuB,iBAyE1D"}
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/commands/install.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAUjC,OAAO,KAAK,EAAE,uBAAuB,EAAoB,MAAM,UAAU,CAAA;AASzE,eAAO,MAAM,OAAO,0BAA0B,CAAA;AAC9C,eAAO,MAAM,IAAI,QAIN,CAAA;AAEX,eAAO,MAAM,OAAO;;;;;;;;;;CAUV,CAAA;AAEV,eAAO,MAAM,OAAO,UAAW,IAAI,aAalC,CAAA;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,uBAAuB,iBA0E1D"}
@@ -1,29 +1,23 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.handler = exports.builder = exports.cmdArgs = exports.desc = exports.command = void 0;
7
1
  /* eslint-disable no-console */
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const path_1 = __importDefault(require("path"));
10
- const yarn_install_1 = __importDefault(require("yarn-install"));
11
- const utils_1 = require("../utils");
12
- const config_1 = require("./config");
13
- const constants_1 = require("../constants");
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import yarnInstall from 'yarn-install';
5
+ import { replaceConfig, findInConfig, addServiceDeps, convertPackageHashToObject } from '../utils.js';
6
+ import { missingConfigurationPrompt } from './config.js';
7
+ import { SUPPORTED_PACKAGES, CLI_EPILOGUE } from '../constants.js';
14
8
  const supportedInstallations = {
15
- plugin: constants_1.SUPPORTED_PACKAGES.plugin.map(({ value }) => (0, utils_1.convertPackageHashToObject)(value)),
16
- service: constants_1.SUPPORTED_PACKAGES.service.map(({ value }) => (0, utils_1.convertPackageHashToObject)(value)),
17
- reporter: constants_1.SUPPORTED_PACKAGES.reporter.map(({ value }) => (0, utils_1.convertPackageHashToObject)(value)),
18
- framework: constants_1.SUPPORTED_PACKAGES.framework.map(({ value }) => (0, utils_1.convertPackageHashToObject)(value))
9
+ plugin: SUPPORTED_PACKAGES.plugin.map(({ value }) => convertPackageHashToObject(value)),
10
+ service: SUPPORTED_PACKAGES.service.map(({ value }) => convertPackageHashToObject(value)),
11
+ reporter: SUPPORTED_PACKAGES.reporter.map(({ value }) => convertPackageHashToObject(value)),
12
+ framework: SUPPORTED_PACKAGES.framework.map(({ value }) => convertPackageHashToObject(value))
19
13
  };
20
- exports.command = 'install <type> <name>';
21
- exports.desc = [
14
+ export const command = 'install <type> <name>';
15
+ export const desc = [
22
16
  'Add a `reporter`, `service`, or `framework` to your WebdriverIO project.',
23
17
  'The command installs the package from NPM, adds it to your package.json',
24
18
  'and modifies the wdio.conf.js accordingly.'
25
19
  ].join(' ');
26
- exports.cmdArgs = {
20
+ export const cmdArgs = {
27
21
  yarn: {
28
22
  desc: 'Install packages using yarn',
29
23
  type: 'boolean',
@@ -34,10 +28,10 @@ exports.cmdArgs = {
34
28
  default: './wdio.conf.js',
35
29
  },
36
30
  };
37
- const builder = (yargs) => {
31
+ export const builder = (yargs) => {
38
32
  yargs
39
- .options(exports.cmdArgs)
40
- .epilogue(constants_1.CLI_EPILOGUE)
33
+ .options(cmdArgs)
34
+ .epilogue(CLI_EPILOGUE)
41
35
  .help();
42
36
  for (const [type, plugins] of Object.entries(supportedInstallations)) {
43
37
  for (const plugin of plugins) {
@@ -46,8 +40,7 @@ const builder = (yargs) => {
46
40
  }
47
41
  return yargs;
48
42
  };
49
- exports.builder = builder;
50
- async function handler(argv) {
43
+ export async function handler(argv) {
51
44
  /**
52
45
  * type = service | reporter | framework
53
46
  * name = names for the supported service or reporter
@@ -70,20 +63,21 @@ async function handler(argv) {
70
63
  process.exit(0);
71
64
  return;
72
65
  }
73
- const localConfPath = path_1.default.join(process.cwd(), config);
74
- if (!fs_extra_1.default.existsSync(localConfPath)) {
66
+ const localConfPath = path.join(process.cwd(), config);
67
+ const localConfExists = await fs.access(localConfPath).then(() => true, () => false);
68
+ if (!localConfExists) {
75
69
  try {
76
70
  const promptMessage = `Cannot install packages without a WebdriverIO configuration.
77
71
  You can create one by running 'wdio config'`;
78
- await (0, config_1.missingConfigurationPrompt)('install', promptMessage, yarn);
72
+ await missingConfigurationPrompt('install', promptMessage, yarn);
79
73
  }
80
74
  catch {
81
75
  process.exit(1);
82
76
  return;
83
77
  }
84
78
  }
85
- const configFile = fs_extra_1.default.readFileSync(localConfPath, { encoding: 'utf-8' });
86
- const match = (0, utils_1.findInConfig)(configFile, type);
79
+ const configFile = await fs.readFile(localConfPath, { encoding: 'utf-8' });
80
+ const match = findInConfig(configFile, type);
87
81
  if (match && match[0].includes(name)) {
88
82
  console.log(`The ${type} ${name} is already part of your configuration.`);
89
83
  process.exit(0);
@@ -91,22 +85,21 @@ You can create one by running 'wdio config'`;
91
85
  }
92
86
  const selectedPackage = supportedInstallations[type].find(({ short }) => short === name);
93
87
  const pkgsToInstall = selectedPackage ? [selectedPackage.package] : [];
94
- (0, utils_1.addServiceDeps)(selectedPackage ? [selectedPackage] : [], pkgsToInstall, true);
88
+ addServiceDeps(selectedPackage ? [selectedPackage] : [], pkgsToInstall, true);
95
89
  console.log(`Installing "${selectedPackage.package}"${yarn ? ' using yarn.' : '.'}`);
96
- const install = (0, yarn_install_1.default)({ deps: pkgsToInstall, dev: true, respectNpm5: !yarn }); // use !yarn so the package forces npm install
90
+ const install = yarnInstall({ deps: pkgsToInstall, dev: true, respectNpm5: !yarn }); // use !yarn so the package forces npm install
97
91
  if (install.status !== 0) {
98
92
  console.error('Error installing packages', install.stderr);
99
93
  process.exit(1);
100
94
  return;
101
95
  }
102
96
  console.log(`Package "${selectedPackage.package}" installed successfully.`);
103
- const newConfig = (0, utils_1.replaceConfig)(configFile, type, name);
97
+ const newConfig = replaceConfig(configFile, type, name);
104
98
  if (!newConfig) {
105
- throw new Error(`Couldn't find "${type}" property in ${path_1.default.basename(localConfPath)}`);
99
+ throw new Error(`Couldn't find "${type}" property in ${path.basename(localConfPath)}`);
106
100
  }
107
- fs_extra_1.default.writeFileSync(localConfPath, newConfig, { encoding: 'utf-8' });
101
+ await fs.writeFile(localConfPath, newConfig, { encoding: 'utf-8' });
108
102
  console.log('Your wdio.conf.js file has been updated.');
109
103
  process.exit(0);
110
104
  }
111
- exports.handler = handler;
112
105
  /* eslint-enable no-console */
@@ -1,11 +1,11 @@
1
- import { ReplCommandArguments } from '../types';
2
- import yargs from 'yargs';
1
+ import type { Argv, Options } from 'yargs';
2
+ import type { ReplCommandArguments } from '../types';
3
3
  export declare const command = "repl <option> [capabilities]";
4
4
  export declare const desc = "Run WebDriver session in command line";
5
5
  export declare const cmdArgs: {
6
- [k in keyof ReplCommandArguments]?: yargs.Options;
6
+ [k in keyof ReplCommandArguments]?: Options;
7
7
  };
8
- export declare const builder: (yargs: yargs.Argv<{}>) => yargs.Argv<yargs.Omit<{}, string | number> & yargs.InferredOptionTypes<import("lodash").Dictionary<yargs.Options | {
8
+ export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, string | number> & import("yargs").InferredOptionTypes<import("lodash").Dictionary<Options | {
9
9
  readonly desc: "Run WebdriverIO in watch mode";
10
10
  readonly type: "boolean";
11
11
  } | {
@@ -67,5 +67,5 @@ export declare const builder: (yargs: yargs.Argv<{}>) => yargs.Argv<yargs.Omit<{
67
67
  } | {
68
68
  readonly desc: "Auto compilation options";
69
69
  }>>>;
70
- export declare const handler: (argv: ReplCommandArguments) => Promise<any>;
70
+ export declare const handler: (argv: ReplCommandArguments) => Promise<void>;
71
71
  //# sourceMappingURL=repl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../../src/commands/repl.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,OAAO,iCAAiC,CAAA;AACrD,eAAO,MAAM,IAAI,0CAA0C,CAAA;AAC3D,eAAO,MAAM,OAAO,EAAE;KAAG,CAAC,IAAI,MAAM,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO;CAgB/D,CAAA;AAEV,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAYnB,CAAA;AAED,eAAO,MAAM,OAAO,SAAgB,oBAAoB,iBAiBvD,CAAA"}
1
+ {"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../../src/commands/repl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAK1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAOpD,eAAO,MAAM,OAAO,iCAAiC,CAAA;AACrD,eAAO,MAAM,IAAI,0CAA0C,CAAA;AAC3D,eAAO,MAAM,OAAO,EAAE;KAAG,CAAC,IAAI,MAAM,oBAAoB,CAAC,CAAC,EAAE,OAAO;CAgBzD,CAAA;AAEV,eAAO,MAAM,OAAO,UAAW,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAYlC,CAAA;AAED,eAAO,MAAM,OAAO,SAAgB,oBAAoB,kBAWvD,CAAA"}
@@ -1,22 +1,15 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.handler = exports.builder = exports.cmdArgs = exports.desc = exports.command = void 0;
7
- const lodash_pickby_1 = __importDefault(require("lodash.pickby"));
8
- const webdriverio_1 = require("webdriverio");
9
- const utils_1 = require("@wdio/utils");
10
- const run_1 = require("./run");
11
- const utils_2 = require("../utils");
12
- const constants_1 = require("../constants");
1
+ import pickBy from 'lodash.pickby';
2
+ import { remote } from 'webdriverio';
3
+ import { cmdArgs as runCmdArgs } from './run.js';
4
+ import { getCapabilities } from '../utils.js';
5
+ import { CLI_EPILOGUE } from '../constants.js';
13
6
  const IGNORED_ARGS = [
14
7
  'bail', 'framework', 'reporters', 'suite', 'spec', 'exclude',
15
8
  'mochaOpts', 'jasmineOpts', 'cucumberOpts', 'autoCompileOpts'
16
9
  ];
17
- exports.command = 'repl <option> [capabilities]';
18
- exports.desc = 'Run WebDriver session in command line';
19
- exports.cmdArgs = {
10
+ export const command = 'repl <option> [capabilities]';
11
+ export const desc = 'Run WebDriver session in command line';
12
+ export const cmdArgs = {
20
13
  platformVersion: {
21
14
  alias: 'v',
22
15
  desc: 'Version of OS for mobile devices',
@@ -33,9 +26,9 @@ exports.cmdArgs = {
33
26
  type: 'string',
34
27
  }
35
28
  };
36
- const builder = (yargs) => {
29
+ export const builder = (yargs) => {
37
30
  return yargs
38
- .options((0, lodash_pickby_1.default)({ ...exports.cmdArgs, ...run_1.cmdArgs }, (_, key) => !IGNORED_ARGS.includes(key)))
31
+ .options(pickBy({ ...cmdArgs, ...runCmdArgs }, (_, key) => !IGNORED_ARGS.includes(key)))
39
32
  .example('$0 repl firefox --path /', 'Run repl locally')
40
33
  .example('$0 repl chrome -u <SAUCE_USERNAME> -k <SAUCE_ACCESS_KEY>', 'Run repl in Sauce Labs cloud')
41
34
  .example('$0 repl android', 'Run repl browser on launched Android device')
@@ -43,23 +36,16 @@ const builder = (yargs) => {
43
36
  .example('$0 repl ios -v 11.3 -d "iPhone 7" -u 123432abc', 'Run repl browser on iOS device with capabilities')
44
37
  .example('$0 repl "./path/to/wdio.config.js" 0 -p 9515', 'Run repl using the first capability from the capabilty array in wdio.config.js')
45
38
  .example('$0 repl "./path/to/wdio.config.js" "myChromeBrowser" -p 9515', 'Run repl using a named multiremote capabilities in wdio.config.js')
46
- .epilogue(constants_1.CLI_EPILOGUE)
39
+ .epilogue(CLI_EPILOGUE)
47
40
  .help();
48
41
  };
49
- exports.builder = builder;
50
- const handler = async (argv) => {
51
- const caps = (0, utils_2.getCapabilities)(argv);
52
- /**
53
- * runner option required to wrap commands within Fibers context
54
- */
55
- const execMode = utils_1.hasWdioSyncSupport ? { runner: 'local' } : {};
56
- const client = await (0, webdriverio_1.remote)({ ...argv, ...caps, ...execMode });
57
- // @ts-ignore
42
+ export const handler = async (argv) => {
43
+ const caps = await getCapabilities(argv);
44
+ const client = await remote({ ...argv, ...caps });
58
45
  global.$ = client.$.bind(client);
59
- // @ts-ignore
60
46
  global.$$ = client.$$.bind(client);
47
+ // @ts-expect-error global browser is for some reason not detected
61
48
  global.browser = client;
62
49
  await client.debug();
63
50
  return client.deleteSession();
64
51
  };
65
- exports.handler = handler;
@@ -1,5 +1,7 @@
1
- import { RunCommandArguments } from '../types';
2
- import yargs from 'yargs';
1
+ /// <reference types="node" />
2
+ import cp from 'node:child_process';
3
+ import type { Argv } from 'yargs';
4
+ import type { RunCommandArguments } from '../types';
3
5
  export declare const command = "run <configPath>";
4
6
  export declare const desc = "Run your WDIO configuration file to initialize your tests. (default)";
5
7
  export declare const cmdArgs: {
@@ -84,7 +86,7 @@ export declare const cmdArgs: {
84
86
  readonly desc: "Auto compilation options";
85
87
  };
86
88
  };
87
- export declare const builder: (yargs: yargs.Argv<{}>) => yargs.Argv<yargs.Omit<{}, "framework" | "reporters" | "hostname" | "port" | "path" | "baseUrl" | "exclude" | "user" | "key" | "logLevel" | "spec" | "waitforTimeout" | "watch" | "bail" | "suite" | "mochaOpts" | "jasmineOpts" | "cucumberOpts" | "autoCompileOpts"> & yargs.InferredOptionTypes<{
89
+ export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "framework" | "reporters" | "hostname" | "port" | "path" | "baseUrl" | "exclude" | "user" | "key" | "logLevel" | "spec" | "waitforTimeout" | "watch" | "bail" | "suite" | "mochaOpts" | "jasmineOpts" | "cucumberOpts" | "autoCompileOpts"> & import("yargs").InferredOptionTypes<{
88
90
  readonly watch: {
89
91
  readonly desc: "Run WebdriverIO in watch mode";
90
92
  readonly type: "boolean";
@@ -167,6 +169,6 @@ export declare const builder: (yargs: yargs.Argv<{}>) => yargs.Argv<yargs.Omit<{
167
169
  };
168
170
  }>>;
169
171
  export declare function launchWithStdin(wdioConfPath: string, params: Partial<RunCommandArguments>): void;
170
- export declare function launch(wdioConfPath: string, params: Partial<RunCommandArguments>): Promise<void>;
171
- export declare function handler(argv: RunCommandArguments): Promise<void>;
172
+ export declare function launch(wdioConfPath: string, params: Partial<RunCommandArguments>): Promise<void> | cp.ChildProcess;
173
+ export declare function handler(argv: RunCommandArguments): Promise<void | cp.ChildProcess>;
172
174
  //# sourceMappingURL=run.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAK9C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,eAAO,MAAM,OAAO,qBAAqB,CAAA;AAEzC,eAAO,MAAM,IAAI,yEAAyE,CAAA;AAE1F,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiFV,CAAA;AAEV,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAUnB,CAAA;AAED,wBAAgB,eAAe,CAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,mBAAmB,CAAC,QAc1F;AAED,wBAAgB,MAAM,CAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,mBAAmB,CAAC,iBAgBjF;AAED,wBAAsB,OAAO,CAAE,IAAI,EAAE,mBAAmB,iBAkCvD"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACnC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAMjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnD,eAAO,MAAM,OAAO,qBAAqB,CAAA;AAEzC,eAAO,MAAM,IAAI,yEAAyE,CAAA;AAE1F,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiFV,CAAA;AAEV,eAAO,MAAM,OAAO,UAAW,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAUlC,CAAA;AAED,wBAAgB,eAAe,CAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,mBAAmB,CAAC,QAc1F;AAED,wBAAgB,MAAM,CAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,mBAAmB,CAAC,mCAgDjF;AAED,wBAAsB,OAAO,CAAE,IAAI,EAAE,mBAAmB,mCA0CvD"}