Skip to content

Commit e1305b5

Browse files
Merge branch 'codeceptjs:3.x' into patch-1
2 parents 3908267 + ca956d6 commit e1305b5

17 files changed

+171
-26
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ Thanks all to those who are and will have contributing to this awesome project!
315315
<a href="https://github.com/VikalpP"><img src="https://avatars.githubusercontent.com/u/11846339?v=4" title="VikalpP" width="80" height="80"></a>
316316
<a href="https://github.com/elaichenkov"><img src="https://avatars.githubusercontent.com/u/29764053?v=4" title="elaichenkov" width="80" height="80"></a>
317317
<a href="https://github.com/BorisOsipov"><img src="https://avatars.githubusercontent.com/u/6514276?v=4" title="BorisOsipov" width="80" height="80"></a>
318-
<a href="https://github.com/hubidu"><img src="https://avatars.githubusercontent.com/u/13134082?v=4" title="hubidu" width="80" height="80"></a>
319318
<a href="https://github.com/nitschSB"><img src="https://avatars.githubusercontent.com/u/39341455?v=4" title="nitschSB" width="80" height="80"></a>
319+
<a href="https://github.com/hubidu"><img src="https://avatars.githubusercontent.com/u/13134082?v=4" title="hubidu" width="80" height="80"></a>
320320
<a href="https://github.com/jploskonka"><img src="https://avatars.githubusercontent.com/u/669483?v=4" title="jploskonka" width="80" height="80"></a>
321321
<a href="https://github.com/ngraf"><img src="https://avatars.githubusercontent.com/u/7094389?v=4" title="ngraf" width="80" height="80"></a>
322322
<a href="https://github.com/maojunxyz"><img src="https://avatars.githubusercontent.com/u/28778042?v=4" title="maojunxyz" width="80" height="80"></a>

docs/helpers/Expect.md docs/helpers/ExpectHelper.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
permalink: /helpers/Expect
2+
permalink: /helpers/ExpectHelper
33
editLink: false
44
sidebar: auto
5-
title: Expect
5+
title: ExpectHelper
66
---
77

