codeceptjs 3.6.4 → 3.6.5-beta.2
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 -63
- package/lib/assert/empty.js +19 -19
- package/lib/assert/equal.js +32 -30
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +42 -42
- package/lib/assert/throws.js +13 -11
- package/lib/assert/truth.js +17 -18
- package/lib/command/configMigrate.js +57 -52
- package/lib/command/definitions.js +88 -88
- package/lib/command/dryRun.js +65 -63
- package/lib/command/generate.js +191 -181
- package/lib/command/info.js +39 -37
- package/lib/command/init.js +289 -286
- package/lib/command/interactive.js +32 -32
- package/lib/command/list.js +26 -26
- package/lib/command/run-multiple.js +113 -93
- package/lib/command/run-rerun.js +22 -22
- package/lib/command/run-workers.js +63 -63
- package/lib/command/run.js +24 -26
- package/lib/command/utils.js +64 -63
- package/lib/data/context.js +60 -60
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +29 -29
- package/lib/data/table.js +26 -20
- package/lib/helper/AI.js +67 -65
- package/lib/helper/ApiDataFactory.js +72 -69
- package/lib/helper/Appium.js +409 -379
- package/lib/helper/ExpectHelper.js +214 -248
- package/lib/helper/FileSystem.js +77 -78
- package/lib/helper/GraphQL.js +44 -43
- package/lib/helper/GraphQLDataFactory.js +49 -50
- package/lib/helper/JSONResponse.js +64 -62
- package/lib/helper/Mochawesome.js +28 -28
- package/lib/helper/MockServer.js +12 -12
- package/lib/helper/Nightmare.js +664 -572
- package/lib/helper/Playwright.js +1320 -1211
- package/lib/helper/Protractor.js +663 -629
- package/lib/helper/Puppeteer.js +1232 -1124
- package/lib/helper/REST.js +87 -72
- package/lib/helper/TestCafe.js +490 -491
- package/lib/helper/WebDriver.js +1294 -1156
- package/lib/interfaces/bdd.js +38 -51
- package/lib/interfaces/featureConfig.js +19 -19
- package/lib/interfaces/gherkin.js +122 -111
- package/lib/interfaces/scenarioConfig.js +29 -29
- package/lib/listener/artifacts.js +9 -9
- package/lib/listener/config.js +24 -23
- 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 -51
- package/lib/listener/timeout.js +53 -53
- package/lib/plugin/allure.js +14 -14
- package/lib/plugin/autoDelay.js +29 -36
- package/lib/plugin/autoLogin.js +70 -66
- package/lib/plugin/commentStep.js +18 -18
- package/lib/plugin/coverage.js +92 -77
- package/lib/plugin/customLocator.js +20 -19
- package/lib/plugin/debugErrors.js +24 -24
- package/lib/plugin/eachElement.js +37 -37
- package/lib/plugin/fakerTransform.js +6 -6
- package/lib/plugin/heal.js +66 -63
- package/lib/plugin/pauseOnFail.js +10 -10
- package/lib/plugin/retryFailedStep.js +31 -38
- package/lib/plugin/retryTo.js +28 -28
- package/lib/plugin/screenshotOnFail.js +107 -86
- package/lib/plugin/selenoid.js +131 -117
- package/lib/plugin/standardActingHelpers.js +2 -8
- package/lib/plugin/stepByStepReport.js +102 -92
- package/lib/plugin/stepTimeout.js +23 -22
- package/lib/plugin/subtitles.js +34 -34
- package/lib/plugin/tryTo.js +39 -29
- package/lib/plugin/wdio.js +77 -72
- package/lib/template/heal.js +11 -14
- package/package.json +4 -2
- package/translations/de-DE.js +1 -1
- package/translations/fr-FR.js +1 -1
- package/translations/index.js +9 -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/promiseBasedTypes.d.ts +238 -0
- package/typings/types.d.ts +32 -0
package/lib/assert/truth.js
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
const Assertion = require('../assert')
|
|
2
|
-
const AssertionFailedError = require('./error')
|
|
3
|
-
const { template } = require('../utils')
|
|
4
|
-
const output = require('../output')
|
|
1
|
+
const Assertion = require('../assert')
|
|
2
|
+
const AssertionFailedError = require('./error')
|
|
3
|
+
const { template } = require('../utils')
|
|
4
|
+
const output = require('../output')
|
|
5
5
|
|
|
6
6
|
class TruthAssertion extends Assertion {
|
|
7
7
|
constructor(params) {
|
|
8
8
|
super((value) => {
|
|
9
9
|
if (Array.isArray(value)) {
|
|
10
|
-
return value.filter(val => !!val).length > 0
|
|
10
|
+
return value.filter((val) => !!val).length > 0
|
|
11
11
|
}
|
|
12
|
-
return !!value
|
|
13
|
-
}, params)
|
|
14
|
-
this.params.type = this.params.type || 'to be true'
|
|
12
|
+
return !!value
|
|
13
|
+
}, params)
|
|
14
|
+
this.params.type = this.params.type || 'to be true'
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
getException() {
|
|
18
|
-
const err = new AssertionFailedError(this.params, '{{customMessage}}expected {{subject}} {{type}}')
|
|
18
|
+
const err = new AssertionFailedError(this.params, '{{customMessage}}expected {{subject}} {{type}}')
|
|
19
19
|
err.cliMessage = () => {
|
|
20
|
-
const msg = err.template
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return err;
|
|
20
|
+
const msg = err.template.replace('{{subject}}', output.colors.bold('{{subject}}'))
|
|
21
|
+
return template(msg, this.params)
|
|
22
|
+
}
|
|
23
|
+
return err
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
addAssertParams() {
|
|
28
|
-
this.params.value = this.params.actual = arguments[0]
|
|
29
|
-
this.params.expected = true
|
|
30
|
-
this.params.customMessage = arguments[1] ? `${arguments[1]}\n\n` : ''
|
|
27
|
+
this.params.value = this.params.actual = arguments[0]
|
|
28
|
+
this.params.expected = true
|
|
29
|
+
this.params.customMessage = arguments[1] ? `${arguments[1]}\n\n` : ''
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
module.exports = {
|
|
35
34
|
Assertion: TruthAssertion,
|
|
36
35
|
truth: (subject, type) => new TruthAssertion({ subject, type }),
|
|
37
|
-
}
|
|
36
|
+
}
|
|
@@ -1,71 +1,76 @@
|
|
|
1
|
-
const colors = require('chalk')
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const inquirer = require('inquirer')
|
|
4
|
-
const mkdirp = require('mkdirp')
|
|
5
|
-
const path = require('path')
|
|
6
|
-
const util = require('util')
|
|
1
|
+
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')
|
|
7
7
|
|
|
8
|
-
const { print, success, error } = require('../output')
|
|
9
|
-
const { fileExists } = require('../utils')
|
|
10
|
-
const { getTestRoot } = require('./utils')
|
|
8
|
+
const { print, success, error } = require('../output')
|
|
9
|
+
const { fileExists } = require('../utils')
|
|
10
|
+
const { getTestRoot } = require('./utils')
|
|
11
11
|
|
|
12
12
|
module.exports = function (initPath) {
|
|
13
|
-
const testsPath = getTestRoot(initPath)
|
|
13
|
+
const testsPath = getTestRoot(initPath)
|
|
14
14
|
|
|
15
|
-
print()
|
|
16
|
-
print(` Welcome to ${colors.magenta.bold('CodeceptJS')} configuration migration tool`)
|
|
17
|
-
print(
|
|
18
|
-
|
|
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()
|
|
19
21
|
|
|
20
22
|
if (!path) {
|
|
21
|
-
print('No config file is specified.')
|
|
22
|
-
print(`Test root is assumed to be ${colors.yellow.bold(testsPath)}`)
|
|
23
|
-
print('----------------------------------')
|
|
23
|
+
print('No config file is specified.')
|
|
24
|
+
print(`Test root is assumed to be ${colors.yellow.bold(testsPath)}`)
|
|
25
|
+
print('----------------------------------')
|
|
24
26
|
} else {
|
|
25
|
-
print(`Migrating ${colors.magenta.bold('.js')} config to ${colors.bold(testsPath)}`)
|
|
27
|
+
print(`Migrating ${colors.magenta.bold('.js')} config to ${colors.bold(testsPath)}`)
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
if (!fileExists(testsPath)) {
|
|
29
|
-
print(`Directory ${testsPath} does not exist, creating...`)
|
|
30
|
-
mkdirp.sync(testsPath)
|
|
31
|
+
print(`Directory ${testsPath} does not exist, creating...`)
|
|
32
|
+
mkdirp.sync(testsPath)
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
const configFile = path.join(testsPath, 'codecept.conf.js')
|
|
35
|
+
const configFile = path.join(testsPath, 'codecept.conf.js')
|
|
34
36
|
if (fileExists(configFile)) {
|
|
35
|
-
error(`Config is already created at ${configFile}`)
|
|
36
|
-
return
|
|
37
|
+
error(`Config is already created at ${configFile}`)
|
|
38
|
+
return
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
inquirer
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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()
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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}`)
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
if (result.delete) {
|
|
67
|
+
if (fileExists(jsonConfigFile)) {
|
|
68
|
+
fs.unlinkSync(jsonConfigFile)
|
|
69
|
+
success('JSON config file is deleted!')
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
};
|
|
73
|
+
finish()
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const path = require('path')
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
3
|
|
|
4
|
-
const { getConfig, getTestRoot } = require('./utils')
|
|
5
|
-
const Codecept = require('../codecept')
|
|
6
|
-
const container = require('../container')
|
|
7
|
-
const output = require('../output')
|
|
8
|
-
const actingHelpers = [...require('../plugin/standardActingHelpers'), 'REST']
|
|
4
|
+
const { getConfig, getTestRoot } = require('./utils')
|
|
5
|
+
const Codecept = require('../codecept')
|
|
6
|
+
const container = require('../container')
|
|
7
|
+
const output = require('../output')
|
|
8
|
+
const actingHelpers = [...require('../plugin/standardActingHelpers'), 'REST']
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Prepare data and generate content of definitions file
|
|
@@ -29,32 +29,27 @@ const getDefinitionsFileContent = ({
|
|
|
29
29
|
importPaths,
|
|
30
30
|
translations,
|
|
31
31
|
}) => {
|
|
32
|
-
const getHelperListFragment = ({
|
|
33
|
-
hasCustomHelper,
|
|
34
|
-
hasCustomStepsFile,
|
|
35
|
-
}) => {
|
|
32
|
+
const getHelperListFragment = ({ hasCustomHelper, hasCustomStepsFile }) => {
|
|
36
33
|
if (hasCustomHelper && hasCustomStepsFile) {
|
|
37
|
-
return `${['ReturnType<steps_file>', 'WithTranslation<Methods>'].join(', ')}
|
|
34
|
+
return `${['ReturnType<steps_file>', 'WithTranslation<Methods>'].join(', ')}`
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
if (hasCustomStepsFile) {
|
|
41
|
-
return 'ReturnType<steps_file>'
|
|
38
|
+
return 'ReturnType<steps_file>'
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
return 'WithTranslation<Methods>'
|
|
45
|
-
}
|
|
41
|
+
return 'WithTranslation<Methods>'
|
|
42
|
+
}
|
|
46
43
|
|
|
47
44
|
const helpersListFragment = getHelperListFragment({
|
|
48
45
|
hasCustomHelper,
|
|
49
46
|
hasCustomStepsFile,
|
|
50
|
-
})
|
|
47
|
+
})
|
|
51
48
|
|
|
52
|
-
const importPathsFragment = importPaths.join('\n')
|
|
53
|
-
const supportObjectsTypeFragment = convertMapToType(supportObject)
|
|
54
|
-
const methodsTypeFragment = helperNames.length > 0
|
|
55
|
-
|
|
56
|
-
: '';
|
|
57
|
-
const translatedActionsFragment = JSON.stringify(translations.vocabulary.actions, null, 2);
|
|
49
|
+
const importPathsFragment = importPaths.join('\n')
|
|
50
|
+
const supportObjectsTypeFragment = convertMapToType(supportObject)
|
|
51
|
+
const methodsTypeFragment = helperNames.length > 0 ? `interface Methods extends ${helperNames.join(', ')} {}` : ''
|
|
52
|
+
const translatedActionsFragment = JSON.stringify(translations.vocabulary.actions, null, 2)
|
|
58
53
|
|
|
59
54
|
return generateDefinitionsContent({
|
|
60
55
|
helpersListFragment,
|
|
@@ -62,8 +57,8 @@ const getDefinitionsFileContent = ({
|
|
|
62
57
|
supportObjectsTypeFragment,
|
|
63
58
|
methodsTypeFragment,
|
|
64
59
|
translatedActionsFragment,
|
|
65
|
-
})
|
|
66
|
-
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
67
62
|
|
|
68
63
|
/**
|
|
69
64
|
* Generate content for definitions file from fragments
|
|
@@ -96,83 +91,83 @@ declare namespace CodeceptJS {
|
|
|
96
91
|
interface Actions ${translatedActionsFragment}
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
|
-
|
|
100
|
-
}
|
|
94
|
+
`
|
|
95
|
+
}
|
|
101
96
|
|
|
102
97
|
/** @type {Array<string>} */
|
|
103
|
-
const helperNames = []
|
|
98
|
+
const helperNames = []
|
|
104
99
|
/** @type {Array<string>} */
|
|
105
|
-
const customHelpers = []
|
|
100
|
+
const customHelpers = []
|
|
106
101
|
|
|
107
102
|
module.exports = function (genPath, options) {
|
|
108
|
-
const configFile = options.config || genPath
|
|
103
|
+
const configFile = options.config || genPath
|
|
109
104
|
/** @type {string} */
|
|
110
|
-
const testsPath = getTestRoot(configFile)
|
|
111
|
-
const config = getConfig(configFile)
|
|
112
|
-
if (!config) return
|
|
105
|
+
const testsPath = getTestRoot(configFile)
|
|
106
|
+
const config = getConfig(configFile)
|
|
107
|
+
if (!config) return
|
|
113
108
|
|
|
114
109
|
/** @type {Object<string, string>} */
|
|
115
|
-
const helperPaths = {}
|
|
110
|
+
const helperPaths = {}
|
|
116
111
|
/** @type {Object<string, string>} */
|
|
117
|
-
const supportPaths = {}
|
|
112
|
+
const supportPaths = {}
|
|
118
113
|
/** @type {boolean} */
|
|
119
|
-
let hasCustomStepsFile = false
|
|
114
|
+
let hasCustomStepsFile = false
|
|
120
115
|
/** @type {boolean} */
|
|
121
|
-
let hasCustomHelper = false
|
|
116
|
+
let hasCustomHelper = false
|
|
122
117
|
|
|
123
118
|
/** @type {string} */
|
|
124
|
-
const targetFolderPath = options.output && getTestRoot(options.output) || testsPath
|
|
119
|
+
const targetFolderPath = (options.output && getTestRoot(options.output)) || testsPath
|
|
125
120
|
|
|
126
|
-
const codecept = new Codecept(config, {})
|
|
127
|
-
codecept.init(testsPath)
|
|
121
|
+
const codecept = new Codecept(config, {})
|
|
122
|
+
codecept.init(testsPath)
|
|
128
123
|
|
|
129
|
-
const helpers = container.helpers()
|
|
130
|
-
const translations = container.translation()
|
|
124
|
+
const helpers = container.helpers()
|
|
125
|
+
const translations = container.translation()
|
|
131
126
|
for (const name in helpers) {
|
|
132
|
-
const require = codecept.config.helpers[name].require
|
|
127
|
+
const require = codecept.config.helpers[name].require
|
|
133
128
|
if (require) {
|
|
134
|
-
helperPaths[name] = require
|
|
135
|
-
helperNames.push(name)
|
|
129
|
+
helperPaths[name] = require
|
|
130
|
+
helperNames.push(name)
|
|
136
131
|
} else {
|
|
137
|
-
const fullBasedPromised = codecept.config.fullPromiseBased
|
|
138
|
-
helperNames.push(fullBasedPromised === true ? `${name}Ts` : name)
|
|
132
|
+
const fullBasedPromised = codecept.config.fullPromiseBased
|
|
133
|
+
helperNames.push(fullBasedPromised === true ? `${name}Ts` : name)
|
|
139
134
|
}
|
|
140
135
|
|
|
141
136
|
if (!actingHelpers.includes(name)) {
|
|
142
|
-
customHelpers.push(name)
|
|
137
|
+
customHelpers.push(name)
|
|
143
138
|
}
|
|
144
139
|
}
|
|
145
140
|
|
|
146
|
-
let autoLogin
|
|
141
|
+
let autoLogin
|
|
147
142
|
if (config.plugins.autoLogin) {
|
|
148
|
-
autoLogin = config.plugins.autoLogin.inject
|
|
143
|
+
autoLogin = config.plugins.autoLogin.inject
|
|
149
144
|
}
|
|
150
145
|
|
|
151
|
-
const supportObject = new Map()
|
|
152
|
-
supportObject.set('I', 'I')
|
|
153
|
-
supportObject.set('current', 'any')
|
|
146
|
+
const supportObject = new Map()
|
|
147
|
+
supportObject.set('I', 'I')
|
|
148
|
+
supportObject.set('current', 'any')
|
|
154
149
|
|
|
155
150
|
if (translations.loaded) {
|
|
156
|
-
supportObject.set(translations.I, translations.I)
|
|
151
|
+
supportObject.set(translations.I, translations.I)
|
|
157
152
|
}
|
|
158
153
|
|
|
159
154
|
if (autoLogin) {
|
|
160
|
-
supportObject.set(autoLogin, 'any')
|
|
155
|
+
supportObject.set(autoLogin, 'any')
|
|
161
156
|
}
|
|
162
157
|
|
|
163
158
|
if (customHelpers.length > 0) {
|
|
164
|
-
hasCustomHelper = true
|
|
159
|
+
hasCustomHelper = true
|
|
165
160
|
}
|
|
166
161
|
|
|
167
162
|
for (const name in codecept.config.include) {
|
|
168
|
-
const includePath = codecept.config.include[name]
|
|
163
|
+
const includePath = codecept.config.include[name]
|
|
169
164
|
if (name === 'I' || name === translations.I) {
|
|
170
|
-
hasCustomStepsFile = true
|
|
171
|
-
supportPaths.steps_file = includePath
|
|
172
|
-
continue
|
|
165
|
+
hasCustomStepsFile = true
|
|
166
|
+
supportPaths.steps_file = includePath
|
|
167
|
+
continue
|
|
173
168
|
}
|
|
174
|
-
supportPaths[name] = includePath
|
|
175
|
-
supportObject.set(name, name)
|
|
169
|
+
supportPaths[name] = includePath
|
|
170
|
+
supportObject.set(name, name)
|
|
176
171
|
}
|
|
177
172
|
|
|
178
173
|
let definitionsFileContent = getDefinitionsFileContent({
|
|
@@ -182,31 +177,34 @@ module.exports = function (genPath, options) {
|
|
|
182
177
|
translations,
|
|
183
178
|
hasCustomStepsFile,
|
|
184
179
|
hasCustomHelper,
|
|
185
|
-
})
|
|
180
|
+
})
|
|
186
181
|
|
|
187
182
|
// add aliases for translations
|
|
188
183
|
if (translations.loaded) {
|
|
189
|
-
const namespaceTranslationAliases = []
|
|
190
|
-
namespaceTranslationAliases.push(`interface ${translations.vocabulary.I} extends WithTranslation<Methods> {}`)
|
|
184
|
+
const namespaceTranslationAliases = []
|
|
185
|
+
namespaceTranslationAliases.push(`interface ${translations.vocabulary.I} extends WithTranslation<Methods> {}`)
|
|
191
186
|
|
|
192
|
-
namespaceTranslationAliases.push(' namespace Translation {')
|
|
193
|
-
definitionsFileContent = definitionsFileContent.replace(
|
|
187
|
+
namespaceTranslationAliases.push(' namespace Translation {')
|
|
188
|
+
definitionsFileContent = definitionsFileContent.replace(
|
|
189
|
+
'namespace Translation {',
|
|
190
|
+
namespaceTranslationAliases.join('\n'),
|
|
191
|
+
)
|
|
194
192
|
|
|
195
|
-
const translationAliases = []
|
|
193
|
+
const translationAliases = []
|
|
196
194
|
|
|
197
195
|
if (translations.vocabulary.contexts) {
|
|
198
|
-
Object.keys(translations.vocabulary.contexts).forEach(k => {
|
|
199
|
-
translationAliases.push(`declare const ${translations.vocabulary.contexts[k]}: typeof ${k};`)
|
|
200
|
-
})
|
|
196
|
+
Object.keys(translations.vocabulary.contexts).forEach((k) => {
|
|
197
|
+
translationAliases.push(`declare const ${translations.vocabulary.contexts[k]}: typeof ${k};`)
|
|
198
|
+
})
|
|
201
199
|
}
|
|
202
200
|
|
|
203
|
-
definitionsFileContent += `\n${translationAliases.join('\n')}
|
|
201
|
+
definitionsFileContent += `\n${translationAliases.join('\n')}`
|
|
204
202
|
}
|
|
205
203
|
|
|
206
|
-
fs.writeFileSync(path.join(targetFolderPath, 'steps.d.ts'), definitionsFileContent)
|
|
207
|
-
output.print('TypeScript Definitions provide autocompletion in Visual Studio Code and other IDEs')
|
|
208
|
-
output.print('Definitions were generated in steps.d.ts')
|
|
209
|
-
}
|
|
204
|
+
fs.writeFileSync(path.join(targetFolderPath, 'steps.d.ts'), definitionsFileContent)
|
|
205
|
+
output.print('TypeScript Definitions provide autocompletion in Visual Studio Code and other IDEs')
|
|
206
|
+
output.print('Definitions were generated in steps.d.ts')
|
|
207
|
+
}
|
|
210
208
|
|
|
211
209
|
/**
|
|
212
210
|
* Returns the relative path from the to the targeted folder.
|
|
@@ -215,13 +213,13 @@ module.exports = function (genPath, options) {
|
|
|
215
213
|
* @param {string} testsPath
|
|
216
214
|
*/
|
|
217
215
|
function getPath(originalPath, targetFolderPath, testsPath) {
|
|
218
|
-
const parsedPath = path.parse(originalPath)
|
|
216
|
+
const parsedPath = path.parse(originalPath)
|
|
219
217
|
|
|
220
218
|
// Remove typescript extension if exists.
|
|
221
|
-
if (parsedPath.base.endsWith('.d.ts')) parsedPath.base = parsedPath.base.substring(0, parsedPath.base.length - 5)
|
|
222
|
-
else if (parsedPath.ext === '.ts') parsedPath.base = parsedPath.name
|
|
219
|
+
if (parsedPath.base.endsWith('.d.ts')) parsedPath.base = parsedPath.base.substring(0, parsedPath.base.length - 5)
|
|
220
|
+
else if (parsedPath.ext === '.ts') parsedPath.base = parsedPath.name
|
|
223
221
|
|
|
224
|
-
if (!parsedPath.dir.startsWith('.')) return path.posix.join(parsedPath.dir, parsedPath.base)
|
|
222
|
+
if (!parsedPath.dir.startsWith('.')) return path.posix.join(parsedPath.dir, parsedPath.base)
|
|
225
223
|
const relativePath = path.posix.relative(
|
|
226
224
|
targetFolderPath.split(path.sep).join(path.posix.sep),
|
|
227
225
|
path.posix.join(
|
|
@@ -229,9 +227,9 @@ function getPath(originalPath, targetFolderPath, testsPath) {
|
|
|
229
227
|
parsedPath.dir.split(path.sep).join(path.posix.sep),
|
|
230
228
|
parsedPath.base.split(path.sep).join(path.posix.sep),
|
|
231
229
|
),
|
|
232
|
-
)
|
|
230
|
+
)
|
|
233
231
|
|
|
234
|
-
return relativePath.startsWith('.') ? relativePath : `./${relativePath}
|
|
232
|
+
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`
|
|
235
233
|
}
|
|
236
234
|
|
|
237
235
|
/**
|
|
@@ -245,19 +243,19 @@ function getPath(originalPath, targetFolderPath, testsPath) {
|
|
|
245
243
|
* @returns {Array<string>}
|
|
246
244
|
*/
|
|
247
245
|
function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue) {
|
|
248
|
-
const importStrings = []
|
|
246
|
+
const importStrings = []
|
|
249
247
|
|
|
250
248
|
for (const name in pathsToType) {
|
|
251
|
-
const relativePath = getPath(pathsToType[name], targetFolderPath, testsPath)
|
|
252
|
-
importStrings.push(`type ${name} = typeof import('${relativePath}');`)
|
|
249
|
+
const relativePath = getPath(pathsToType[name], targetFolderPath, testsPath)
|
|
250
|
+
importStrings.push(`type ${name} = typeof import('${relativePath}');`)
|
|
253
251
|
}
|
|
254
252
|
|
|
255
253
|
for (const name in pathsToValue) {
|
|
256
|
-
const relativePath = getPath(pathsToValue[name], targetFolderPath, testsPath)
|
|
257
|
-
importStrings.push(`type ${name} = import('${relativePath}');`)
|
|
254
|
+
const relativePath = getPath(pathsToValue[name], targetFolderPath, testsPath)
|
|
255
|
+
importStrings.push(`type ${name} = import('${relativePath}');`)
|
|
258
256
|
}
|
|
259
257
|
|
|
260
|
-
return importStrings
|
|
258
|
+
return importStrings
|
|
261
259
|
}
|
|
262
260
|
|
|
263
261
|
/**
|
|
@@ -266,5 +264,7 @@ function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue)
|
|
|
266
264
|
* @returns {string}
|
|
267
265
|
*/
|
|
268
266
|
function convertMapToType(map) {
|
|
269
|
-
return `{ ${Array.from(map)
|
|
267
|
+
return `{ ${Array.from(map)
|
|
268
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
269
|
+
.join(', ')} }`
|
|
270
270
|
}
|