Skip to content

Commit e12ae78

Browse files
Copilotkobenguyent
andcommitted
Changes before error encountered
Co-authored-by: kobenguyent <[email protected]>
1 parent 6fc1a2a commit e12ae78

File tree

18 files changed

+418
-124
lines changed

18 files changed

+418
-124
lines changed

lib/command/check.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ module.exports = async function (options) {
3131
}
3232

3333
const testRoot = getTestRoot(configFile)
34-
let config = getConfig(configFile)
34+
let config = await getConfig(configFile)
3535

3636
try {
37-
config = getConfig(configFile)
37+
config = await getConfig(configFile)
3838
checks['config'] = true
3939
} catch (err) {
4040
checks['config'] = err

lib/command/definitions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs')
22
const path = require('path')
33

4-
const { getConfig, getTestRoot } = require('./utils')
4+
const { getConfigSync, getTestRoot } = require('./utils')
55
const Codecept = require('../codecept')
66
const container = require('../container')
77
const output = require('../output')
@@ -90,7 +90,7 @@ module.exports = function (genPath, options) {
9090
const configFile = options.config || genPath
9191
/** @type {string} */
9292
const testsPath = getTestRoot(configFile)
93-
const config = getConfig(configFile)
93+
const config = getConfigSync(configFile)
9494
if (!config) return
9595

9696
/** @type {Object<string, string>} */

lib/command/dryRun.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = async function (test, options) {
1212
let codecept
1313

1414
const testRoot = getTestRoot(configFile)
15-
let config = getConfig(configFile)
15+
let config = await getConfig(configFile)
1616
if (options.override) {
1717
config = Config.append(JSON.parse(options.override))
1818
}

lib/command/generate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const path = require('path')
66
const { fileExists, ucfirst, lcfirst, beautify } = require('../utils')
77
const output = require('../output')
88
const generateDefinitions = require('./definitions')
9-
const { getConfig, getTestRoot, safeFileWrite, readConfig } = require('./utils')
9+
const { getConfigSync, getTestRoot, safeFileWrite, readConfig } = require('./utils')
1010

1111
let extension = 'js'
1212

@@ -21,7 +21,7 @@ Scenario('test something', async ({ {{actor}} }) => {
2121
module.exports.test = function (genPath) {
2222
const testsPath = getTestRoot(genPath)
2323
global.codecept_dir = testsPath
24-
const config = getConfig(testsPath)
24+
const config = getConfigSync(testsPath)
2525
if (!config) return
2626

2727
output.print('Creating a new test...')
@@ -107,7 +107,7 @@ export = {{name}};
107107

108108
module.exports.pageObject = function (genPath, opts) {
109109
const testsPath = getTestRoot(genPath)
110-
const config = getConfig(testsPath)
110+
const config = getConfigSync(testsPath)
111111
const kind = opts.T || 'page'
112112
if (!config) return
113113

lib/command/gherkin/init.js

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
const path = require('path');
2-
const mkdirp = require('mkdirp');
1+
const path = require('path')
2+
const mkdirp = require('mkdirp')
33

4-
const output = require('../../output');
5-
const { fileExists } = require('../../utils');
6-
const {
7-
getConfig, getTestRoot, updateConfig, safeFileWrite, findConfigFile,
8-
} = require('../utils');
4+
const output = require('../../output')
5+
const { fileExists } = require('../../utils')
6+
const { getConfigSync, getTestRoot, updateConfig, safeFileWrite, findConfigFile } = require('../utils')
97

108
const featureFile = `Feature: Business rules
119
In order to achieve my goals
@@ -14,68 +12,64 @@ const featureFile = `Feature: Business rules
1412
1513
Scenario: do something
1614
Given I have a defined step
17-
`;
15+
`
1816

1917
const stepsFile = `const { I } = inject();
2018
// Add in your custom step files
2119
2220
Given('I have a defined step', () => {
2321
// TODO: replace with your own step
2422
});
25-
`;
23+
`
2624

2725
module.exports = function (genPath) {
28-
const testsPath = getTestRoot(genPath);
29-
const configFile = findConfigFile(testsPath);
26+
const testsPath = getTestRoot(genPath)
27+
const configFile = findConfigFile(testsPath)
3028

3129
if (!configFile) {
32-
output.error(
33-
"Can't initialize Gherkin. This command must be run in an already initialized project.",
34-
);
35-
process.exit(1);
30+
output.error("Can't initialize Gherkin. This command must be run in an already initialized project.")
31+
process.exit(1)
3632
}
3733

38-
const config = getConfig(testsPath);
39-
const extension = path.extname(configFile).substring(1);
34+
const config = getConfigSync(testsPath)
35+
const extension = path.extname(configFile).substring(1)
4036

41-
output.print('Initializing Gherkin (Cucumber BDD) for CodeceptJS');
42-
output.print('--------------------------');
37+
output.print('Initializing Gherkin (Cucumber BDD) for CodeceptJS')
38+
output.print('--------------------------')
4339

4440
if (config.gherkin && config.gherkin.steps) {
45-
output.error('Gherkin is already initialized in this project. See `gherkin` section in the config');
46-
process.exit(1);
41+
output.error('Gherkin is already initialized in this project. See `gherkin` section in the config')
42+
process.exit(1)
4743
}
4844

49-
let dir;
50-
dir = path.join(testsPath, 'features');
45+
let dir
46+
dir = path.join(testsPath, 'features')
5147
if (!fileExists(dir)) {
52-
mkdirp.sync(dir);
53-
output.success(`Created ${dir}, place your *.feature files in it`);
48+
mkdirp.sync(dir)
49+
output.success(`Created ${dir}, place your *.feature files in it`)
5450
}
5551

5652
if (safeFileWrite(path.join(dir, 'basic.feature'), featureFile)) {
57-
output.success('Created sample feature file: features/basic.feature');
53+
output.success('Created sample feature file: features/basic.feature')
5854
}
5955

60-
dir = path.join(testsPath, 'step_definitions');
56+
dir = path.join(testsPath, 'step_definitions')
6157
if (!fileExists(dir)) {
62-
mkdirp.sync(dir);
63-
output.success(`Created ${dir}, place step definitions into it`);
58+
mkdirp.sync(dir)
59+
output.success(`Created ${dir}, place step definitions into it`)
6460
}
6561

6662
if (safeFileWrite(path.join(dir, `steps.${extension}`), stepsFile)) {
67-
output.success(
68-
`Created sample steps file: step_definitions/steps.${extension}`,
69-
);
63+
output.success(`Created sample steps file: step_definitions/steps.${extension}`)
7064
}
7165

7266
config.gherkin = {
7367
features: './features/*.feature',
7468
steps: [`./step_definitions/steps.${extension}`],
75-
};
69+
}
7670

77-
updateConfig(testsPath, config, extension);
71+
updateConfig(testsPath, config, extension)
7872

79-
output.success('Gherkin setup is done.');
80-
output.success('Start writing feature files and implement corresponding steps.');
81-
};
73+
output.success('Gherkin setup is done.')
74+
output.success('Start writing feature files and implement corresponding steps.')
75+
}

lib/command/gherkin/snippets.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Messages = require('@cucumber/messages')
55
const { globSync } = require('glob')
66
const fsPath = require('path')
77

8-
const { getConfig, getTestRoot } = require('../utils')
8+
const { getConfigSync, getTestRoot } = require('../utils')
99
const Codecept = require('../../codecept')
1010
const output = require('../../output')
1111
const { matchStep } = require('../../mocha/bdd')
@@ -19,7 +19,7 @@ parser.stopAtFirstError = false
1919
module.exports = function (genPath, options) {
2020
const configFile = options.config || genPath
2121
const testsPath = getTestRoot(configFile)
22-
const config = getConfig(configFile)
22+
const config = getConfigSync(configFile)
2323
if (!config) return
2424

2525
const codecept = new Codecept(config, {})

lib/command/gherkin/steps.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
const { getConfig, getTestRoot } = require('../utils');
2-
const Codecept = require('../../codecept');
3-
const output = require('../../output');
4-
const { getSteps } = require('../../mocha/bdd');
1+
const { getConfigSync, getTestRoot } = require('../utils')
2+
const Codecept = require('../../codecept')
3+
const output = require('../../output')
4+
const { getSteps } = require('../../mocha/bdd')
55

66
module.exports = function (genPath, options) {
7-
const configFile = options.config || genPath;
8-
const testsPath = getTestRoot(configFile);
9-
const config = getConfig(configFile);
10-
if (!config) return;
7+
const configFile = options.config || genPath
8+
const testsPath = getTestRoot(configFile)
9+
const config = getConfigSync(configFile)
10+
if (!config) return
1111

12-
const codecept = new Codecept(config, {});
13-
codecept.init(testsPath);
12+
const codecept = new Codecept(config, {})
13+
codecept.init(testsPath)
1414

15-
output.print('Gherkin Step Definitions:');
16-
output.print();
17-
const steps = getSteps();
15+
output.print('Gherkin Step Definitions:')
16+
output.print()
17+
const steps = getSteps()
1818
for (const step of Object.keys(steps)) {
19-
output.print(` ${output.colors.bold(step)} ${output.colors.green(steps[step].line || '')}`);
19+
output.print(` ${output.colors.bold(step)} ${output.colors.green(steps[step].line || '')}`)
2020
}
21-
output.print();
21+
output.print()
2222
if (!Object.keys(steps).length) {
23-
output.error('No Gherkin steps defined');
23+
output.error('No Gherkin steps defined')
2424
}
25-
};
25+
}

lib/command/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async function getOsBrowsers() {
4242

4343
module.exports = async function (path) {
4444
const testsPath = getTestRoot(path)
45-
const config = getConfig(testsPath)
45+
const config = await getConfig(testsPath)
4646
const codecept = new Codecept(config, {})
4747
codecept.init(testsPath)
4848

lib/command/interactive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = async function (path, options) {
1212
process.env.profile = options.profile
1313
const configFile = options.config
1414

15-
const config = getConfig(configFile)
15+
const config = await getConfig(configFile)
1616
const testsPath = getTestRoot(configFile)
1717

1818
const codecept = new Codecept(config, options)

lib/command/list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { getConfig, getTestRoot } = require('./utils')
1+
const { getConfigSync, getTestRoot } = require('./utils')
22
const Codecept = require('../codecept')
33
const container = require('../container')
44
const { getParamsToString } = require('../parser')
@@ -7,7 +7,7 @@ const output = require('../output')
77

88
module.exports = function (path) {
99
const testsPath = getTestRoot(path)
10-
const config = getConfig(testsPath)
10+
const config = getConfigSync(testsPath)
1111
const codecept = new Codecept(config, {})
1212
codecept.init(testsPath)
1313

0 commit comments

Comments
 (0)