-
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
23 changed files
with
360 additions
and
98 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
Empty file.
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 |
---|---|---|
@@ -1,25 +1,42 @@ | ||
'use strict'; | ||
|
||
const Feature = require('./Feature'); | ||
const Comment = require('./Comment'); | ||
|
||
/** | ||
* Model of a complete Gherkin Document | ||
* @class | ||
*/ | ||
class GherkinDocument { | ||
constructor(feature) { | ||
/** | ||
* @constructor | ||
*/ | ||
constructor() { | ||
this.feature = null; | ||
this.comments = []; | ||
} | ||
|
||
/** | ||
* Parses a GherkinDocument object, based on the passed AST object. | ||
* @param {Object} obj | ||
* @returns {GherkinDocument} | ||
* @throws {TypeError} If the passed object is not a GherkinDocument. | ||
*/ | ||
static parse(obj) { | ||
if (!obj || obj.type !== 'GherkinDocument') { | ||
throw new TypeError('The given object is not a GherkinDocument!'); | ||
} | ||
const document = new GherkinDocument(); | ||
document.feature = Feature.parse(obj.feature); | ||
if (Array.isArray(obj.comments)) { | ||
document.comments = obj.comments.map(comment => Comment.parse(comment)); | ||
} | ||
return document; | ||
} | ||
|
||
/** | ||
* Returns the Cucumber feature file | ||
* representative text of the Document. | ||
* @returns {string} | ||
*/ | ||
toString() { | ||
return this.feature.toString(); | ||
} | ||
} | ||
|
||
module.exports = GherkinDocument; |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,64 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const Feature = require(path.resolve('lib/ast/Feature.js')); | ||
const Scenario = require(path.resolve('lib/ast/Scenario.js')); | ||
const ScenarioOutline = require(path.resolve('lib/ast/ScenarioOutline.js')); | ||
const Background = require(path.resolve('lib/ast/Background.js')); | ||
const Step = require(path.resolve('lib/ast/Step.js')); | ||
const Tag = require(path.resolve('lib/ast/Tag.js')); | ||
|
||
const featureAst = require('../data/base.ast.json').feature; | ||
const featureFile = fs.readFileSync(path.resolve('test/data/base.feature'), 'utf8'); | ||
|
||
const expect = require('chai').expect; | ||
const dc = require('deep-copy'); | ||
|
||
describe('Ast.Feature', () => { | ||
it('should represent an Ast Feature instance', () => { | ||
const feature = new Feature('Feature', 'this is a feature', 'this is a good feature\n a'); | ||
expect(feature).to.be.instanceOf(Feature); | ||
expect(feature.keyword).to.equal('Feature'); | ||
expect(feature.name).to.equal('this is a feature'); | ||
expect(feature.description).to.equal('this is a good feature\na'); | ||
expect(feature.tags).to.eql([]); | ||
expect(feature.scenarios).to.eql([]); | ||
}); | ||
|
||
it('should not parse regular objects', () => { | ||
expect(() => Feature.parse()).to.throw(TypeError); | ||
expect(() => Feature.parse({type: 'Type'})).to.throw(TypeError); | ||
}); | ||
|
||
it('should parse Gherkin Ast Feature type to Feature', () => { | ||
const feature = Feature.parse(featureAst); | ||
expect(feature).to.be.instanceOf(Feature); | ||
expect(feature.keyword).to.equal(featureAst.keyword); | ||
expect(feature.name).to.equal(featureAst.name); | ||
expect(feature.tags).to.have.lengthOf(featureAst.tags.length); | ||
feature.tags.forEach((tag, i) => { | ||
expect(tag).to.be.instanceOf(Tag); | ||
expect(tag.name).to.equal(featureAst.tags[i].name); | ||
}); | ||
expect(feature.scenarios).to.have.lengthOf(featureAst.children.length); | ||
feature.scenarios.forEach((scenario, i) => { | ||
expect(scenario.constructor.name).to.equal(featureAst.children[i].type); | ||
expect(scenario.name).to.equal(featureAst.children[i].name); | ||
}); | ||
}); | ||
|
||
it('should not parse Gherkin Ast Feature if it has unsupported children', () => { | ||
const wrongAst = dc(featureAst); | ||
wrongAst.children.push({ | ||
type: 'ThereIsNoTypeLikeThis' | ||
}); | ||
expect(() => Feature.parse(wrongAst)).to.throw(TypeError); | ||
}); | ||
|
||
it('should have proper string representation', () => { | ||
const feature = Feature.parse(featureAst); | ||
expect(feature.toString()).to.equal(featureFile); | ||
}); | ||
}); |
Oops, something went wrong.