Skip to content

Commit 159350b

Browse files
authored
fix: examples in test title (#4030)
1 parent 1936b0b commit 159350b

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

lib/interfaces/gherkin.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ module.exports = (text, file) => {
119119
});
120120
}
121121
const tags = child.scenario.tags.map(t => t.name).concat(examples.tags.map(t => t.name));
122-
const title = `${child.scenario.name} ${JSON.stringify(current)} ${tags.join(' ')}`.trim();
122+
let title = `${child.scenario.name} ${JSON.stringify(current)} ${tags.join(' ')}`.trim();
123+
124+
for (const [key, value] of Object.entries(current)) {
125+
if (title.includes(`<${key}>`)) {
126+
title = title.replace(JSON.stringify(current), '').replace(`<${key}>`, value);
127+
}
128+
}
129+
123130
const test = new Test(title, async () => runSteps(addExampleInTable(exampleSteps, current)));
124131
test.tags = suite.tags.concat(tags);
125132
test.file = file;

test/bdd/features/faker.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@bdd
22
Feature: Faker examples
33

4-
Scenario Outline: faker data genetation
4+
Scenario Outline: faker data generation
55
Given I sold the "<product>" car to "<customer>" for "<price>"
66
When customer "<customer>" paid "<price>" for car "<product>" in "<cashier>"
77
Then "<cashier>" returned "<change>" in change to "<customer>"

test/data/sandbox/features/IncludeExamplesInDataTable.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: Include Examples in dataTtable placeholder
22

33
@IncludeExamplesIndataTtable
4-
Scenario Outline: order a product with discount
4+
Scenario Outline: order a product with discount - <name> - <price>
55
Given I have this product in my cart
66
| data | value |
77
| name | <name> |

test/data/sandbox/features/examples.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ Feature: Checkout examples process
1616
| 20 | 20.0 |
1717
| 21 | 18.9 |
1818
| 30 | 27.0 |
19-
| 50 | 45.0 |
19+
| 50 | 45.0 |

test/runner/bdd_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ describe('BDD Gherkin', () => {
9999
});
100100
});
101101

102+
it('should show data from examples in test title', (done) => {
103+
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Include Examples in dataTtable placeholder"', (err, stdout, stderr) => { //eslint-disable-line
104+
stdout.should.include('order a product with discount - iPhone 5 - 10 @IncludeExamplesIndataTtable');
105+
stdout.should.include('name | Nuclear Bomb ');
106+
stdout.should.include('price | 20 ');
107+
stdout.should.include('name | iPhone 5 ');
108+
stdout.should.include('price | 10 ');
109+
assert(!err);
110+
done();
111+
});
112+
});
113+
102114
it('should run feature with tables', (done) => {
103115
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Checkout products"', (err, stdout, stderr) => { //eslint-disable-line
104116
stdout.should.include('Given I have products in my cart');

0 commit comments

Comments
 (0)