Skip to content

Commit 377bd51

Browse files
author
DavertMik
committed
Merge branch '3.x' of github.com:codeceptjs/CodeceptJS into 3.x
2 parents 202fc42 + 1a022e8 commit 377bd51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+913
-550
lines changed

.github/workflows/appium_iOS.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ env:
1414

1515
jobs:
1616
appium:
17+
if: false
1718
runs-on: ubuntu-22.04
1819

1920
strategy:

lib/codecept.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { existsSync, readFileSync } = require('fs')
2-
const glob = require('glob')
2+
const { globSync } = require('glob')
33
const fsPath = require('path')
44
const { resolve } = require('path')
55

@@ -168,15 +168,17 @@ class Codecept {
168168
}
169169

170170
for (pattern of patterns) {
171-
glob.sync(pattern, options).forEach(file => {
172-
if (file.includes('node_modules')) return
173-
if (!fsPath.isAbsolute(file)) {
174-
file = fsPath.join(global.codecept_dir, file)
175-
}
176-
if (!this.testFiles.includes(fsPath.resolve(file))) {
177-
this.testFiles.push(fsPath.resolve(file))
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+
}
180182
}
181183
}
182184

@@ -200,12 +202,12 @@ class Codecept {
200202
}
201203
const done = () => {
202204
event.emit(event.all.result, container.result())
203-
event.emit(event.all.after)
205+
event.emit(event.all.after, this)
204206
resolve()
205207
}
206208

207209
try {
208-
event.emit(event.all.before)
210+
event.emit(event.all.before, this)
209211
mocha.run(() => done())
210212
} catch (e) {
211213
output.error(e.stack)

lib/command/check.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { getConfig, getTestRoot } = require('./utils')
22
const Codecept = require('../codecept')
33
const output = require('../output')
4-
const standardActingHelpers = require('../plugin/standardActingHelpers')
54
const store = require('../store')
65
const container = require('../container')
76
const figures = require('figures')
@@ -23,6 +22,7 @@ module.exports = async function (options) {
2322
container: false,
2423
pageObjects: false,
2524
plugins: false,
25+
ai: true, // we don't need to check AI
2626
helpers: false,
2727
setup: false,
2828
tests: false,
@@ -51,6 +51,8 @@ module.exports = async function (options) {
5151
checks.container = err
5252
}
5353

54+
const standardActingHelpers = container.STANDARD_ACTING_HELPERS
55+
5456
printCheck('container', checks['container'])
5557

5658
if (codecept) {
@@ -83,6 +85,13 @@ module.exports = async function (options) {
8385
}
8486
}
8587

88+
if (config?.ai?.request) {
89+
checks.ai = true
90+
printCheck('ai', checks['ai'], 'AI configuration is enabled, request function is set')
91+
} else {
92+
printCheck('ai', checks['ai'], 'AI is disabled')
93+
}
94+
8695
printCheck('tests', checks['tests'], `Total: ${numTests} tests`)
8796

8897
store.dryRun = true
@@ -170,7 +179,7 @@ function printCheck(name, value, comment = '') {
170179
}
171180

172181
if (value instanceof Error) {
173-
comment = `${comment} ${chalk.red.italic(value.message)}`.trim()
182+
comment = `${comment} ${chalk.red(value.message)}`.trim()
174183
}
175184

176185
output.print(status, name.toUpperCase(), chalk.dim(comment))

lib/command/definitions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { getConfig, getTestRoot } = require('./utils')
55
const Codecept = require('../codecept')
66
const container = require('../container')
77
const output = require('../output')
8-
const actingHelpers = [...require('../plugin/standardActingHelpers'), 'REST']
8+
const actingHelpers = [...container.STANDARD_ACTING_HELPERS, 'REST']
99

1010
/**
1111
* Prepare data and generate content of definitions file

lib/command/gherkin/snippets.js

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -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 glob = require('glob');
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')
77

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')
1212

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
1818

1919
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
2424

25-
const codecept = new Codecept(config, {});
26-
codecept.init(testsPath);
25+
const codecept = new Codecept(config, {})
26+
codecept.init(testsPath)
2727

2828
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)
3131
}
3232
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)
3535
}
3636
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)
3939
}
4040
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)
4343
}
4444

45-
const files = [];
46-
glob.sync(options.feature || config.gherkin.features, { cwd: options.feature ? '.' : global.codecept_dir }).forEach(file => {
45+
const files = []
46+
globSync(options.feature || config.gherkin.features, { cwd: options.feature ? '.' : global.codecept_dir }).forEach(file => {
4747
if (!fsPath.isAbsolute(file)) {
48-
file = fsPath.join(global.codecept_dir, file);
48+
file = fsPath.join(global.codecept_dir, file)
4949
}
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`)
5353

54-
const newSteps = new Map();
54+
const newSteps = new Map()
5555

5656
const parseSteps = steps => {
57-
const newSteps = [];
58-
let currentKeyword = '';
57+
const newSteps = []
58+
let currentKeyword = ''
5959
for (const step of steps) {
6060
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
6363
}
64-
currentKeyword = step.keyword;
64+
currentKeyword = step.keyword
6565
try {
66-
matchStep(step.text);
66+
matchStep(step.text)
6767
} catch (err) {
68-
let stepLine;
68+
let stepLine
6969
if (/[{}()/]/.test(step.text)) {
7070
stepLine = escapeStringRegexp(step.text)
7171
.replace(/\//g, '\\/')
7272
.replace(/\"(.*?)\"/g, '"(.*?)"')
7373
.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 })
7676
} else {
7777
stepLine = step.text
7878
.replace(/\"(.*?)\"/g, '{string}')
7979
.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 })
8282
}
83-
newSteps.push(stepLine);
83+
newSteps.push(stepLine)
8484
}
8585
}
86-
return newSteps;
87-
};
86+
return newSteps
87+
}
8888

8989
const parseFile = file => {
90-
const ast = parser.parse(fs.readFileSync(file).toString());
90+
const ast = parser.parse(fs.readFileSync(file).toString())
9191
for (const child of ast.feature.children) {
92-
if (child.scenario.keyword === 'Scenario Outline') continue; // skip scenario outline
92+
if (child.scenario.keyword === 'Scenario Outline') continue // skip scenario outline
9393
parseSteps(child.scenario.steps)
9494
.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) })
9696
})
97-
.map(step => newSteps.set(`${step.type}(${step})`, step));
97+
.map(step => newSteps.set(`${step.type}(${step})`, step))
9898
}
99-
};
99+
}
100100

101-
files.forEach(file => parseFile(file));
101+
files.forEach(file => parseFile(file))
102102

103-
let stepFile = options.path || config.gherkin.steps[0];
103+
let stepFile = options.path || config.gherkin.steps[0]
104104
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)
107107
}
108108

109109
if (!fsPath.isAbsolute(stepFile)) {
110-
stepFile = fsPath.join(global.codecept_dir, stepFile);
110+
stepFile = fsPath.join(global.codecept_dir, stepFile)
111111
}
112112

113113
const snippets = [...newSteps.values()]
@@ -117,18 +117,18 @@ module.exports = function (genPath, options) {
117117
${step.type}(${step.regexp ? '/^' : "'"}${step}${step.regexp ? '$/' : "'"}, () => {
118118
// From "${step.file}" ${JSON.stringify(step.location)}
119119
throw new Error('Not implemented yet');
120-
});`;
121-
});
120+
});`
121+
})
122122

123123
if (!snippets.length) {
124-
output.print('No new snippets found');
125-
return;
124+
output.print('No new snippets found')
125+
return
126126
}
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'))
129129

130130
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')
133133
}
134-
};
134+
}

lib/command/interactive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Codecept = require('../codecept')
44
const Container = require('../container')
55
const event = require('../event')
66
const output = require('../output')
7-
const webHelpers = require('../plugin/standardActingHelpers')
7+
const webHelpers = Container.STANDARD_ACTING_HELPERS
88

99
module.exports = async function (path, options) {
1010
// Backward compatibility for --profile

0 commit comments

Comments
 (0)