Skip to content

Commit 38166cc

Browse files
author
DavertMik
committed
Merge branch '3.x' into feat/analyze-result
2 parents a0ae921 + f27e662 commit 38166cc

File tree

11 files changed

+216
-4
lines changed

11 files changed

+216
-4
lines changed

lib/plugin/commentStep.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ let currentCommentStep
77
const defaultGlobalName = '__'
88

99
/**
10+
* @deprecated
11+
*
1012
* Add descriptive nested steps for your tests:
1113
*
1214
* ```js
@@ -100,6 +102,9 @@ const defaultGlobalName = '__'
100102
* ```
101103
*/
102104
module.exports = function (config) {
105+
console.log('commentStep is deprecated, disable it and use Section instead')
106+
console.log('const { Section: __ } = require("codeceptjs/steps")')
107+
103108
event.dispatcher.on(event.test.started, () => {
104109
currentCommentStep = null
105110
})

lib/step/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class Step {
214214
processingStep = this
215215

216216
while (processingStep.metaStep) {
217-
if (processingStep.metaStep.actor.match(/^(Given|When|Then|And)/)) {
217+
if (processingStep.metaStep.actor?.match(/^(Given|When|Then|And)/)) {
218218
hasBDD = true
219219
break
220220
} else {

lib/step/meta.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ class MetaStep extends Step {
66
constructor(actor, method) {
77
if (!method) method = ''
88
super(method)
9+
10+
/** @member {boolean} collsapsed hide children steps from output */
11+
this.collapsed = false
12+
913
this.actor = actor
1014
}
1115

@@ -32,7 +36,11 @@ class MetaStep extends Step {
3236
return `${this.prefix}${actorText} ${this.humanize()} ${this.humanizeArgs()}${this.suffix}`
3337
}
3438

35-
return `On ${this.prefix}${actorText}: ${this.humanize()} ${this.humanizeArgs()}${this.suffix}`
39+
if (!this.actor) {
40+
return `${this.name} ${this.humanizeArgs()}${this.suffix}`.trim()
41+
}
42+
43+
return `On ${this.prefix}${actorText}: ${this.humanize()} ${this.humanizeArgs()}${this.suffix}`.trim()
3644
}
3745

3846
humanize() {

lib/step/section.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const MetaStep = require('./meta')
2+
const event = require('../event')
3+
4+
let currentSection
5+
6+
class Section {
7+
constructor(name = '') {
8+
this.name = name
9+
10+
this.metaStep = new MetaStep(null, name)
11+
12+
this.attachMetaStep = step => {
13+
if (currentSection !== this) return
14+
if (!step) return
15+
const metaStep = getRootMetaStep(step)
16+
17+
if (metaStep !== this.metaStep) {
18+
metaStep.metaStep = this.metaStep
19+
}
20+
}
21+
}
22+
23+
hidden() {
24+
this.metaStep.collapsed = true
25+
return this
26+
}
27+
28+
start() {
29+
if (currentSection) currentSection.end()
30+
currentSection = this
31+
event.dispatcher.prependListener(event.step.before, this.attachMetaStep)
32+
event.dispatcher.once(event.test.finished, () => this.end())
33+
return this
34+
}
35+
36+
end() {
37+
currentSection = null
38+
event.dispatcher.off(event.step.started, this.attachMetaStep)
39+
return this
40+
}
41+
42+
/**
43+
* @returns {Section}
44+
*/
45+
static current() {
46+
return currentSection
47+
}
48+
}
49+
50+
function getRootMetaStep(step) {
51+
if (step.metaStep) return getRootMetaStep(step.metaStep)
52+
return step
53+
}
54+
55+
module.exports = Section

lib/steps.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const StepConfig = require('./step/config')
2-
2+
const Section = require('./step/section')
33
function stepOpts(opts = {}) {
44
return new StepConfig(opts)
55
}
@@ -12,12 +12,39 @@ function stepRetry(retry) {
1212
return new StepConfig().retry(retry)
1313
}
1414

15+
function section(name) {
16+
if (!name) return endSection()
17+
return new Section(name).start()
18+
}
19+
20+
function endSection() {
21+
return Section.current().end()
22+
}
23+
1524
// Section function to be added here
1625

1726
const step = {
27+
// steps.opts syntax
1828
opts: stepOpts,
1929
timeout: stepTimeout,
2030
retry: stepRetry,
31+
32+
// one-function syntax
33+
stepTimeout,
34+
stepRetry,
35+
stepOpts,
36+
37+
// sections
38+
section,
39+
endSection,
40+
41+
Section: section,
42+
EndSection: endSection,
43+
44+
// shortcuts
45+
Given: () => section('Given'),
46+
When: () => section('When'),
47+
Then: () => section('Then'),
2148
}
2249

2350
module.exports = step

runok.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ describe('CodeceptJS ${featureName}', function () {
607607
console.log(`Created test files for feature: ${featureName}`)
608608

609609
console.log('Run codecept tests with:')
610-
console.log(`./bin/codecept.js run --config ${configDir}/codecept.${featureName}.conf.js`)
610+
console.log(`./bin/codecept.js run --config ${configDir}/codecept.conf.js`)
611611

612612
console.log('')
613613
console.log('Run tests with:')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
exports.config = {
2+
tests: './*_test.js',
3+
output: './output',
4+
helpers: {
5+
FileSystem: {},
6+
CustomHelper: {
7+
require: './customHelper.js',
8+
},
9+
},
10+
include: {
11+
userPage: './userPage.js',
12+
},
13+
bootstrap: false,
14+
mocha: {},
15+
name: 'step-sections tests',
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class CustomHelper extends Helper {
2+
act() {
3+
this.debug(JSON.stringify(arguments))
4+
}
5+
}
6+
7+
module.exports = CustomHelper
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { Section, EndSection } = require('codeceptjs/steps')
2+
3+
Feature('step-sections')
4+
5+
Scenario('test using of basic step-sections', ({ I }) => {
6+
I.amInPath('.')
7+
8+
Section('User Journey')
9+
I.act('Hello, World!')
10+
11+
Section()
12+
I.act('Nothing to say')
13+
})
14+
15+
Scenario('test using of step-sections and page objects', ({ I, userPage }) => {
16+
Section('User Journey')
17+
userPage.actOnPage()
18+
19+
I.act('One more step')
20+
21+
Section()
22+
23+
I.act('Nothing to say')
24+
})
25+
26+
Scenario('test using of hidden step-sections', ({ I, userPage }) => {
27+
Section('User Journey').hidden()
28+
userPage.actOnPage()
29+
I.act('One more step')
30+
31+
EndSection()
32+
33+
I.act('Nothing to say')
34+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { I } = inject()
2+
3+
module.exports = {
4+
actOnPage: () => {
5+
I.act('actOnPage')
6+
I.act('see on this page')
7+
},
8+
}

0 commit comments

Comments
 (0)