88
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
@@ -20,7 +20,7 @@ Zero-configuration when paired with other helpers like REST, Playwright:
2020
{
2121
helpers: {
2222
Playwright: {...},
23-
Expect: {},
23+
ExpectHelper: {},
2424
}
2525
}
2626
```

lib/command/gherkin/init.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const mkdirp = require('mkdirp');
44
const output = require('../../output');
55
const { fileExists } = require('../../utils');
66
const {
7-
getConfig, getTestRoot, updateConfig, safeFileWrite,
7+
getConfig, getTestRoot, updateConfig, safeFileWrite, findConfigFile,
88
} = require('../utils');
99

1010
const featureFile = `Feature: Business rules
@@ -26,7 +26,17 @@ Given('I have a defined step', () => {
2626

2727
module.exports = function (genPath) {
2828
const testsPath = getTestRoot(genPath);
29+
const configFile = findConfigFile(testsPath);
30+
31+
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);
36+
}
37+
2938
const config = getConfig(testsPath);
39+
const extension = path.extname(configFile).substring(1);
3040

3141
output.print('Initializing Gherkin (Cucumber BDD) for CodeceptJS');
3242
output.print('--------------------------');
@@ -53,18 +63,18 @@ module.exports = function (genPath) {
5363
output.success(`Created ${dir}, place step definitions into it`);
5464
}
5565

56-
if (safeFileWrite(path.join(dir, 'steps.js'), stepsFile)) {
57-
output.success('Created sample steps file: step_definitions/steps.js');
66+
if (safeFileWrite(path.join(dir, `steps.${extension}`), stepsFile)) {
67+
output.success(
68+
`Created sample steps file: step_definitions/steps.${extension}`
69+
);
5870
}
5971

6072
config.gherkin = {
61-
features: './features/*.feature',
62-
steps: [
63-
'./step_definitions/steps.js',
64-
],
73+
features: "./features/*.feature",
74+
steps: [`./step_definitions/steps.${extension}`],
6575
};
6676

67-
updateConfig(testsPath, config);
77+
updateConfig(testsPath, config, extension);
6878

6979
output.success('Gherkin setup is done.');
7080
output.success('Start writing feature files and implement corresponding steps.');

lib/command/utils.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ function fail(msg) {
4141

4242
module.exports.fail = fail;
4343

44-
function updateConfig(testsPath, config, key, extension = 'js') {
44+
function updateConfig(testsPath, config, extension) {
4545
const configFile = path.join(testsPath, `codecept.conf.${extension}`);
4646
if (!fileExists(configFile)) {
47-
console.log();
4847
const msg = `codecept.conf.${extension} config can\'t be updated automatically`;
48+
console.log();
4949
console.log(`${output.colors.bold.red(msg)}`);
50-
console.log('Please update it manually:');
50+
console.log(`${output.colors.bold.red("Please update it manually:")}`);
5151
console.log();
52-
console.log(`${key}: ${config[key]}`);
52+
console.log(config);
5353
console.log();
5454
return;
5555
}
@@ -104,3 +104,14 @@ module.exports.createOutputDir = (config, testRoot) => {
104104
mkdirp.sync(outputDir);
105105
}
106106
};
107+
108+
module.exports.findConfigFile = (testsPath) => {
109+
const extensions = ['js', 'ts'];
110+
for (const ext of extensions) {
111+
const configFile = path.join(testsPath, `codecept.conf.${ext}`);
112+
if (fileExists(configFile)) {
113+
return configFile;
114+
}
115+
}
116+
return null;
117+
}

lib/helper/Expect.js lib/helper/ExpectHelper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import('chai').then(chai => {
2323
*{
2424
* helpers: {
2525
* Playwright: {...},
26-
* Expect: {},
26+
* ExpectHelper: {},
2727
* }
2828
*}
2929
* ```

test/acceptance/codecept.Playwright.coverage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports.config = {
2323
require: '../support/ScreenshotSessionHelper.js',
2424
outputPath: 'test/acceptance/output',
2525
},
26-
Expect: {},
26+
ExpectHelper: {},
2727
},
2828
include: {},
2929
bootstrap: false,

test/acceptance/codecept.Playwright.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports.config = {
2323
require: '../support/ScreenshotSessionHelper.js',
2424
outputPath: 'test/acceptance/output',
2525
},
26-
Expect: {},
26+
ExpectHelper: {},
2727
},
2828
include: {},
2929
bootstrap: false,

test/acceptance/codecept.Playwright.retryTo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports.config = {
2323
require: '../support/ScreenshotSessionHelper.js',
2424
outputPath: 'test/acceptance/output',
2525
},
26-
Expect: {},
26+
ExpectHelper: {},
2727
},
2828
include: {},
2929
bootstrap: false,

test/acceptance/codecept.Puppeteer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports.config = {
1919
require: '../support/ScreenshotSessionHelper.js',
2020
outputPath: './output',
2121
},
22-
Expect: {},
22+
ExpectHelper: {},
2323
},
2424
include: {},
2525
bootstrap: false,

test/acceptance/codecept.Testcafe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports.config = {
99
url: TestHelper.siteUrl(),
1010
show: true,
1111
},
12-
Expect: {},
12+
ExpectHelper: {},
1313
},
1414
include: {},
1515
bootstrap: false,

test/acceptance/codecept.WebDriver.devtools.coverage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports.config = {
2121
require: '../support/ScreenshotSessionHelper.js',
2222
outputPath: './output',
2323
},
24-
Expect: {},
24+
ExpectHelper: {},
2525
},
2626
include: {},
2727
mocha: {},

test/acceptance/codecept.WebDriver.devtools.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports.config = {
2121
require: '../support/ScreenshotSessionHelper.js',
2222
outputPath: './output',
2323
},
24-
Expect: {},
24+
ExpectHelper: {},
2525
},
2626
include: {},
2727
bootstrap: async () => new Promise(done => {

test/acceptance/codecept.WebDriver.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports.config = {
2121
require: '../support/ScreenshotSessionHelper.js',
2222
outputPath: './output',
2323
},
24-
Expect: {},
24+
ExpectHelper: {},
2525
},
2626
include: {},
2727
bootstrap: async () => new Promise(done => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** @type {CodeceptJS.MainConfig} */
2+
exports.config = {
3+
tests: "./*_test.js",
4+
output: "./output",
5+
helpers: {
6+
Playwright: {
7+
browser: "chromium",
8+
url: "http://localhost",
9+
show: true,
10+
},
11+
},
12+
include: {
13+
I: "./steps_file.js",
14+
},
15+
name: "CodeceptJS",
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const config: CodeceptJS.MainConfig = {
2+
tests: "./*_test.ts",
3+
output: "./output",
4+
helpers: {
5+
Playwright: {
6+
browser: "chromium",
7+
url: "http://localhost",
8+
show: true
9+
}
10+
},
11+
include: {
12+
I: "./steps_file"
13+
},
14+
name: "CodeceptJS"
15+
}

test/helper/Expect_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import('chai').then(chai => {
55
expect = chai.expect;
66
});
77

8-
const ExpectHelper = require('../../lib/helper/Expect');
8+
const ExpectHelper = require('../../lib/helper/ExpectHelper');
99

1010
global.codeceptjs = require('../../lib');
1111

test/runner/gherkin_test.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const assert = require("assert");
2+
const path = require("path");
3+
const fs = require("fs");
4+
const exec = require("child_process").exec;
5+
6+
const runner = path.join(__dirname, "/../../bin/codecept.js");
7+
const codecept_dir = path.join(__dirname, "/../data/sandbox/configs/gherkin/");
8+
9+
describe("gherkin bdd commands", () => {
10+
describe("bdd:init", () => {
11+
let codecept_dir_js = path.join(codecept_dir, "config_js");
12+
let codecept_dir_ts = path.join(codecept_dir, "config_ts");
13+
14+
beforeEach(() => {
15+
fs.copyFileSync(
16+
path.join(codecept_dir_js, "codecept.conf.init.js"),
17+
path.join(codecept_dir_js, "codecept.conf.js")
18+
);
19+
fs.copyFileSync(
20+
path.join(codecept_dir_ts, "codecept.conf.init.ts"),
21+
path.join(codecept_dir_ts, "codecept.conf.ts")
22+
);
23+
});
24+
25+
afterEach(() => {
26+
try {
27+
fs.rmSync(path.join(codecept_dir_js, "codecept.conf.js"));
28+
fs.rmSync(path.join(codecept_dir_js, "features"), {
29+
recursive: true,
30+
});
31+
fs.rmSync(path.join(codecept_dir_js, "step_definitions"), {
32+
recursive: true,
33+
});
34+
} catch (e) {}
35+
try {
36+
fs.rmSync(path.join(codecept_dir_ts, "codecept.conf.ts"));
37+
fs.rmSync(path.join(codecept_dir_ts, "features"), {
38+
recursive: true,
39+
});
40+
fs.rmSync(path.join(codecept_dir_ts, "step_definitions"), {
41+
recursive: true,
42+
});
43+
} catch (e) {}
44+
});
45+
46+
[
47+
{
48+
codecept_dir_test: codecept_dir_js,
49+
extension: "js",
50+
},
51+
{
52+
codecept_dir_test: codecept_dir_ts,
53+
extension: "ts",
54+
},
55+
].forEach(({ codecept_dir_test, extension }) => {
56+
it(`prepare CodeceptJS to run feature files (codecept.conf.${extension})`, (done) => {
57+
exec(`${runner} gherkin:init ${codecept_dir_test}`, (err, stdout) => {
58+
let dir = path.join(codecept_dir_test, "features");
59+
60+
stdout.should.include(
61+
"Initializing Gherkin (Cucumber BDD) for CodeceptJS"
62+
);
63+
stdout.should.include(
64+
`Created ${dir}, place your *.feature files in it`
65+
);
66+
stdout.should.include(
67+
"Created sample feature file: features/basic.feature"
68+
);
69+
70+
dir = path.join(codecept_dir_test, "step_definitions");
71+
stdout.should.include(
72+
`Created ${dir}, place step definitions into it`
73+
);
74+
stdout.should.include(
75+
`Created sample steps file: step_definitions/steps.${extension}`
76+
);
77+
assert(!err);
78+
79+
const configResult = fs
80+
.readFileSync(
81+
path.join(codecept_dir_test, `codecept.conf.${extension}`)
82+
)
83+
.toString();
84+
configResult.should.contain(`features: './features/*.feature'`);
85+
configResult.should.contain(
86+
`steps: ['./step_definitions/steps.${extension}']`
87+
);
88+
done();
89+
});
90+
});
91+
});
92+
});
93+
});

0 commit comments

Comments
 (0)