Skip to content

Commit 02012d6

Browse files
committed
fix: allow gherkin keywords as supported by cucumber
1 parent ba64d2c commit 02012d6

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

lib/mocha/gherkin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module.exports = (text, file) => {
107107
)
108108
continue
109109
}
110-
if (child.scenario && (currentLanguage ? child.scenario.keyword === currentLanguage.contexts.ScenarioOutline : child.scenario.keyword === 'Scenario Outline')) {
110+
if (child.scenario && (currentLanguage ? currentLanguage.scenarioOutline.includes(child.scenario.keyword) : child.scenario.keyword === 'Scenario Outline')) {
111111
for (const examples of child.scenario.examples) {
112112
const fields = examples.tableHeader.cells.map(c => c.value)
113113
for (const example of examples.tableBody) {
@@ -185,15 +185,15 @@ function addExampleInTable(exampleSteps, placeholders) {
185185
}
186186

187187
function getTranslation(language) {
188-
const translations = Object.keys(require('../../translations'))
188+
const translations = Object.keys(require('@cucumber/gherkin/src/gherkin-languages.json'))
189189

190190
for (const availableTranslation of translations) {
191191
if (!language) {
192192
break
193193
}
194194

195195
if (availableTranslation.includes(language)) {
196-
return require('../../translations')[availableTranslation]
196+
return require('@cucumber/gherkin/src/gherkin-languages.json')[availableTranslation]
197197
}
198198
}
199199
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
exports.config = {
2+
tests: './*_no_test.js',
3+
timeout: 10000,
4+
output: '../output',
5+
helpers: {
6+
BDD: {
7+
require: '../support/bdd_helper.js',
8+
},
9+
},
10+
gherkin: {
11+
features: './features/examples.nl.feature',
12+
steps: ['./features/step_definitions/my_steps.nl.js'],
13+
},
14+
include: {},
15+
bootstrap: false,
16+
mocha: {},
17+
name: 'sandbox',
18+
translation: 'nl-NL',
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#language: nl
2+
Functionaliteit: Checkout proces
3+
Om producten te kopen
4+
Als klant
5+
Moet ik in staat zijn om meerdere producten te kopen
6+
7+
@i18n
8+
Abstract Scenario: korting bestellen
9+
Gegeven ik heb een product met een prijs van <price>$ in mijn winkelwagen
10+
En de korting voor bestellingen van meer dan $20 is 10 %
11+
Wanneer ik naar de kassa ga
12+
Dan zou ik de totaalprijs van "<total>" $ moeten zien
13+
14+
Voorbeelden:
15+
| price | total |
16+
| 10 | 10.0 |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const I = actor()
2+
3+
Given('ik heb een product met een prijs van {int}$ in mijn winkelwagen', price => {
4+
I.addItem(parseInt(price, 10))
5+
})
6+
7+
Given('de korting voor bestellingen van meer dan ${int} is {int} %', (maxPrice, discount) => {
8+
I.haveDiscountForPrice(maxPrice, discount)
9+
})
10+
11+
When('ik naar de kassa ga', () => {
12+
I.checkout()
13+
})
14+
15+
Then('zou ik de totaalprijs van "{float}" $ moeten zien', price => {
16+
I.seeSum(price)
17+
})

test/runner/bdd_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,5 +353,25 @@ When(/^I define a step with a \\( paren and a "(.*?)" string$/, () => {
353353
done()
354354
})
355355
})
356+
357+
it('should run feature files in NL', done => {
358+
exec(config_run_config('codecept.bdd.nl.js') + ' --steps --grep "@i18n"', (err, stdout, stderr) => {
359+
console.log(stdout)
360+
stdout.should.include('On Gegeven: ik heb een product met een prijs van 10$ in mijn winkelwagen')
361+
stdout.should.include('On En: de korting voor bestellingen van meer dan $20 is 10 %')
362+
stdout.should.include('On Wanneer: ik naar de kassa ga')
363+
stdout.should.include('On Dan: zou ik de totaalprijs van "10.0" $ moeten zien')
364+
stdout.should.include('On Gegeven: ik heb een product met een prijs van 10$ in mijn winkelwagen')
365+
stdout.should.include('I add item 10')
366+
stdout.should.include('On En: de korting voor bestellingen van meer dan $20 is 10 %')
367+
stdout.should.include('I have discount for price 20, 10')
368+
stdout.should.include('On Wanneer: ik naar de kassa ga')
369+
stdout.should.include('I checkout')
370+
stdout.should.include('On Dan: zou ik de totaalprijs van "10.0" $ moeten zien')
371+
stdout.should.include('I see sum 10')
372+
assert(!err)
373+
done()
374+
})
375+
})
356376
})
357377
})

0 commit comments

Comments
 (0)