Skip to content

Commit cfc95c6

Browse files
author
DavertMik
committed
fixed bdd tests
1 parent 01bfdb2 commit cfc95c6

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

lib/mocha/gherkin.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const Gherkin = require('@cucumber/gherkin')
22
const Messages = require('@cucumber/messages')
3-
const { Context, Suite, Test } = require('mocha')
3+
const { Context, Suite } = require('mocha')
44
const debug = require('debug')('codeceptjs:bdd')
55

6+
const { enhanceMochaSuite } = require('./suite')
7+
const { createTest } = require('./test')
68
const { matchStep } = require('./bdd')
79
const event = require('../event')
810
const scenario = require('./scenario')
@@ -28,6 +30,7 @@ module.exports = (text, file) => {
2830
throw new Error(`No 'Features' available in Gherkin '${file}' provided!`)
2931
}
3032
const suite = new Suite(ast.feature.name, new Context())
33+
enhanceMochaSuite(suite)
3134
const tags = ast.feature.tags.map(t => t.name)
3235
suite.title = `${suite.title} ${tags.join(' ')}`.trim()
3336
suite.tags = tags || []
@@ -130,10 +133,10 @@ module.exports = (text, file) => {
130133
}
131134
}
132135

133-
const test = new Test(title, async () => runSteps(addExampleInTable(exampleSteps, current)))
136+
const test = createTest(title, async () => runSteps(addExampleInTable(exampleSteps, current)))
137+
test.addToSuite(suite)
134138
test.tags = suite.tags.concat(tags)
135139
test.file = file
136-
suite.addTest(scenario.test(test))
137140
}
138141
}
139142
continue
@@ -142,10 +145,10 @@ module.exports = (text, file) => {
142145
if (child.scenario) {
143146
const tags = child.scenario.tags.map(t => t.name)
144147
const title = `${child.scenario.name} ${tags.join(' ')}`.trim()
145-
const test = new Test(title, async () => runSteps(child.scenario.steps))
148+
const test = createTest(title, async () => runSteps(child.scenario.steps))
149+
test.addToSuite(suite)
146150
test.tags = suite.tags.concat(tags)
147151
test.file = file
148-
suite.addTest(scenario.test(test))
149152
}
150153
}
151154

lib/mocha/scenarioConfig.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { isAsyncFunction } = require('../utils')
2+
13
/** @class */
24
class ScenarioConfig {
35
constructor(test) {
@@ -71,21 +73,20 @@ class ScenarioConfig {
7173
* @param {Object<string, any>} [obj]
7274
* @returns {this}
7375
*/
74-
async config(helper, obj) {
76+
config(helper, obj) {
7577
if (!obj) {
7678
obj = helper
7779
helper = 0
7880
}
7981
if (typeof obj === 'function') {
80-
obj(this.test).then(result => {
81-
this.test.config[helper] = result
82-
})
82+
if (isAsyncFunction(obj)) {
83+
obj(this.test).then(res => (this.test.config[helper] = res))
84+
} else {
85+
obj = obj(this.test)
86+
}
8387
return this
8488
}
8589

86-
if (!this.test.config) {
87-
this.test.config = {}
88-
}
8990
this.test.config[helper] = obj
9091
return this
9192
}

test/unit/bdd_test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const Gherkin = require('@cucumber/gherkin')
22
const Messages = require('@cucumber/messages')
3-
3+
const path = require('path')
44
const chai = require('chai')
55

66
const expect = chai.expect
@@ -17,6 +17,8 @@ const container = require('../../lib/container')
1717
const actor = require('../../lib/actor')
1818
const event = require('../../lib/event')
1919

20+
global.codecept_dir = path.join(__dirname, '/..')
21+
2022
class Color {
2123
constructor(name) {
2224
this.name = name
@@ -111,7 +113,7 @@ describe('BDD', () => {
111113
expect('@super').is.equal(suite.tests[0].tags[0])
112114
})
113115

114-
it('should load step definitions', done => {
116+
it('should load and run step definitions', done => {
115117
let sum = 0
116118
Given(/I have product with (\d+) price/, param => (sum += parseInt(param, 10)))
117119
When('I go to checkout process', () => (sum += 10))

0 commit comments

Comments
 (0)