codeceptjs 3.6.6 → 4.0.0-beta.1

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.
Files changed (151) hide show
  1. package/bin/codecept.js +81 -84
  2. package/lib/actor.js +13 -13
  3. package/lib/ai.js +13 -10
  4. package/lib/assert/empty.js +21 -20
  5. package/lib/assert/equal.js +39 -37
  6. package/lib/assert/error.js +14 -14
  7. package/lib/assert/include.js +47 -46
  8. package/lib/assert/throws.js +11 -13
  9. package/lib/assert/truth.js +22 -19
  10. package/lib/assert.js +2 -4
  11. package/lib/cli.js +49 -57
  12. package/lib/codecept.js +155 -142
  13. package/lib/colorUtils.js +3 -3
  14. package/lib/command/configMigrate.js +52 -58
  15. package/lib/command/definitions.js +89 -88
  16. package/lib/command/dryRun.js +68 -71
  17. package/lib/command/generate.js +188 -197
  18. package/lib/command/gherkin/init.js +16 -27
  19. package/lib/command/gherkin/snippets.js +20 -20
  20. package/lib/command/gherkin/steps.js +8 -8
  21. package/lib/command/info.js +38 -40
  22. package/lib/command/init.js +288 -290
  23. package/lib/command/interactive.js +32 -32
  24. package/lib/command/list.js +26 -26
  25. package/lib/command/run-multiple/chunk.js +5 -5
  26. package/lib/command/run-multiple/collection.js +3 -3
  27. package/lib/command/run-multiple/run.js +2 -6
  28. package/lib/command/run-multiple.js +93 -113
  29. package/lib/command/run-rerun.js +25 -20
  30. package/lib/command/run-workers.js +66 -64
  31. package/lib/command/run.js +29 -26
  32. package/lib/command/utils.js +65 -80
  33. package/lib/command/workers/runTests.js +10 -10
  34. package/lib/config.js +9 -10
  35. package/lib/container.js +48 -40
  36. package/lib/data/context.js +59 -60
  37. package/lib/data/dataScenarioConfig.js +47 -47
  38. package/lib/data/dataTableArgument.js +29 -29
  39. package/lib/data/table.js +20 -26
  40. package/lib/dirname.js +5 -0
  41. package/lib/event.js +167 -163
  42. package/lib/heal.js +17 -13
  43. package/lib/helper/AI.js +41 -130
  44. package/lib/helper/ApiDataFactory.js +69 -73
  45. package/lib/helper/Appium.js +381 -412
  46. package/lib/helper/Expect.js +425 -0
  47. package/lib/helper/ExpectHelper.js +48 -40
  48. package/lib/helper/FileSystem.js +79 -80
  49. package/lib/helper/GraphQL.js +43 -44
  50. package/lib/helper/GraphQLDataFactory.js +50 -50
  51. package/lib/helper/JSONResponse.js +62 -65
  52. package/lib/helper/Mochawesome.js +28 -28
  53. package/lib/helper/MockServer.js +14 -12
  54. package/lib/helper/Nightmare.js +566 -662
  55. package/lib/helper/Playwright.js +1216 -1361
  56. package/lib/helper/Protractor.js +627 -663
  57. package/lib/helper/Puppeteer.js +1128 -1231
  58. package/lib/helper/REST.js +68 -159
  59. package/lib/helper/SoftExpectHelper.js +2 -2
  60. package/lib/helper/TestCafe.js +484 -490
  61. package/lib/helper/WebDriver.js +1156 -1297
  62. package/lib/helper/clientscripts/PollyWebDriverExt.js +1 -1
  63. package/lib/helper/errors/ConnectionRefused.js +1 -1
  64. package/lib/helper/errors/ElementAssertion.js +2 -2
  65. package/lib/helper/errors/ElementNotFound.js +2 -2
  66. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +1 -1
  67. package/lib/helper/extras/Console.js +1 -1
  68. package/lib/helper/extras/PlaywrightPropEngine.js +2 -2
  69. package/lib/helper/extras/PlaywrightReactVueLocator.js +1 -1
  70. package/lib/helper/extras/PlaywrightRestartOpts.js +18 -21
  71. package/lib/helper/extras/Popup.js +1 -1
  72. package/lib/helper/extras/React.js +3 -3
  73. package/lib/helper/network/actions.js +7 -14
  74. package/lib/helper/network/utils.js +2 -3
  75. package/lib/helper/scripts/blurElement.js +1 -1
  76. package/lib/helper/scripts/focusElement.js +1 -1
  77. package/lib/helper/scripts/highlightElement.js +1 -1
  78. package/lib/helper/scripts/isElementClickable.js +1 -1
  79. package/lib/helper/testcafe/testControllerHolder.js +1 -1
  80. package/lib/helper/testcafe/testcafe-utils.js +7 -6
  81. package/lib/helper.js +3 -1
  82. package/lib/history.js +5 -6
  83. package/lib/hooks.js +6 -6
  84. package/lib/html.js +7 -7
  85. package/lib/index.js +41 -25
  86. package/lib/interfaces/bdd.js +64 -47
  87. package/lib/interfaces/featureConfig.js +19 -19
  88. package/lib/interfaces/gherkin.js +118 -124
  89. package/lib/interfaces/scenarioConfig.js +29 -29
  90. package/lib/listener/artifacts.js +9 -9
  91. package/lib/listener/config.js +24 -24
  92. package/lib/listener/exit.js +12 -12
  93. package/lib/listener/helpers.js +42 -42
  94. package/lib/listener/mocha.js +11 -11
  95. package/lib/listener/retry.js +30 -32
  96. package/lib/listener/steps.js +53 -50
  97. package/lib/listener/timeout.js +54 -54
  98. package/lib/locator.js +10 -6
  99. package/lib/mochaFactory.js +15 -18
  100. package/lib/output.js +10 -6
  101. package/lib/parser.js +12 -15
  102. package/lib/pause.js +33 -40
  103. package/lib/plugin/allure.js +15 -15
  104. package/lib/plugin/autoDelay.js +37 -29
  105. package/lib/plugin/autoLogin.js +65 -70
  106. package/lib/plugin/commentStep.js +18 -18
  107. package/lib/plugin/coverage.js +67 -115
  108. package/lib/plugin/customLocator.js +20 -21
  109. package/lib/plugin/debugErrors.js +24 -24
  110. package/lib/plugin/eachElement.js +38 -38
  111. package/lib/plugin/fakerTransform.js +6 -6
  112. package/lib/plugin/heal.js +108 -67
  113. package/lib/plugin/pauseOnFail.js +11 -11
  114. package/lib/plugin/retryFailedStep.js +39 -32
  115. package/lib/plugin/retryTo.js +40 -46
  116. package/lib/plugin/screenshotOnFail.js +87 -109
  117. package/lib/plugin/selenoid.js +118 -131
  118. package/lib/plugin/standardActingHelpers.js +8 -2
  119. package/lib/plugin/stepByStepReport.js +91 -110
  120. package/lib/plugin/stepTimeout.js +23 -24
  121. package/lib/plugin/subtitles.js +35 -34
  122. package/lib/plugin/tryTo.js +30 -40
  123. package/lib/plugin/wdio.js +75 -78
  124. package/lib/recorder.js +17 -14
  125. package/lib/rerun.js +10 -11
  126. package/lib/scenario.js +23 -25
  127. package/lib/secret.js +2 -4
  128. package/lib/session.js +10 -10
  129. package/lib/step.js +9 -12
  130. package/lib/store.js +3 -2
  131. package/lib/transform.js +1 -1
  132. package/lib/translation.js +8 -7
  133. package/lib/ui.js +14 -12
  134. package/lib/utils.js +72 -70
  135. package/lib/within.js +10 -10
  136. package/lib/workerStorage.js +25 -27
  137. package/lib/workers.js +32 -29
  138. package/package.json +53 -51
  139. package/translations/de-DE.js +1 -1
  140. package/translations/fr-FR.js +1 -1
  141. package/translations/index.js +13 -9
  142. package/translations/it-IT.js +1 -1
  143. package/translations/ja-JP.js +1 -1
  144. package/translations/pl-PL.js +1 -1
  145. package/translations/pt-BR.js +1 -1
  146. package/translations/ru-RU.js +1 -1
  147. package/translations/zh-CN.js +1 -1
  148. package/translations/zh-TW.js +1 -1
  149. package/typings/index.d.ts +65 -415
  150. package/typings/promiseBasedTypes.d.ts +32 -0
  151. package/typings/types.d.ts +32 -0
