Skip to content

Commit

Permalink
fix: examples in test title
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Nov 25, 2023
1 parent 1e5dd80 commit d4330f0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
9 changes: 8 additions & 1 deletion lib/interfaces/gherkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ module.exports = (text, file) => {
});
}
const tags = child.scenario.tags.map(t => t.name).concat(examples.tags.map(t => t.name));
const title = `${child.scenario.name} ${JSON.stringify(current)} ${tags.join(' ')}`.trim();
let title = `${child.scenario.name} ${JSON.stringify(current)} ${tags.join(' ')}`.trim();

for (const [key, value] of Object.entries(current)) {
if (title.includes(`<${key}>`)) {
title = title.replace(JSON.stringify(current), '').replace(`<${key}>`, value);
}
}

const test = new Test(title, async () => runSteps(addExampleInTable(exampleSteps, current)));
test.tags = suite.tags.concat(tags);
test.file = file;
Expand Down
2 changes: 1 addition & 1 deletion test/bdd/features/faker.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@bdd
Feature: Faker examples

Scenario Outline: faker data genetation
Scenario Outline: faker data generation
Given I sold the "<product>" car to "<customer>" for "<price>"
When customer "<customer>" paid "<price>" for car "<product>" in "<cashier>"
Then "<cashier>" returned "<change>" in change to "<customer>"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Include Examples in dataTtable placeholder

@IncludeExamplesIndataTtable
Scenario Outline: order a product with discount
Scenario Outline: order a product with discount - <name> - <price>
Given I have this product in my cart
| data | value |
| name | <name> |
Expand Down
2 changes: 1 addition & 1 deletion test/data/sandbox/features/examples.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Feature: Checkout examples process
| 20 | 20.0 |
| 21 | 18.9 |
| 30 | 27.0 |
| 50 | 45.0 |
| 50 | 45.0 |
12 changes: 12 additions & 0 deletions test/runner/bdd_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ describe('BDD Gherkin', () => {
});
});

it('should show data from examples in test title', (done) => {
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Include Examples in dataTtable placeholder"', (err, stdout, stderr) => { //eslint-disable-line
stdout.should.include('order a product with discount - iPhone 5 - 10 @IncludeExamplesIndataTtable');
stdout.should.include('name | Nuclear Bomb ');
stdout.should.include('price | 20 ');
stdout.should.include('name | iPhone 5 ');
stdout.should.include('price | 10 ');
assert(!err);
done();
});
});

it('should run feature with tables', (done) => {
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Checkout products"', (err, stdout, stderr) => { //eslint-disable-line
stdout.should.include('Given I have products in my cart');
Expand Down

0 comments on commit d4330f0

Please sign in to comment.