codeceptjs 3.7.0-beta.11 → 3.7.0-beta.12
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/lib/codecept.js +12 -10
- package/lib/command/gherkin/snippets.js +69 -69
- package/lib/command/run-multiple/chunk.js +48 -45
- package/lib/container.js +7 -7
- package/lib/mocha/gherkin.js +1 -1
- package/lib/plugin/auth.js +435 -0
- package/lib/plugin/autoLogin.js +3 -337
- package/lib/step/base.js +5 -0
- package/lib/step/comment.js +10 -0
- package/package.json +12 -13
- package/translations/de-DE.js +4 -3
- package/translations/fr-FR.js +4 -3
- package/translations/index.js +1 -0
- package/translations/it-IT.js +4 -3
- package/translations/ja-JP.js +4 -3
- package/translations/nl-NL.js +76 -0
- package/translations/pl-PL.js +4 -3
- package/translations/pt-BR.js +4 -3
- package/translations/ru-RU.js +4 -3
- package/translations/utils.js +9 -0
- package/translations/zh-CN.js +4 -3
- package/translations/zh-TW.js +4 -3
- package/typings/types.d.ts +1 -1
package/lib/codecept.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { existsSync, readFileSync } = require('fs')
|
|
2
|
-
const
|
|
2
|
+
const { globSync } = require('glob')
|
|
3
3
|
const fsPath = require('path')
|
|
4
4
|
const { resolve } = require('path')
|
|
5
5
|
|
|
@@ -168,15 +168,17 @@ class Codecept {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
for (pattern of patterns) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.testFiles.
|
|
178
|
-
|
|
179
|
-
|
|
171
|
+
if (pattern) {
|
|
172
|
+
globSync(pattern, options).forEach(file => {
|
|
173
|
+
if (file.includes('node_modules')) return
|
|
174
|
+
if (!fsPath.isAbsolute(file)) {
|
|
175
|
+
file = fsPath.join(global.codecept_dir, file)
|
|
176
|
+
}
|
|
177
|
+
if (!this.testFiles.includes(fsPath.resolve(file))) {
|
|
178
|
+
this.testFiles.push(fsPath.resolve(file))
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
}
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
|
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
const escapeStringRegexp = require('escape-string-regexp')
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const Gherkin = require('@cucumber/gherkin')
|
|
4
|
-
const Messages = require('@cucumber/messages')
|
|
5
|
-
const
|
|
6
|
-
const fsPath = require('path')
|
|
1
|
+
const escapeStringRegexp = require('escape-string-regexp')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const Gherkin = require('@cucumber/gherkin')
|
|
4
|
+
const Messages = require('@cucumber/messages')
|
|
5
|
+
const { globSync } = require('glob')
|
|
6
|
+
const fsPath = require('path')
|
|
7
7
|
|
|
8
|
-
const { getConfig, getTestRoot } = require('../utils')
|
|
9
|
-
const Codecept = require('../../codecept')
|
|
10
|
-
const output = require('../../output')
|
|
11
|
-
const { matchStep } = require('../../mocha/bdd')
|
|
8
|
+
const { getConfig, getTestRoot } = require('../utils')
|
|
9
|
+
const Codecept = require('../../codecept')
|
|
10
|
+
const output = require('../../output')
|
|
11
|
+
const { matchStep } = require('../../mocha/bdd')
|
|
12
12
|
|
|
13
|
-
const uuidFn = Messages.IdGenerator.uuid()
|
|
14
|
-
const builder = new Gherkin.AstBuilder(uuidFn)
|
|
15
|
-
const matcher = new Gherkin.GherkinClassicTokenMatcher()
|
|
16
|
-
const parser = new Gherkin.Parser(builder, matcher)
|
|
17
|
-
parser.stopAtFirstError = false
|
|
13
|
+
const uuidFn = Messages.IdGenerator.uuid()
|
|
14
|
+
const builder = new Gherkin.AstBuilder(uuidFn)
|
|
15
|
+
const matcher = new Gherkin.GherkinClassicTokenMatcher()
|
|
16
|
+
const parser = new Gherkin.Parser(builder, matcher)
|
|
17
|
+
parser.stopAtFirstError = false
|
|
18
18
|
|
|
19
19
|
module.exports = function (genPath, options) {
|
|
20
|
-
const configFile = options.config || genPath
|
|
21
|
-
const testsPath = getTestRoot(configFile)
|
|
22
|
-
const config = getConfig(configFile)
|
|
23
|
-
if (!config) return
|
|
20
|
+
const configFile = options.config || genPath
|
|
21
|
+
const testsPath = getTestRoot(configFile)
|
|
22
|
+
const config = getConfig(configFile)
|
|
23
|
+
if (!config) return
|
|
24
24
|
|
|
25
|
-
const codecept = new Codecept(config, {})
|
|
26
|
-
codecept.init(testsPath)
|
|
25
|
+
const codecept = new Codecept(config, {})
|
|
26
|
+
codecept.init(testsPath)
|
|
27
27
|
|
|
28
28
|
if (!config.gherkin) {
|
|
29
|
-
output.error('Gherkin is not enabled in config. Run `codecept gherkin:init` to enable it')
|
|
30
|
-
process.exit(1)
|
|
29
|
+
output.error('Gherkin is not enabled in config. Run `codecept gherkin:init` to enable it')
|
|
30
|
+
process.exit(1)
|
|
31
31
|
}
|
|
32
32
|
if (!config.gherkin.steps || !config.gherkin.steps[0]) {
|
|
33
|
-
output.error('No gherkin steps defined in config. Exiting')
|
|
34
|
-
process.exit(1)
|
|
33
|
+
output.error('No gherkin steps defined in config. Exiting')
|
|
34
|
+
process.exit(1)
|
|
35
35
|
}
|
|
36
36
|
if (!options.feature && !config.gherkin.features) {
|
|
37
|
-
output.error('No gherkin features defined in config. Exiting')
|
|
38
|
-
process.exit(1)
|
|
37
|
+
output.error('No gherkin features defined in config. Exiting')
|
|
38
|
+
process.exit(1)
|
|
39
39
|
}
|
|
40
40
|
if (options.path && !config.gherkin.steps.includes(options.path)) {
|
|
41
|
-
output.error(`You must include ${options.path} to the gherkin steps in your config file`)
|
|
42
|
-
process.exit(1)
|
|
41
|
+
output.error(`You must include ${options.path} to the gherkin steps in your config file`)
|
|
42
|
+
process.exit(1)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const files = []
|
|
46
|
-
|
|
45
|
+
const files = []
|
|
46
|
+
globSync(options.feature || config.gherkin.features, { cwd: options.feature ? '.' : global.codecept_dir }).forEach(file => {
|
|
47
47
|
if (!fsPath.isAbsolute(file)) {
|
|
48
|
-
file = fsPath.join(global.codecept_dir, file)
|
|
48
|
+
file = fsPath.join(global.codecept_dir, file)
|
|
49
49
|
}
|
|
50
|
-
files.push(fsPath.resolve(file))
|
|
51
|
-
})
|
|
52
|
-
output.print(`Loaded ${files.length} files`)
|
|
50
|
+
files.push(fsPath.resolve(file))
|
|
51
|
+
})
|
|
52
|
+
output.print(`Loaded ${files.length} files`)
|
|
53
53
|
|
|
54
|
-
const newSteps = new Map()
|
|
54
|
+
const newSteps = new Map()
|
|
55
55
|
|
|
56
56
|
const parseSteps = steps => {
|
|
57
|
-
const newSteps = []
|
|
58
|
-
let currentKeyword = ''
|
|
57
|
+
const newSteps = []
|
|
58
|
+
let currentKeyword = ''
|
|
59
59
|
for (const step of steps) {
|
|
60
60
|
if (step.keyword.trim() === 'And') {
|
|
61
|
-
if (!currentKeyword) throw new Error(`There is no active keyword for step '${step.text}'`)
|
|
62
|
-
step.keyword = currentKeyword
|
|
61
|
+
if (!currentKeyword) throw new Error(`There is no active keyword for step '${step.text}'`)
|
|
62
|
+
step.keyword = currentKeyword
|
|
63
63
|
}
|
|
64
|
-
currentKeyword = step.keyword
|
|
64
|
+
currentKeyword = step.keyword
|
|
65
65
|
try {
|
|
66
|
-
matchStep(step.text)
|
|
66
|
+
matchStep(step.text)
|
|
67
67
|
} catch (err) {
|
|
68
|
-
let stepLine
|
|
68
|
+
let stepLine
|
|
69
69
|
if (/[{}()/]/.test(step.text)) {
|
|
70
70
|
stepLine = escapeStringRegexp(step.text)
|
|
71
71
|
.replace(/\//g, '\\/')
|
|
72
72
|
.replace(/\"(.*?)\"/g, '"(.*?)"')
|
|
73
73
|
.replace(/(\d+\\\.\d+)/, '(\\d+\\.\\d+)')
|
|
74
|
-
.replace(/ (\d+) /, ' (\\d+) ')
|
|
75
|
-
stepLine = Object.assign(stepLine, { type: step.keyword.trim(), location: step.location, regexp: true })
|
|
74
|
+
.replace(/ (\d+) /, ' (\\d+) ')
|
|
75
|
+
stepLine = Object.assign(stepLine, { type: step.keyword.trim(), location: step.location, regexp: true })
|
|
76
76
|
} else {
|
|
77
77
|
stepLine = step.text
|
|
78
78
|
.replace(/\"(.*?)\"/g, '{string}')
|
|
79
79
|
.replace(/(\d+\.\d+)/, '{float}')
|
|
80
|
-
.replace(/ (\d+) /, ' {int} ')
|
|
81
|
-
stepLine = Object.assign(stepLine, { type: step.keyword.trim(), location: step.location, regexp: false })
|
|
80
|
+
.replace(/ (\d+) /, ' {int} ')
|
|
81
|
+
stepLine = Object.assign(stepLine, { type: step.keyword.trim(), location: step.location, regexp: false })
|
|
82
82
|
}
|
|
83
|
-
newSteps.push(stepLine)
|
|
83
|
+
newSteps.push(stepLine)
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
return newSteps
|
|
87
|
-
}
|
|
86
|
+
return newSteps
|
|
87
|
+
}
|
|
88
88
|
|
|
89
89
|
const parseFile = file => {
|
|
90
|
-
const ast = parser.parse(fs.readFileSync(file).toString())
|
|
90
|
+
const ast = parser.parse(fs.readFileSync(file).toString())
|
|
91
91
|
for (const child of ast.feature.children) {
|
|
92
|
-
if (child.scenario.keyword === 'Scenario Outline') continue
|
|
92
|
+
if (child.scenario.keyword === 'Scenario Outline') continue // skip scenario outline
|
|
93
93
|
parseSteps(child.scenario.steps)
|
|
94
94
|
.map(step => {
|
|
95
|
-
return Object.assign(step, { file: file.replace(global.codecept_dir, '').slice(1) })
|
|
95
|
+
return Object.assign(step, { file: file.replace(global.codecept_dir, '').slice(1) })
|
|
96
96
|
})
|
|
97
|
-
.map(step => newSteps.set(`${step.type}(${step})`, step))
|
|
97
|
+
.map(step => newSteps.set(`${step.type}(${step})`, step))
|
|
98
98
|
}
|
|
99
|
-
}
|
|
99
|
+
}
|
|
100
100
|
|
|
101
|
-
files.forEach(file => parseFile(file))
|
|
101
|
+
files.forEach(file => parseFile(file))
|
|
102
102
|
|
|
103
|
-
let stepFile = options.path || config.gherkin.steps[0]
|
|
103
|
+
let stepFile = options.path || config.gherkin.steps[0]
|
|
104
104
|
if (!fs.existsSync(stepFile)) {
|
|
105
|
-
output.error(`Please enter a valid step file path ${stepFile}`)
|
|
106
|
-
process.exit(1)
|
|
105
|
+
output.error(`Please enter a valid step file path ${stepFile}`)
|
|
106
|
+
process.exit(1)
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
if (!fsPath.isAbsolute(stepFile)) {
|
|
110
|
-
stepFile = fsPath.join(global.codecept_dir, stepFile)
|
|
110
|
+
stepFile = fsPath.join(global.codecept_dir, stepFile)
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
const snippets = [...newSteps.values()]
|
|
@@ -117,18 +117,18 @@ module.exports = function (genPath, options) {
|
|
|
117
117
|
${step.type}(${step.regexp ? '/^' : "'"}${step}${step.regexp ? '$/' : "'"}, () => {
|
|
118
118
|
// From "${step.file}" ${JSON.stringify(step.location)}
|
|
119
119
|
throw new Error('Not implemented yet');
|
|
120
|
-
})
|
|
121
|
-
})
|
|
120
|
+
});`
|
|
121
|
+
})
|
|
122
122
|
|
|
123
123
|
if (!snippets.length) {
|
|
124
|
-
output.print('No new snippets found')
|
|
125
|
-
return
|
|
124
|
+
output.print('No new snippets found')
|
|
125
|
+
return
|
|
126
126
|
}
|
|
127
|
-
output.success(`Snippets generated: ${snippets.length}`)
|
|
128
|
-
output.print(snippets.join('\n'))
|
|
127
|
+
output.success(`Snippets generated: ${snippets.length}`)
|
|
128
|
+
output.print(snippets.join('\n'))
|
|
129
129
|
|
|
130
130
|
if (!options.dryRun) {
|
|
131
|
-
output.success(`Snippets added to ${output.colors.bold(stepFile)}`)
|
|
132
|
-
fs.writeFileSync(stepFile, fs.readFileSync(stepFile).toString() + snippets.join('\n') + '\n')
|
|
131
|
+
output.success(`Snippets added to ${output.colors.bold(stepFile)}`)
|
|
132
|
+
fs.writeFileSync(stepFile, fs.readFileSync(stepFile).toString() + snippets.join('\n') + '\n')
|
|
133
133
|
}
|
|
134
|
-
}
|
|
134
|
+
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
const
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const fs = require('fs')
|
|
1
|
+
const { globSync } = require('glob')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const fs = require('fs')
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Splits a list to (n) parts, defined via the size argument.
|
|
7
7
|
*/
|
|
8
8
|
const splitFiles = (list, size) => {
|
|
9
|
-
const sets = []
|
|
10
|
-
const chunks = list.length / size
|
|
11
|
-
let i = 0
|
|
9
|
+
const sets = []
|
|
10
|
+
const chunks = list.length / size
|
|
11
|
+
let i = 0
|
|
12
12
|
|
|
13
13
|
while (i < chunks) {
|
|
14
|
-
sets[i] = list.splice(0, size)
|
|
15
|
-
i
|
|
14
|
+
sets[i] = list.splice(0, size)
|
|
15
|
+
i++
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
return sets
|
|
19
|
-
}
|
|
18
|
+
return sets
|
|
19
|
+
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Executes a glob pattern and pushes the results to a list.
|
|
23
23
|
*/
|
|
24
|
-
const findFiles =
|
|
25
|
-
const files = []
|
|
24
|
+
const findFiles = pattern => {
|
|
25
|
+
const files = []
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
files.push(path.resolve(file))
|
|
29
|
-
})
|
|
27
|
+
globSync(pattern).forEach(file => {
|
|
28
|
+
files.push(path.resolve(file))
|
|
29
|
+
})
|
|
30
30
|
|
|
31
|
-
return files
|
|
32
|
-
}
|
|
31
|
+
return files
|
|
32
|
+
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Joins a list of files to a valid glob pattern
|
|
36
36
|
*/
|
|
37
|
-
const flattenFiles =
|
|
38
|
-
const pattern = list.join(',')
|
|
39
|
-
return pattern.indexOf(',') > -1 ? `{${pattern}}` : pattern
|
|
40
|
-
}
|
|
37
|
+
const flattenFiles = list => {
|
|
38
|
+
const pattern = list.join(',')
|
|
39
|
+
return pattern.indexOf(',') > -1 ? `{${pattern}}` : pattern
|
|
40
|
+
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Greps a file by its content, checks if Scenario or Feature text'
|
|
44
44
|
* matches the grep text.
|
|
45
45
|
*/
|
|
46
46
|
const grepFile = (file, grep) => {
|
|
47
|
-
const contents = fs.readFileSync(file, 'utf8')
|
|
48
|
-
const pattern = new RegExp(`((Scenario|Feature)\(.*${grep}.*\))`, 'g')
|
|
49
|
-
return !!pattern.exec(contents)
|
|
50
|
-
}
|
|
47
|
+
const contents = fs.readFileSync(file, 'utf8')
|
|
48
|
+
const pattern = new RegExp(`((Scenario|Feature)\(.*${grep}.*\))`, 'g') // <- How future proof/solid is this?
|
|
49
|
+
return !!pattern.exec(contents)
|
|
50
|
+
}
|
|
51
51
|
|
|
52
|
-
const mapFileFormats =
|
|
52
|
+
const mapFileFormats = files => {
|
|
53
53
|
return {
|
|
54
54
|
gherkin: files.filter(file => file.match(/\.feature$/)),
|
|
55
55
|
js: files.filter(file => file.match(/\.t|js$/)),
|
|
56
|
-
}
|
|
57
|
-
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Creates a list of chunks incl. configuration by either dividing a list of scenario
|
|
@@ -62,30 +62,33 @@ const mapFileFormats = (files) => {
|
|
|
62
62
|
* the splitting.
|
|
63
63
|
*/
|
|
64
64
|
const createChunks = (config, patterns = []) => {
|
|
65
|
-
const files = patterns
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
const files = patterns
|
|
66
|
+
.filter(pattern => !!pattern)
|
|
67
|
+
.map(pattern => {
|
|
68
|
+
return findFiles(pattern).filter(file => {
|
|
69
|
+
return config.grep ? grepFile(file, config.grep) : true
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
.reduce((acc, val) => acc.concat(val), [])
|
|
70
73
|
|
|
71
|
-
let chunks = []
|
|
74
|
+
let chunks = []
|
|
72
75
|
if (typeof config.chunks === 'function') {
|
|
73
|
-
chunks = config.chunks.call(this, files)
|
|
76
|
+
chunks = config.chunks.call(this, files)
|
|
74
77
|
} else if (typeof config.chunks === 'number' || typeof config.chunks === 'string') {
|
|
75
|
-
chunks = splitFiles(files, Math.ceil(files.length / config.chunks))
|
|
78
|
+
chunks = splitFiles(files, Math.ceil(files.length / config.chunks))
|
|
76
79
|
} else {
|
|
77
|
-
throw new Error('chunks is neither a finite number or a valid function')
|
|
80
|
+
throw new Error('chunks is neither a finite number or a valid function')
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
const chunkConfig = { ...config }
|
|
81
|
-
delete chunkConfig.chunks
|
|
83
|
+
const chunkConfig = { ...config }
|
|
84
|
+
delete chunkConfig.chunks
|
|
82
85
|
|
|
83
|
-
return chunks.map(
|
|
84
|
-
const { js, gherkin } = mapFileFormats(chunkFiles)
|
|
85
|
-
return { ...chunkConfig, tests: flattenFiles(js), gherkin: { features: flattenFiles(gherkin) } }
|
|
86
|
-
})
|
|
87
|
-
}
|
|
86
|
+
return chunks.map(chunkFiles => {
|
|
87
|
+
const { js, gherkin } = mapFileFormats(chunkFiles)
|
|
88
|
+
return { ...chunkConfig, tests: flattenFiles(js), gherkin: { features: flattenFiles(gherkin) } }
|
|
89
|
+
})
|
|
90
|
+
}
|
|
88
91
|
|
|
89
92
|
module.exports = {
|
|
90
93
|
createChunks,
|
|
91
|
-
}
|
|
94
|
+
}
|
package/lib/container.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { globSync } = require('glob')
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const debug = require('debug')('codeceptjs:container')
|
|
4
4
|
const { MetaStep } = require('./step')
|
|
@@ -169,18 +169,18 @@ class Container {
|
|
|
169
169
|
* @param {Object<string, *>} newSupport
|
|
170
170
|
* @param {Object<string, *>} newPlugins
|
|
171
171
|
*/
|
|
172
|
-
static clear(newHelpers, newSupport, newPlugins) {
|
|
173
|
-
container.helpers = newHelpers
|
|
172
|
+
static clear(newHelpers = {}, newSupport = {}, newPlugins = {}) {
|
|
173
|
+
container.helpers = newHelpers
|
|
174
174
|
container.translation = loadTranslation()
|
|
175
|
-
container.proxySupport = createSupportObjects(newSupport
|
|
176
|
-
container.plugins = newPlugins
|
|
175
|
+
container.proxySupport = createSupportObjects(newSupport)
|
|
176
|
+
container.plugins = newPlugins
|
|
177
177
|
asyncHelperPromise = Promise.resolve()
|
|
178
178
|
store.actor = null
|
|
179
179
|
debug('container cleared')
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
* @param {Function} fn
|
|
183
|
+
* @param {Function|null} fn
|
|
184
184
|
* @returns {Promise<void>}
|
|
185
185
|
*/
|
|
186
186
|
static async started(fn = null) {
|
|
@@ -471,7 +471,7 @@ function loadGherkinSteps(paths) {
|
|
|
471
471
|
} else {
|
|
472
472
|
const folderPath = paths.startsWith('.') ? path.join(global.codecept_dir, paths) : ''
|
|
473
473
|
if (folderPath !== '') {
|
|
474
|
-
|
|
474
|
+
globSync(folderPath).forEach(file => {
|
|
475
475
|
loadSupportObject(file, `Step Definition from ${file}`)
|
|
476
476
|
})
|
|
477
477
|
}
|
package/lib/mocha/gherkin.js
CHANGED
|
@@ -107,7 +107,7 @@ module.exports = (text, file) => {
|
|
|
107
107
|
)
|
|
108
108
|
continue
|
|
109
109
|
}
|
|
110
|
-
if (child.scenario && (currentLanguage ? child.scenario.keyword
|
|
110
|
+
if (child.scenario && (currentLanguage ? currentLanguage.contexts.ScenarioOutline.includes(child.scenario.keyword) : child.scenario.keyword === 'Scenario Outline')) {
|
|
111
111
|
for (const examples of child.scenario.examples) {
|
|
112
112
|
const fields = examples.tableHeader.cells.map(c => c.value)
|
|
113
113
|
for (const example of examples.tableBody) {
|