package/lib/codecept.js CHANGED
@@ -1,215 +1,228 @@
1
- const { existsSync, readFileSync } = require('fs');
2
- const glob = require('glob');
3
- const fsPath = require('path');
4
- const { resolve } = require('path');
5
-
6
- const container = require('./container');
7
- const Config = require('./config');
8
- const event = require('./event');
9
- const runHook = require('./hooks');
10
- const output = require('./output');
11
- const { emptyFolder } = require('./utils');
1
+ import { existsSync, readFileSync } from 'fs';
2
+ import glob from 'glob';
3
+ import { resolve, dirname, isAbsolute, join } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { createRequire } from 'node:module';
6
+ import container from './container.js';
7
+ import Config from './config.js';
8
+ import * as event from './event.js';
9
+ import runHook from './hooks.js';
10
+ import * as output from './output.js';
11
+ import { emptyFolder } from './utils.js';
12
+ import * as index from './index.js';
13
+
14
+ // Helpers and features
15
+ import * as actor from './actor.js';
16
+ import pause from './pause.js';
17
+ import within from './within.js';
18
+ import session from './session.js';
19
+ import data from './data/table.js';
20
+ import Locator from './locator.js';
21
+ import secret from './secret.js';
22
+ import * as stepDefinitions from './interfaces/bdd.js';
23
+
24
+ // Listeners
25
+ import listener from './listener/steps.js';
26
+ import listenerArtifacts from './listener/artifacts.js';
27
+ import listenerConfig from './listener/config.js';
28
+ import listenerHelpers from './listener/helpers.js';
29
+ import listenerRetry from './listener/retry.js';
30
+ import listenerTimeout from './listener/timeout.js';
31
+ import listenerExit from './listener/exit.js';
32
+
33
+ const __dirname = dirname(fileURLToPath(import.meta.url));
34
+ const require = createRequire(import.meta.url);
12
35
 
