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.
- 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 +57 -49
- package/lib/codecept.js +142 -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 +71 -68
- package/lib/command/generate.js +197 -188
- package/lib/command/gherkin/init.js +27 -16
- package/lib/command/gherkin/snippets.js +20 -20
- 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 +10 -10
- 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 +13 -17
- package/lib/helper/AI.js +130 -41
- package/lib/helper/ApiDataFactory.js +73 -69
- package/lib/helper/Appium.js +413 -382
- 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 +50 -50
- package/lib/helper/JSONResponse.js +65 -62
- package/lib/helper/Mochawesome.js +28 -28
- package/lib/helper/MockServer.js +12 -14
- package/lib/helper/Nightmare.js +662 -566
- package/lib/helper/Playwright.js +1361 -1216
- package/lib/helper/Protractor.js +663 -627
- package/lib/helper/Puppeteer.js +1231 -1128
- package/lib/helper/REST.js +159 -68
- package/lib/helper/SoftExpectHelper.js +2 -2
- package/lib/helper/TestCafe.js +490 -484
- package/lib/helper/WebDriver.js +1297 -1156
- 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 +2 -2
- 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 +3 -2
- 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 +6 -7
- 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 +6 -10
- package/lib/mochaFactory.js +18 -15
- package/lib/output.js +6 -10
- package/lib/parser.js +15 -12
- package/lib/pause.js +40 -33
- 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 +115 -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 -2
- 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 -32
- package/package.json +56 -57
- package/translations/de-DE.js +1 -1
- package/translations/fr-FR.js +1 -1
- 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 +415 -65
- package/typings/promiseBasedTypes.d.ts +32 -0
- package/typings/types.d.ts +32 -0
- package/lib/dirname.js +0 -5
- package/lib/helper/Expect.js +0 -425
package/lib/codecept.js
CHANGED
|
@@ -1,228 +1,215 @@
|
|
|
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;
|
|
86
95
|
}
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
/**
|
|
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.
|
|
99
|
+
* Executes hooks.
|
|
116
100
|
*/
|
|
117
101
|
runHooks() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
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
|
|
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
|
|
150
|
-
*
|
|
132
|
+
* Loads tests by pattern or by config.tests
|
|
133
|
+
*
|
|
134
|
+
* @param {string} [pattern]
|
|
151
135
|
*/
|
|
152
136
|
loadTests(pattern) {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
182
|
-
|
|
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
|
-
|
|
186
|
-
|
|
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
|
-
*
|
|
194
|
-
*
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
224
|
-
|
|
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
|
-
|
|
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
|
}
|