codeceptjs 4.0.0-beta.2 → 4.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/codecept.js +84 -81
- package/lib/actor.js +13 -13
- package/lib/ai.js +10 -13
- package/lib/assert/empty.js +20 -21
- package/lib/assert/equal.js +37 -39
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +46 -47
- package/lib/assert/throws.js +13 -11
- package/lib/assert/truth.js +19 -22
- package/lib/assert.js +4 -2
- package/lib/cli.js +56 -49
- package/lib/codecept.js +145 -155
- package/lib/colorUtils.js +3 -3
- package/lib/command/configMigrate.js +58 -52
- package/lib/command/definitions.js +88 -89
- package/lib/command/dryRun.js +79 -81
- package/lib/command/generate.js +197 -188
- package/lib/command/gherkin/init.js +27 -16
- package/lib/command/gherkin/snippets.js +21 -21
- package/lib/command/gherkin/steps.js +8 -8
- package/lib/command/info.js +40 -38
- package/lib/command/init.js +290 -288
- package/lib/command/interactive.js +32 -32
- package/lib/command/list.js +26 -26
- package/lib/command/run-multiple/chunk.js +5 -5
- package/lib/command/run-multiple/collection.js +3 -3
- package/lib/command/run-multiple/run.js +6 -2
- package/lib/command/run-multiple.js +113 -93
- package/lib/command/run-rerun.js +20 -25
- package/lib/command/run-workers.js +64 -66
- package/lib/command/run.js +26 -29
- package/lib/command/utils.js +80 -65
- package/lib/command/workers/runTests.js +11 -12
- package/lib/config.js +10 -9
- package/lib/container.js +40 -48
- package/lib/data/context.js +60 -59
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +29 -29
- package/lib/data/table.js +26 -20
- package/lib/event.js +163 -167
- package/lib/heal.js +14 -18
- package/lib/helper/AI.js +130 -41
- package/lib/helper/ApiDataFactory.js +74 -70
- package/lib/helper/Appium.js +416 -388
- package/lib/helper/ExpectHelper.js +40 -48
- package/lib/helper/FileSystem.js +80 -79
- package/lib/helper/GraphQL.js +44 -43
- package/lib/helper/GraphQLDataFactory.js +51 -51
- package/lib/helper/JSONResponse.js +65 -62
- package/lib/helper/Mochawesome.js +28 -28
- package/lib/helper/Nightmare.js +664 -571
- package/lib/helper/Playwright.js +1367 -1222
- package/lib/helper/Protractor.js +663 -635
- package/lib/helper/Puppeteer.js +1232 -1132
- package/lib/helper/REST.js +183 -68
- package/lib/helper/SoftExpectHelper.js +2 -2
- package/lib/helper/TestCafe.js +490 -486
- package/lib/helper/WebDriver.js +1246 -1297
- package/lib/helper/clientscripts/PollyWebDriverExt.js +1 -1
- package/lib/helper/errors/ConnectionRefused.js +1 -1
- package/lib/helper/errors/ElementAssertion.js +2 -2
- package/lib/helper/errors/ElementNotFound.js +2 -2
- package/lib/helper/errors/RemoteBrowserConnectionRefused.js +1 -1
- package/lib/helper/extras/Console.js +1 -1
- package/lib/helper/extras/PlaywrightPropEngine.js +4 -4
- package/lib/helper/extras/PlaywrightReactVueLocator.js +1 -1
- package/lib/helper/extras/PlaywrightRestartOpts.js +21 -18
- package/lib/helper/extras/Popup.js +1 -1
- package/lib/helper/extras/React.js +3 -3
- package/lib/helper/network/actions.js +14 -7
- package/lib/helper/network/utils.js +4 -3
- package/lib/helper/scripts/blurElement.js +1 -1
- package/lib/helper/scripts/focusElement.js +1 -1
- package/lib/helper/scripts/highlightElement.js +1 -1
- package/lib/helper/scripts/isElementClickable.js +1 -1
- package/lib/helper/testcafe/testControllerHolder.js +1 -1
- package/lib/helper/testcafe/testcafe-utils.js +7 -8
- package/lib/helper.js +1 -3
- package/lib/history.js +6 -5
- package/lib/hooks.js +6 -6
- package/lib/html.js +7 -7
- package/lib/index.js +25 -41
- package/lib/interfaces/bdd.js +47 -64
- package/lib/interfaces/featureConfig.js +19 -19
- package/lib/interfaces/gherkin.js +124 -118
- package/lib/interfaces/scenarioConfig.js +29 -29
- package/lib/listener/artifacts.js +9 -9
- package/lib/listener/config.js +24 -24
- package/lib/listener/exit.js +12 -12
- package/lib/listener/helpers.js +42 -42
- package/lib/listener/mocha.js +11 -11
- package/lib/listener/retry.js +32 -30
- package/lib/listener/steps.js +50 -53
- package/lib/listener/timeout.js +54 -54
- package/lib/locator.js +7 -11
- package/lib/mochaFactory.js +18 -15
- package/lib/output.js +19 -15
- package/lib/parser.js +15 -12
- package/lib/pause.js +45 -38
- package/lib/plugin/allure.js +15 -15
- package/lib/plugin/autoDelay.js +29 -37
- package/lib/plugin/autoLogin.js +70 -65
- package/lib/plugin/commentStep.js +18 -18
- package/lib/plugin/coverage.js +112 -67
- package/lib/plugin/customLocator.js +21 -20
- package/lib/plugin/debugErrors.js +24 -24
- package/lib/plugin/eachElement.js +38 -38
- package/lib/plugin/fakerTransform.js +6 -6
- package/lib/plugin/heal.js +67 -108
- package/lib/plugin/pauseOnFail.js +11 -11
- package/lib/plugin/retryFailedStep.js +32 -39
- package/lib/plugin/retryTo.js +46 -40
- package/lib/plugin/screenshotOnFail.js +109 -87
- package/lib/plugin/selenoid.js +131 -118
- package/lib/plugin/standardActingHelpers.js +2 -8
- package/lib/plugin/stepByStepReport.js +110 -91
- package/lib/plugin/stepTimeout.js +24 -23
- package/lib/plugin/subtitles.js +34 -35
- package/lib/plugin/tryTo.js +40 -30
- package/lib/plugin/wdio.js +78 -75
- package/lib/recorder.js +14 -17
- package/lib/rerun.js +11 -10
- package/lib/scenario.js +25 -23
- package/lib/secret.js +4 -3
- package/lib/session.js +10 -10
- package/lib/step.js +12 -9
- package/lib/store.js +2 -3
- package/lib/transform.js +1 -1
- package/lib/translation.js +7 -8
- package/lib/ui.js +12 -14
- package/lib/utils.js +70 -72
- package/lib/within.js +10 -10
- package/lib/workerStorage.js +27 -25
- package/lib/workers.js +29 -33
- package/package.json +67 -68
- package/translations/de-DE.js +2 -1
- package/translations/fr-FR.js +2 -2
- package/translations/index.js +9 -13
- package/translations/it-IT.js +1 -1
- package/translations/ja-JP.js +1 -1
- package/translations/pl-PL.js +1 -1
- package/translations/pt-BR.js +1 -1
- package/translations/ru-RU.js +1 -1
- package/translations/zh-CN.js +1 -1
- package/translations/zh-TW.js +1 -1
- package/typings/index.d.ts +423 -65
- package/typings/promiseBasedTypes.d.ts +41 -172
- package/typings/types.d.ts +43 -178
- package/lib/dirname.js +0 -5
- package/lib/helper/Expect.js +0 -425
- package/lib/helper/MockServer.js +0 -223
package/lib/codecept.js
CHANGED
|
@@ -1,228 +1,218 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
14
|
+
* CodeceptJS runner
|
|
38
15
|
*/
|
|
39
|
-
|
|
16
|
+
class Codecept {
|
|
40
17
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
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
|
|
27
|
+
this.testFiles = new Array(0);
|
|
28
|
+
this.requireModules(config.require);
|
|
50
29
|
}
|
|
51
30
|
|
|
52
31
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
32
|
+
* Require modules before codeceptjs running
|
|
33
|
+
*
|
|
34
|
+
* @param {string[]} requiringModules
|
|
55
35
|
*/
|
|
56
36
|
requireModules(requiringModules) {
|
|
57
|
-
requiringModules
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
*
|
|
66
|
-
*
|
|
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
|
-
*
|
|
76
|
-
*
|
|
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
|
-
|
|
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;
|
|
95
|
+
|
|
96
|
+
// mask sensitive data
|
|
97
|
+
global.maskSensitiveData = this.config.maskSensitiveData || false;
|
|
86
98
|
}
|
|
87
99
|
}
|
|
88
100
|
|
|
89
101
|
/**
|
|
90
|
-
*
|
|
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.
|
|
102
|
+
* Executes hooks.
|
|
116
103
|
*/
|
|
117
104
|
runHooks() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// Run custom hooks
|
|
131
|
-
this.config.hooks.forEach(runHook);
|
|
105
|
+
// default hooks
|
|
106
|
+
runHook(require('./listener/steps'));
|
|
107
|
+
runHook(require('./listener/artifacts'));
|
|
108
|
+
runHook(require('./listener/config'));
|
|
109
|
+
runHook(require('./listener/helpers'));
|
|
110
|
+
runHook(require('./listener/retry'));
|
|
111
|
+
runHook(require('./listener/timeout'));
|
|
112
|
+
runHook(require('./listener/exit'));
|
|
113
|
+
|
|
114
|
+
// custom hooks (previous iteration of plugins)
|
|
115
|
+
this.config.hooks.forEach(hook => runHook(hook));
|
|
132
116
|
}
|
|
133
117
|
|
|
134
118
|
/**
|
|
135
|
-
* Executes
|
|
119
|
+
* Executes bootstrap.
|
|
120
|
+
*
|
|
136
121
|
*/
|
|
137
122
|
async bootstrap() {
|
|
138
123
|
return runHook(this.config.bootstrap, 'bootstrap');
|
|
139
124
|
}
|
|
140
125
|
|
|
141
126
|
/**
|
|
142
|
-
* Executes
|
|
127
|
+
* Executes teardown.
|
|
128
|
+
|
|
143
129
|
*/
|
|
144
130
|
async teardown() {
|
|
145
131
|
return runHook(this.config.teardown, 'teardown');
|
|
146
132
|
}
|
|
147
133
|
|
|
148
134
|
/**
|
|
149
|
-
* Loads
|
|
150
|
-
*
|
|
135
|
+
* Loads tests by pattern or by config.tests
|
|
136
|
+
*
|
|
137
|
+
* @param {string} [pattern]
|
|
151
138
|
*/
|
|
152
139
|
loadTests(pattern) {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
140
|
+
const options = {
|
|
141
|
+
cwd: global.codecept_dir,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
let patterns = [pattern];
|
|
145
|
+
if (!pattern) {
|
|
146
|
+
patterns = [];
|
|
147
|
+
|
|
148
|
+
// If the user wants to test a specific set of test files as an array or string.
|
|
149
|
+
if (this.config.tests && !this.opts.features) {
|
|
150
|
+
if (Array.isArray(this.config.tests)) {
|
|
151
|
+
patterns.push(...this.config.tests);
|
|
152
|
+
} else {
|
|
153
|
+
patterns.push(this.config.tests);
|
|
165
154
|
}
|
|
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;
|
|
155
|
+
}
|
|
180
156
|
|
|
181
|
-
|
|
182
|
-
|
|
157
|
+
if (this.config.gherkin.features && !this.opts.tests) {
|
|
158
|
+
if (Array.isArray(this.config.gherkin.features)) {
|
|
159
|
+
this.config.gherkin.features.forEach(feature => {
|
|
160
|
+
patterns.push(feature);
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
patterns.push(this.config.gherkin.features);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
183
166
|
}
|
|
184
167
|
|
|
185
|
-
|
|
186
|
-
|
|
168
|
+
for (pattern of patterns) {
|
|
169
|
+
glob.sync(pattern, options).forEach((file) => {
|
|
170
|
+
if (file.includes('node_modules')) return;
|
|
171
|
+
if (!fsPath.isAbsolute(file)) {
|
|
172
|
+
file = fsPath.join(global.codecept_dir, file);
|
|
173
|
+
}
|
|
174
|
+
if (!this.testFiles.includes(fsPath.resolve(file))) {
|
|
175
|
+
this.testFiles.push(fsPath.resolve(file));
|
|
176
|
+
}
|
|
177
|
+
});
|
|
187
178
|
}
|
|
188
|
-
|
|
189
|
-
return patterns;
|
|
190
179
|
}
|
|
191
180
|
|
|
192
181
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
182
|
+
* Run a specific test or all loaded tests.
|
|
183
|
+
*
|
|
184
|
+
* @param {string} [test]
|
|
195
185
|
* @returns {Promise<void>}
|
|
196
186
|
*/
|
|
197
187
|
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
188
|
return new Promise((resolve, reject) => {
|
|
189
|
+
const mocha = container.mocha();
|
|
190
|
+
mocha.files = this.testFiles;
|
|
191
|
+
if (test) {
|
|
192
|
+
if (!fsPath.isAbsolute(test)) {
|
|
193
|
+
test = fsPath.join(global.codecept_dir, test);
|
|
194
|
+
}
|
|
195
|
+
mocha.files = mocha.files.filter(t => fsPath.basename(t, '.js') === test || t === test);
|
|
196
|
+
}
|
|
197
|
+
const done = () => {
|
|
198
|
+
event.emit(event.all.result, this);
|
|
199
|
+
event.emit(event.all.after, this);
|
|
200
|
+
resolve();
|
|
201
|
+
};
|
|
202
|
+
|
|
207
203
|
try {
|
|
208
204
|
event.emit(event.all.before, this);
|
|
209
|
-
mocha.run(() =>
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
});
|
|
214
|
-
} catch (error) {
|
|
215
|
-
output.output.error(error.stack);
|
|
216
|
-
reject(error);
|
|
205
|
+
mocha.run(() => done());
|
|
206
|
+
} catch (e) {
|
|
207
|
+
output.error(e.stack);
|
|
208
|
+
reject(e);
|
|
217
209
|
}
|
|
218
210
|
});
|
|
219
211
|
}
|
|
220
|
-
}
|
|
221
212
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
*/
|
|
226
|
-
export function version() {
|
|
227
|
-
return JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf8')).version;
|
|
213
|
+
static version() {
|
|
214
|
+
return JSON.parse(readFileSync(`${__dirname}/../package.json`, 'utf8')).version;
|
|
215
|
+
}
|
|
228
216
|
}
|
|
217
|
+
|
|
218
|
+
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
251
|
+
module.exports = {
|
|
252
252
|
isColorProperty,
|
|
253
253
|
convertColorToRGBA,
|
|
254
254
|
convertColorNameToHex,
|
|
@@ -1,70 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
12
|
-
|
|
8
|
+
const { print, success, error } = require('../output')
|
|
9
|
+
const { fileExists } = require('../utils')
|
|
10
|
+
const { getTestRoot } = require('./utils')
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
27
|
+
print(`Migrating ${colors.magenta.bold('.js')} config to ${colors.bold(testsPath)}`)
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
if (!fileExists(testsPath)) {
|
|
28
|
-
|
|
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
|
-
|
|
35
|
-
return
|
|
37
|
+
error(`Config is already created at ${configFile}`)
|
|
38
|
+
return
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
inquirer
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
68
|
-
}
|
|
69
|
-
});
|
|
73
|
+
finish()
|
|
74
|
+
}
|
|
75
|
+
})
|
|
70
76
|
}
|