13
36
  /**
14
- * CodeceptJS runner
37
+ * CodeceptJS runner class.
15
38
  */
16
- class Codecept {
39
+ export default class Codecept {
17
40
  /**
18
- * Create CodeceptJS runner.
19
- * Config and options should be passed
20
- *
21
- * @param {*} config
22
- * @param {*} opts
41
+ * Initializes CodeceptJS runner with config and options.
42
+ * @param {Object} config - Configuration object.
43
+ * @param {Object} opts - Options.
23
44
  */
24
45
  constructor(config, opts) {
25
46
  this.config = Config.create(config);
26
47
  this.opts = opts;
27
- this.testFiles = new Array(0);
28
- this.requireModules(config.require);
48
+ this.testFiles = [];
49
+ this.requireModules(config?.require);
29
50
  }
30
51
 
31
52
  /**
32
- * Require modules before codeceptjs running
33
- *
34
- * @param {string[]} requiringModules
53
+ * Requires necessary modules before running CodeceptJS.
54
+ * @param {string[]} requiringModules - List of modules to require.
35
55
  */
36
56
  requireModules(requiringModules) {
37
- if (requiringModules) {
38
- requiringModules.forEach((requiredModule) => {
39
- const isLocalFile = existsSync(requiredModule) || existsSync(`${requiredModule}.js`);
40
- if (isLocalFile) {
41
- requiredModule = resolve(requiredModule);
42
- }
43
- require(requiredModule);
44
- });
45
- }
57
+ requiringModules?.forEach((requiredModule) => {
58
+ const isLocalFile = existsSync(requiredModule) || existsSync(`${requiredModule}.js`);
59
+ const modulePath = isLocalFile ? resolve(requiredModule) : requiredModule;
60
+ require(modulePath);
61
+ });
46
62
  }
47
63
 
48
64
  /**
49
- * Initialize CodeceptJS at specific directory.
50
- * If async initialization is required, pass callback as second parameter.
51
- *
52
- * @param {string} dir
65
+ * Initializes CodeceptJS in a specific directory.
66
+ * @param {string} dir - Directory path.
53
67
  */
54
68
  init(dir) {
55
69
  this.initGlobals(dir);
56
- // initializing listeners
57
70
  container.create(this.config, this.opts);
58
71
  this.runHooks();
59
72
  }
60
73
 
61
74
  /**
62
- * Creates global variables
63
- *
64
- * @param {string} dir
75
+ * Initializes global variables.
76
+ * @param {string} dir - Directory path.
65
77
  */
66
78
  initGlobals(dir) {
67
79
  global.codecept_dir = dir;
68
- global.output_dir = fsPath.resolve(dir, this.config.output);
80
+ global.output_dir = resolve(dir, this.config.output);
69
81
 
70
82
  if (this.config.emptyOutputFolder) emptyFolder(global.output_dir);
71
83
 
72
84
  if (!this.config.noGlobals) {
73
- global.Helper = global.codecept_helper = require('@codeceptjs/helper');
74
- global.actor = global.codecept_actor = require('./actor');
75
- global.pause = require('./pause');
76
- global.within = require('./within');
77
- global.session = require('./session');
78
- global.DataTable = require('./data/table');
79
- global.locate = locator => require('./locator').build(locator);
80
- global.inject = container.support;
81
- global.share = container.share;
82
- global.secret = require('./secret').secret;
83
- global.codecept_debug = output.debug;
84
- global.codeceptjs = require('./index'); // load all objects
85
-
86
- // BDD
87
- const stepDefinitions = require('./interfaces/bdd');
88
- global.Given = stepDefinitions.Given;
89
- global.When = stepDefinitions.When;
90
- global.Then = stepDefinitions.Then;
91
- global.DefineParameterType = stepDefinitions.defineParameterType;
92
-
93
- // debug mode
94
- global.debugMode = false;
85
+ this.initGlobalHelpers();
95
86
  }
96
87
  }
97
88
 
98
89
  /**
99
- * Executes hooks.
90
+ * Initializes global helpers and other CodeceptJS features.
91
+ */
92
+ initGlobalHelpers() {
93
+ global.Helper = global.codecept_helper = index.generated;
94
+ global.actor = global.codecept_actor = actor;
95
+ global.pause = pause;
96
+ global.within = within;
97
+ global.session = session;
98
+ global.DataTable = data;
99
+ global.locate = (locator) => new Locator(locator);
100
+ global.inject = container.support;
101
+ global.share = container.share;
102
+ global.secret = secret;
103
+ global.codecept_debug = output.debug;
104
+ global.codeceptjs = index;
105
+
106
+ // BDD
107
+ global.Given = stepDefinitions.Given;
108
+ global.When = stepDefinitions.When;
109
+ global.Then = stepDefinitions.Then;
110
+ global.DefineParameterType = stepDefinitions.defineParameterType;
111
+ global.debugMode = false;
112
+ }
113
+
114
+ /**
115
+ * Runs all hooks, including custom and default.
100
116
  */
101
117
  runHooks() {
102
- // default hooks
103
- runHook(require('./listener/steps'));
104
- runHook(require('./listener/artifacts'));
105
- runHook(require('./listener/config'));
106
- runHook(require('./listener/helpers'));
107
- runHook(require('./listener/retry'));
108
- runHook(require('./listener/timeout'));
109
- runHook(require('./listener/exit'));
110
-
111
- // custom hooks (previous iteration of plugins)
112
- this.config.hooks.forEach(hook => runHook(hook));
118
+ const listeners = [
119
+ listener,
120
+ listenerArtifacts,
121
+ listenerConfig,
122
+ listenerHelpers,
123
+ listenerRetry,
124
+ listenerTimeout,
125
+ listenerExit,
126
+ ];
127
+
128
+ listeners.forEach(runHook);
129
+
130
+ // Run custom hooks
131
+ this.config.hooks.forEach(runHook);
113
132
  }
114
133
 
115
134
  /**
116
- * Executes bootstrap.
117
- *
135
+ * Executes the bootstrap process.
118
136
  */
119
137
  async bootstrap() {
120
138
  return runHook(this.config.bootstrap, 'bootstrap');
121
139
  }
122
140
 
123
141
  /**
124
- * Executes teardown.
125
-
142
+ * Executes the teardown process.
126
143
  */
127
144
  async teardown() {
128
145
  return runHook(this.config.teardown, 'teardown');
129
146
  }
130
147
 
131
148
  /**
132
- * Loads tests by pattern or by config.tests
133
- *
134
- * @param {string} [pattern]
149
+ * Loads test files based on the given pattern or config.
150
+ * @param {string} [pattern] - Optional pattern for loading tests.
135
151
  */
136
152
  loadTests(pattern) {
137
- const options = {
138
- cwd: global.codecept_dir,
139
- };
140
-
141
- let patterns = [pattern];
142
- if (!pattern) {
143
- patterns = [];
144
-
145
- // If the user wants to test a specific set of test files as an array or string.
146
- if (this.config.tests && !this.opts.features) {
147
- if (Array.isArray(this.config.tests)) {
148
- patterns.push(...this.config.tests);
149
- } else {
150
- patterns.push(this.config.tests);
153
+ const patterns = this.getTestPatterns(pattern);
154
+ const options = { cwd: global.codecept_dir };
155
+
156
+ patterns.forEach((p) => {
157
+ glob.sync(p, options).forEach((file) => {
158
+ if (!file.includes('node_modules')) {
159
+ const fullPath = isAbsolute(file) ? file : join(global.codecept_dir, file);
160
+ const resolvedFile = resolve(fullPath);
161
+
162
+ if (!this.testFiles.includes(resolvedFile)) {
163
+ this.testFiles.push(resolvedFile);
164
+ }
151
165
  }
152
- }
166
+ });
167
+ });
168
+ }
153
169
 
154
- if (this.config.gherkin.features && !this.opts.tests) {
155
- if (Array.isArray(this.config.gherkin.features)) {
156
- this.config.gherkin.features.forEach(feature => {
157
- patterns.push(feature);
158
- });
159
- } else {
160
- patterns.push(this.config.gherkin.features);
161
- }
162
- }
170
+ /**
171
+ * Gets test patterns based on config and options.
172
+ * @param {string} [pattern] - Test pattern to match.
173
+ * @returns {string[]} - Array of test patterns.
174
+ */
175
+ getTestPatterns(pattern) {
176
+ if (pattern) return [pattern];
177
+
178
+ const patterns = [];
179
+ const { tests, gherkin } = this.config;
180
+
181
+ if (tests && !this.opts.features) {
182
+ patterns.push(...(Array.isArray(tests) ? tests : [tests]));
163
183
  }
164
184
 
165
- for (pattern of patterns) {
166
- glob.sync(pattern, options).forEach((file) => {
167
- if (file.includes('node_modules')) return;
168
- if (!fsPath.isAbsolute(file)) {
169
- file = fsPath.join(global.codecept_dir, file);
170
- }
171
- if (!this.testFiles.includes(fsPath.resolve(file))) {
172
- this.testFiles.push(fsPath.resolve(file));
173
- }
174
- });
185
+ if (gherkin?.features && !this.opts.tests) {
186
+ patterns.push(...(Array.isArray(gherkin.features) ? gherkin.features : [gherkin.features]));
175
187
  }
188
+
189
+ return patterns;
176
190
  }
177
191
 
178
192
  /**
179
- * Run a specific test or all loaded tests.
180
- *
181
- * @param {string} [test]
193
+ * Runs tests either specific to a file or all loaded tests.
194
+ * @param {string} [test] - Test file to run.
182
195
  * @returns {Promise<void>}
183
196
  */
184
197
  async run(test) {
185
- return new Promise((resolve, reject) => {
186
- const mocha = container.mocha();
187
- mocha.files = this.testFiles;
188
- if (test) {
189
- if (!fsPath.isAbsolute(test)) {
190
- test = fsPath.join(global.codecept_dir, test);
191
- }
192
- mocha.files = mocha.files.filter(t => fsPath.basename(t, '.js') === test || t === test);
193
- }
194
- const done = () => {
195
- event.emit(event.all.result, this);
196
- event.emit(event.all.after, this);
197
- resolve();
198
- };
198
+ const mocha = container.mocha();
199
+ mocha.files = this.testFiles;
199
200
 
201
+ if (test) {
202
+ const testPath = isAbsolute(test) ? test : join(global.codecept_dir, test);
203
+ mocha.files = mocha.files.filter((t) => resolve(t) === resolve(testPath));
204
+ }
205
+
206
+ return new Promise((resolve, reject) => {
200
207
  try {
201
208
  event.emit(event.all.before, this);
202
- mocha.run(() => done());
203
- } catch (e) {
204
- output.error(e.stack);
205
- reject(e);
209
+ mocha.run(() => {
210
+ event.emit(event.all.result, this);
211
+ event.emit(event.all.after, this);
212
+ resolve();
213
+ });
214
+ } catch (error) {
215
+ output.output.error(error.stack);
216
+ reject(error);
206
217
  }
207
218
  });
208
219
  }
209
-
210
- static version() {
211
- return JSON.parse(readFileSync(`${__dirname}/../package.json`, 'utf8')).version;
212
- }
213
220
  }
214
221
 
215
- module.exports = Codecept;
222
+ /**
223
+ * Retrieves the version from package.json.
224
+ * @returns {string} - The version of the package.
225
+ */
226
+ export function version() {
227
+ return JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf8')).version;
228
+ }
package/lib/colorUtils.js CHANGED
@@ -189,7 +189,7 @@ function convertHexColorToRgba(hex) {
189
189
  *
190
190
  * @param {string} color Color as a string, i.e. rgb(85,0,0)
191
191
  */
192
- function convertColorToRGBA(color) {
192
+ export function convertColorToRGBA(color) {
193
193
  const cstr = `${color}`.toLowerCase().trim() || '';
194
194
 
195
195
  if (!/^rgba?\(.+?\)$/.test(cstr)) {
@@ -221,7 +221,7 @@ function convertColorToRGBA(color) {
221
221
  *
222
222
  * @param {string} prop CSS Property name
223
223
  */
224
- function isColorProperty(prop) {
224
+ export function isColorProperty(prop) {
225
225
  return [
226
226
  'color',
227
227
  'background',
@@ -248,7 +248,7 @@ function isColorProperty(prop) {
248
248
  ].indexOf(prop) > -1;
249
249
  }
250
250
 
251
- module.exports = {
251
+ export default {
252
252
  isColorProperty,
253
253
  convertColorToRGBA,
254
254
  convertColorNameToHex,
@@ -1,76 +1,70 @@
1
- const colors = require('chalk')
2
- const fs = require('fs')
3
- const inquirer = require('inquirer')
4
- const mkdirp = require('mkdirp')
5
- const path = require('path')
6
- const util = require('util')
1
+ import colors from 'chalk';
2
+ import fs from 'fs';
3
+ import inquirer from 'inquirer';
4
+ import mkdirp from 'mkdirp';
5
+ import path from 'path';
6
+ import util from 'util';
7
+ import * as outputLib from '../output.js';
8
+ import { fileExists } from '../utils.js';
9
+ import { getTestRoot } from './utils.js';
7
10
 
8
- const { print, success, error } = require('../output')
9
- const { fileExists } = require('../utils')
10
- const { getTestRoot } = require('./utils')
11
+ export default function (initPath) {
12
+ const testsPath = getTestRoot(initPath);
11
13
 
12
- module.exports = function (initPath) {
13
- const testsPath = getTestRoot(initPath)
14
-
15
- print()
16
- print(` Welcome to ${colors.magenta.bold('CodeceptJS')} configuration migration tool`)
17
- print(
18
- ` It will help you switch from ${colors.cyan.bold('.json')} to ${colors.magenta.bold('.js')} config format at ease`,
19
- )
20
- print()
14
+ outputLib.print();
15
+ outputLib.print(` Welcome to ${colors.magenta.bold('CodeceptJS')} configuration migration tool`);
16
+ outputLib.print(` It will help you switch from ${colors.cyan.bold('.json')} to ${colors.magenta.bold('.js')} config format at ease`);
17
+ outputLib.print();
21
18
 
22
19
  if (!path) {
23
- print('No config file is specified.')
24
- print(`Test root is assumed to be ${colors.yellow.bold(testsPath)}`)
25
- print('----------------------------------')
20
+ outputLib.print('No config file is specified.');
21
+ outputLib.print(`Test root is assumed to be ${colors.yellow.bold(testsPath)}`);
22
+ outputLib.print('----------------------------------');
26
23
  } else {
27
- print(`Migrating ${colors.magenta.bold('.js')} config to ${colors.bold(testsPath)}`)
24
+ outputLib.print(`Migrating ${colors.magenta.bold('.js')} config to ${colors.bold(testsPath)}`);
28
25
  }
29
26
 
30
27
  if (!fileExists(testsPath)) {
31
- print(`Directory ${testsPath} does not exist, creating...`)
32
- mkdirp.sync(testsPath)
28
+ outputLib.print(`Directory ${testsPath} does not exist, creating...`);
29
+ mkdirp.sync(testsPath);
33
30
  }
34
31
 
35
- const configFile = path.join(testsPath, 'codecept.conf.js')
32
+ const configFile = path.join(testsPath, 'codecept.conf.js');
36
33
  if (fileExists(configFile)) {
37
- error(`Config is already created at ${configFile}`)
38
- return
34
+ outputLib.output.output.error(`Config is already created at ${configFile}`);
35
+ return;
39
36
  }
40
37
 
41
- inquirer
42
- .prompt([
43
- {
44
- name: 'configFile',
45
- type: 'confirm',
46
- message: `Would you like to switch from ${colors.cyan.bold('.json')} to ${colors.magenta.bold('.js')} config format?`,
47
- default: true,
48
- },
49
- {
50
- name: 'delete',
51
- type: 'confirm',
52
- message: `Would you like to delete ${colors.cyan.bold('.json')} config format afterwards?`,
53
- default: true,
54
- },
55
- ])
56
- .then((result) => {
57
- if (result.configFile) {
58
- const jsonConfigFile = path.join(testsPath, 'codecept.js')
59
- const config = JSON.parse(fs.readFileSync(jsonConfigFile, 'utf8'))
60
- config.name = testsPath.split(path.sep).pop()
38
+ inquirer.prompt([{
39
+ name: 'configFile',
40
+ type: 'confirm',
41
+ message: `Would you like to switch from ${colors.cyan.bold('.json')} to ${colors.magenta.bold('.js')} config format?`,
42
+ default: true,
43
+ },
44
+ {
45
+ name: 'delete',
46
+ type: 'confirm',
47
+ message: `Would you like to delete ${colors.cyan.bold('.json')} config format afterwards?`,
48
+ default: true,
49
+ },
50
+ ]).then((result) => {
51
+ if (result.configFile) {
52
+ const jsonConfigFile = path.join(testsPath, 'codecept.js');
53
+ const config = JSON.parse(fs.readFileSync(jsonConfigFile, 'utf8'));
54
+ config.name = testsPath.split(path.sep).pop();
61
55
 
62
- const finish = () => {
63
- fs.writeFileSync(configFile, `exports.config = ${util.inspect(config, false, 4, false)}`, 'utf-8')
64
- success(`Config is successfully migrated at ${configFile}`)
56
+ const finish = () => {
57
+ fs.writeFileSync(configFile, `exports.config = ${util.inspect(config, false, 4, false)}`, 'utf-8');
58
+ outputLib.output.success(`Config is successfully migrated at ${configFile}`);
65
59
 
66
- if (result.delete) {
67
- if (fileExists(jsonConfigFile)) {
68
- fs.unlinkSync(jsonConfigFile)
69
- success('JSON config file is deleted!')
70
- }
60
+ if (result.delete) {
61
+ if (fileExists(jsonConfigFile)) {
62
+ fs.unlinkSync(jsonConfigFile);
63
+ outputLib.output.success('JSON config file is deleted!');
71
64
  }
72
65
  }
73
- finish()
74
- }
75
- })
66
+ };
67
+ finish();
68
+ }
69
+ });
76
70
  }