codeceptjs 3.6.7 → 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.
- package/bin/codecept.js +81 -84
- package/lib/actor.js +13 -13
- package/lib/ai.js +13 -10
- package/lib/assert/empty.js +21 -20
- package/lib/assert/equal.js +39 -37
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +47 -46
- package/lib/assert/throws.js +11 -13
- package/lib/assert/truth.js +22 -19
- package/lib/assert.js +2 -4
- package/lib/cli.js +49 -57
- package/lib/codecept.js +155 -142
- package/lib/colorUtils.js +3 -3
- package/lib/command/configMigrate.js +52 -58
- package/lib/command/definitions.js +89 -88
- package/lib/command/dryRun.js +68 -71
- package/lib/command/generate.js +188 -197
- package/lib/command/gherkin/init.js +16 -27
- package/lib/command/gherkin/snippets.js +20 -20
- package/lib/command/gherkin/steps.js +8 -8
- package/lib/command/info.js +38 -40
- package/lib/command/init.js +288 -290
- 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 +2 -6
- package/lib/command/run-multiple.js +93 -113
- package/lib/command/run-rerun.js +25 -20
- package/lib/command/run-workers.js +66 -64
- package/lib/command/run.js +29 -26
- package/lib/command/utils.js +65 -80
- package/lib/command/workers/runTests.js +10 -10
- package/lib/config.js +9 -10
- package/lib/container.js +48 -40
- package/lib/data/context.js +59 -60
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +29 -29
- package/lib/data/table.js +20 -26
- package/lib/dirname.js +5 -0
- package/lib/event.js +167 -163
- package/lib/heal.js +17 -13
- package/lib/helper/AI.js +41 -130
- package/lib/helper/ApiDataFactory.js +69 -73
- package/lib/helper/Appium.js +381 -412
- package/lib/helper/Expect.js +425 -0
- package/lib/helper/ExpectHelper.js +48 -40
- package/lib/helper/FileSystem.js +79 -80
- package/lib/helper/GraphQL.js +43 -44
- package/lib/helper/GraphQLDataFactory.js +50 -50
- package/lib/helper/JSONResponse.js +62 -65
- package/lib/helper/Mochawesome.js +28 -28
- package/lib/helper/MockServer.js +14 -12
- package/lib/helper/Nightmare.js +566 -662
- package/lib/helper/Playwright.js +1216 -1361
- package/lib/helper/Protractor.js +627 -663
- package/lib/helper/Puppeteer.js +1128 -1231
- package/lib/helper/REST.js +68 -159
- package/lib/helper/SoftExpectHelper.js +2 -2
- package/lib/helper/TestCafe.js +484 -490
- package/lib/helper/WebDriver.js +1156 -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 +2 -2
- package/lib/helper/extras/PlaywrightReactVueLocator.js +1 -1
- package/lib/helper/extras/PlaywrightRestartOpts.js +18 -21
- package/lib/helper/extras/Popup.js +1 -1
- package/lib/helper/extras/React.js +3 -3
- package/lib/helper/network/actions.js +7 -14
- package/lib/helper/network/utils.js +2 -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 -6
- package/lib/helper.js +3 -1
- package/lib/history.js +5 -6
- package/lib/hooks.js +6 -6
- package/lib/html.js +7 -7
- package/lib/index.js +41 -25
- package/lib/interfaces/bdd.js +64 -47
- package/lib/interfaces/featureConfig.js +19 -19
- package/lib/interfaces/gherkin.js +118 -124
- 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 +30 -32
- package/lib/listener/steps.js +53 -50
- package/lib/listener/timeout.js +54 -54
- package/lib/locator.js +10 -6
- package/lib/mochaFactory.js +15 -18
- package/lib/output.js +10 -6
- package/lib/parser.js +12 -15
- package/lib/pause.js +33 -40
- package/lib/plugin/allure.js +15 -15
- package/lib/plugin/autoDelay.js +37 -29
- package/lib/plugin/autoLogin.js +65 -70
- package/lib/plugin/commentStep.js +18 -18
- package/lib/plugin/coverage.js +67 -115
- package/lib/plugin/customLocator.js +20 -21
- 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 +108 -67
- package/lib/plugin/pauseOnFail.js +11 -11
- package/lib/plugin/retryFailedStep.js +39 -32
- package/lib/plugin/retryTo.js +40 -46
- package/lib/plugin/screenshotOnFail.js +87 -109
- package/lib/plugin/selenoid.js +118 -131
- package/lib/plugin/standardActingHelpers.js +8 -2
- package/lib/plugin/stepByStepReport.js +91 -110
- package/lib/plugin/stepTimeout.js +23 -24
- package/lib/plugin/subtitles.js +35 -34
- package/lib/plugin/tryTo.js +30 -40
- package/lib/plugin/wdio.js +75 -78
- package/lib/recorder.js +17 -14
- package/lib/rerun.js +10 -11
- package/lib/scenario.js +23 -25
- package/lib/secret.js +2 -4
- package/lib/session.js +10 -10
- package/lib/step.js +9 -12
- package/lib/store.js +3 -2
- package/lib/transform.js +1 -1
- package/lib/translation.js +8 -7
- package/lib/ui.js +14 -12
- package/lib/utils.js +72 -70
- package/lib/within.js +10 -10
- package/lib/workerStorage.js +25 -27
- package/lib/workers.js +32 -29
- package/package.json +53 -51
- package/translations/de-DE.js +1 -1
- package/translations/fr-FR.js +1 -1
- package/translations/index.js +13 -9
- 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 +65 -415
package/lib/codecept.js
CHANGED
|
@@ -1,215 +1,228 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
*
|
|
19
|
-
*
|
|
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 =
|
|
28
|
-
this.requireModules(config
|
|
48
|
+
this.testFiles = [];
|
|
49
|
+
this.requireModules(config?.require);
|
|
29
50
|
}
|
|
30
51
|
|
|
31
52
|
/**
|
|
32
|
-
*
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
*
|
|
50
|
-
*
|
|
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
|
-
*
|
|
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 =
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
|
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
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
166
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
186
|
-
|
|
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(() =>
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
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
|
-
|
|
251
|
+
export default {
|
|
252
252
|
isColorProperty,
|
|
253
253
|
convertColorToRGBA,
|
|
254
254
|
convertColorNameToHex,
|
|
@@ -1,76 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
const
|
|
10
|
-
const { getTestRoot } = require('./utils')
|
|
11
|
+
export default function (initPath) {
|
|
12
|
+
const testsPath = getTestRoot(initPath);
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
66
|
+
};
|
|
67
|
+
finish();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
76
70
|
}
|