codeceptjs 4.0.0-beta.1 → 4.0.0-beta.3

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