-
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.
Added Step,Tag and Scenario and test for them
- Loading branch information
Showing
10 changed files
with
174 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
class Step { | ||
constructor(keyword, text) { | ||
this.keyword = keyword.trim(); | ||
this.text = text; | ||
} | ||
|
||
static parse(obj) { | ||
if (!obj || obj.type !== 'Step') { | ||
throw new TypeError('The given object is not a Step!'); | ||
} | ||
return new Step(obj.keyword, obj.text); | ||
} | ||
|
||
toString() { | ||
return `${this.keyword} ${this.text}`; | ||
} | ||
} | ||
|
||
module.exports = 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 |
---|---|---|
|
@@ -11,6 +11,10 @@ class Tag { | |
} | ||
return new Tag(obj.name); | ||
} | ||
|
||
toString() { | ||
return this.name; | ||
} | ||
} | ||
|
||
module.exports = Tag; |
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,20 @@ | ||
'use strict'; | ||
|
||
const utils = { | ||
indent(text, indentation) { | ||
indentation = indentation || ' '; | ||
return text | ||
.split('\n') | ||
.map(line => indentation + line) | ||
.join('\n'); | ||
}, | ||
|
||
normalize(text) { | ||
return text | ||
.split('\n') | ||
.map(line => line.trim().replace(/\s+/g, ' ')) | ||
.join('\n'); | ||
} | ||
}; | ||
|
||
module.exports = utils; |
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,46 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
const Scenario = require(path.resolve('lib/ast/Scenario.js')); | ||
const Step = require(path.resolve('lib/ast/Step.js')); | ||
const Tag = require(path.resolve('lib/ast/Tag.js')); | ||
|
||
const scenarioAst = require('../data/scenario.json'); | ||
const scenarioFeature = fs.readFileSync(path.resolve('test/data/scenario.txt'), 'utf8'); | ||
|
||
const expect = require('chai').expect; | ||
|
||
describe('Ast.Scenario', () => { | ||
it('should represent an Ast Scenario instance', () => { | ||
const scenario = new Scenario('Scenario', 'this is a scenario', 'this is a good scenario\n a'); | ||
expect(scenario).to.be.instanceOf(Scenario); | ||
expect(scenario.keyword).to.equal('Scenario'); | ||
expect(scenario.name).to.equal('this is a scenario'); | ||
expect(scenario.description).to.equal('this is a good scenario\na'); | ||
expect(scenario.tags).to.eql([]); | ||
expect(scenario.steps).to.eql([]); | ||
}); | ||
|
||
it('should not parse regular objects', () => { | ||
expect(() => Scenario.parse()).to.throw(TypeError); | ||
expect(() => Scenario.parse({type: 'Type'})).to.throw(TypeError); | ||
}); | ||
|
||
it('should parse Gherkin Ast Scenario type to Scenario', () => { | ||
const scenario = Scenario.parse(scenarioAst); | ||
expect(scenario).to.be.instanceOf(Scenario); | ||
expect(scenario.keyword).to.equal(scenarioAst.keyword); | ||
expect(scenario.name).to.equal(scenarioAst.name); | ||
expect(scenario.tags).to.have.lengthOf(2); | ||
scenario.tags.forEach((tag, i) => { | ||
expect(tag).to.be.instanceOf(Tag); | ||
expect(tag.name).to.equal(scenarioAst.tags[i].name); | ||
}); | ||
}); | ||
|
||
it('should have proper string representation', () => { | ||
const scenario = Scenario.parse(scenarioAst); | ||
expect(scenario.toString()).to.equal(scenarioFeature); | ||
}); | ||
}); |
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,32 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const Step = require(path.resolve('./lib/ast/Step.js')); | ||
|
||
const expect = require('chai').expect; | ||
|
||
describe('Ast.Step', () => { | ||
it('should represent an Ast Step instance', () => { | ||
const step = new Step('When ', 'this is a when step'); | ||
expect(step).to.be.instanceOf(Step); | ||
expect(step.keyword).to.equal('When'); | ||
expect(step.text).to.equal('this is a when step'); | ||
}); | ||
|
||
it('should not parse regular objects', () => { | ||
expect(() => Step.parse()).to.throw(TypeError); | ||
expect(() => Step.parse({type: 'Type'})).to.throw(TypeError); | ||
}); | ||
|
||
it('should parse Gherkin Ast Step type to Step', () => { | ||
const step = Step.parse({type: 'Step', keyword: 'When ', text: 'this is a when step'}); | ||
expect(step).to.be.instanceOf(Step); | ||
expect(step.keyword).to.equal('When'); | ||
expect(step.text).to.equal('this is a when step'); | ||
}); | ||
|
||
it('should have proper string representation', () => { | ||
const step = new Step('When ', 'this is a when step'); | ||
expect(step.toString()).to.equal('When this is a when 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
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,18 @@ | ||
{ | ||
"type": "Scenario", | ||
"keyword": "Scenario", | ||
"name": "this is a scenario", | ||
"description": "this is a good\n scenario", | ||
"tags": [ | ||
{ | ||
"type": "Tag", | ||
"name": "@tag1" | ||
}, | ||
{ | ||
"type": "Tag", | ||
"name": "@tag2" | ||
} | ||
], | ||
"steps": [ | ||
] | ||
} |
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,4 @@ | ||
@tag1 @tag2 | ||
Scenario: this is a scenario | ||
this is a good | ||
scenario |