-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
const DefaultConfig = require('../DefaultConfig'); | ||
const {Background} = require('gherkin-assembler').AST; | ||
|
||
/** | ||
* @typedef {Object} ScenarioNumberConfiguration | ||
* @property {string} format | ||
*/ | ||
const DEFAULT_CONFIG = { | ||
format: '${i}. ${name}' | ||
}; | ||
|
||
/** | ||
* The ScenarioNumbering precompiler is responsible | ||
* to add an index to all scenario and scenario outlines | ||
* name. | ||
* @class | ||
* @extends DefaultConfig | ||
*/ | ||
class ScenarioNumbering extends DefaultConfig { | ||
/** | ||
* @constructor | ||
* @param {ScenarioNumberingConfig|Object} config | ||
*/ | ||
constructor(config) { | ||
super(); | ||
this.config = Object.assign({}, DEFAULT_CONFIG, config || {}); | ||
} | ||
|
||
onFeature(feature) { | ||
let i = 0; | ||
feature.elements.forEach(element => { | ||
if (!(element instanceof Background)) { | ||
element.name = this.config.format | ||
.replace(/\$\{i\}/g, ++i) | ||
.replace(/\$\{name\}/g, element.name); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = ScenarioNumbering; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ScenarioNumbering for Gherkin precompiler | ||
|
||
The ScenarioNumbering precompiler is responsible to add an index to all scenario and scenario outlines. | ||
|
||
## Configuration | ||
|
||
ScenariNumbering accepts the following configuration: | ||
|
||
| Option | Type | Description | Default | | ||
|:------:|:----:|:------------|:--------| | ||
| `format` | `String` | The format, how index should be added to the name of the scenario/scenairo outline. Possible tokens: <ul><li>`${name}` the original name</li><li>`${i}` the index</li></ul> | `${i}. ${name}` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const ScenarioNumbering = require(path.resolve('lib/builtIn/ScenarioNumbering.js')); | ||
const expect = require('chai').expect; | ||
const API = require(path.resolve('lib')); | ||
|
||
describe('builtIn.ScenarioNumbering', () => { | ||
it('should be available through API', () => { | ||
expect(API.builtIn.ScenarioNumbering).to.equal(ScenarioNumbering); | ||
}); | ||
|
||
it('should process feature files with default config', () => { | ||
const baseAst = API.load('test/data/input/scenarioNumbering.feature'); | ||
const expectedAst = API.load('test/data/output/scenarioNumbering.1.feature'); | ||
const resultAst = API.process(baseAst, new ScenarioNumbering()); | ||
|
||
expect(resultAst).to.eql(expectedAst); | ||
}); | ||
|
||
it('should process feature files with custom config', () => { | ||
const baseAst = API.load('test/data/input/scenarioNumbering.feature'); | ||
const expectedAst = API.load('test/data/output/scenarioNumbering.2.feature'); | ||
const resultAst = API.process(baseAst, new ScenarioNumbering({ | ||
format: '${i} - ${name}' | ||
})); | ||
|
||
expect(resultAst).to.eql(expectedAst); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Feature: ScenarioNumbering | ||
|
||
Background: | ||
Given step | ||
When step | ||
Then step | ||
|
||
Scenario: First Scenario | ||
Given step | ||
When step | ||
Then step | ||
|
||
Scenario Outline: Second Scenario | ||
Given step | ||
When step | ||
Then step | ||
|
||
Scenario: Third Scenario | ||
Given step | ||
When step | ||
Then step |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Feature: ScenarioNumbering | ||
|
||
Background: | ||
Given step | ||
When step | ||
Then step | ||
|
||
Scenario: 1. First Scenario | ||
Given step | ||
When step | ||
Then step | ||
|
||
Scenario Outline: 2. Second Scenario | ||
Given step | ||
When step | ||
Then step | ||
|
||
Scenario: 3. Third Scenario | ||
Given step | ||
When step | ||
Then step |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Feature: ScenarioNumbering | ||
|
||
Background: | ||
Given step | ||
When step | ||
Then step | ||
|
||
Scenario: 1 - First Scenario | ||
Given step | ||
When step | ||
Then step | ||
|
||
Scenario Outline: 2 - Second Scenario | ||
Given step | ||
When step | ||
Then step | ||
|
||
Scenario: 3 - Third Scenario | ||
Given step | ||
When step | ||
Then step |