Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for feature tags #65

Merged
merged 1 commit into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/lib/feature-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export default function(cucumberOptions) {
files = _.flattenDeep(files);
return files.map((file) => {
let parsedData = parseFeature(file);
let featureTags = _.map(parsedData.tags, 'name');
didDetectErrors = parsedData.didDetectErrors ? true : didDetectErrors;
return parsedData.children
.filter((child) => {
return (child.type === 'Scenario' || child.type === 'ScenarioOutline')
&& verifyTags(child, cucumberOptions.tags);
&& verifyTags(child, featureTags, cucumberOptions.tags);
})
.map((scenario) => {
/*eslint-disable max-nested-callbacks*/
Expand Down Expand Up @@ -66,8 +67,8 @@ function parseFeature(featurePath) {
}
}

function verifyTags(scenario, tags) {
let scenarioTags = _.map(scenario.tags, 'name');
function verifyTags(scenario, featureTags, tags) {
let scenarioTags = [..._.map(scenario.tags, 'name'), ...featureTags];
var results = _.map(tags, (tag) => {
if (tag.indexOf(',') !== 0) {
var orOperatorTags = tag.split(',');
Expand Down
6 changes: 6 additions & 0 deletions test/feature-finder-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ describe('Feature Finder', function(){
return featureFinder(opts).should.eventually.deep.equal(expectedResult);
});

it('should support feature tags', function () {
var opts = options.featureTags;
var expectedResult = results.featureTags;
return featureFinder(opts).should.eventually.deep.equal(expectedResult);
});

it('should support mixed tags', function () {
var opts = options.mixedTags;
var expectedResult = results.mixedTags;
Expand Down
1 change: 1 addition & 0 deletions test/features/sample.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@FeatureTag
Feature: Sample Feature 1

Background:
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ module.exports = {
logDir: '.unit-test-tmp',
silentSummary: true
},
featureTags: {
paths: ['test/features'],
tags: ['@FeatureTag'],
requires: [],
cucumberPath: require.resolve('cucumber'),
workers: 1,
logDir: '.unit-test-tmp',
silentSummary: true
},
mixedTags: {
paths: ['test/features'],
tags: ['@Secondary', '~@Ignore'],
Expand Down
2 changes: 1 addition & 1 deletion test/pretty-parser-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const featureOutput = require('./fixtures/sample-feature-output.json').pop();
const gherkinParser = new Gherkin.Parser();
const feature = gherkinParser.parse(featureFileData).feature;
const scenario = feature.children.filter((child) => {
return (child.location.line === 7);
return (child.location.line === 8);
}).pop();

describe('Pretty parser', function() {
Expand Down
54 changes: 37 additions & 17 deletions test/results/feature-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ module.exports = {
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 7
scenarioLine: 8
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 11
scenarioLine: 12
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 14
scenarioLine: 15
},
{
featureFile: path.join('test', 'features', 'sample2.feature'),
Expand All @@ -41,12 +41,12 @@ module.exports = {
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 7
scenarioLine: 8
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 11
scenarioLine: 12
},
{
featureFile: path.join('test', 'features', 'sample2.feature'),
Expand All @@ -61,12 +61,12 @@ module.exports = {
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 7
scenarioLine: 8
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 14
scenarioLine: 15
},
{
featureFile: path.join('test', 'features', 'sample2.feature'),
Expand All @@ -91,7 +91,27 @@ module.exports = {
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 7
scenarioLine: 8
}
],
didDetectErrors: false
},
featureTags: {
scenarios: [
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 8
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 12
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 15
}
],
didDetectErrors: false
Expand All @@ -101,7 +121,7 @@ module.exports = {
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 7
scenarioLine: 8
}
],
didDetectErrors: false
Expand All @@ -111,12 +131,12 @@ module.exports = {
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 7
scenarioLine: 8
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 11
scenarioLine: 12
},
{
featureFile: path.join('test', 'features', 'sample2.feature'),
Expand All @@ -131,17 +151,17 @@ module.exports = {
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 7
scenarioLine: 8
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 11
scenarioLine: 12
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 14
scenarioLine: 15
}
],
didDetectErrors: false
Expand All @@ -151,17 +171,17 @@ module.exports = {
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 7
scenarioLine: 8
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 11
scenarioLine: 12
},
{
featureFile: path.join('test', 'features', 'sample.feature'),
isScenarioOutline: false,
scenarioLine: 14
scenarioLine: 15
},
{
featureFile: path.join('test', 'features', 'sample2.feature'),
Expand Down
16 changes: 8 additions & 8 deletions test/test-handler-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ describe('Test Handler', function() {
});

it('should return the overall exit code when all tests finish', function () {
var opts = options.default;
this.timeout(timeoutMs);
fs.ensureDir(opts.logDir);
fs.ensureDir(options.default.logDir);

function nonInjectedExitCode() {
let cukeRunner = new TestHandler(opts);
let cukeRunner = new TestHandler(options.default);
return cukeRunner.run();
}

function injectedExitCode() {
let injectedCukeRunner = new TestHandler(opts);
let injectedCukeRunner = new TestHandler(options.tagged);
injectedCukeRunner.overallExitCode = 10;
return injectedCukeRunner.run();
}

return Promise.all([
nonInjectedExitCode().should.eventually.have.deep.property('exitCode').and.to.be.equal(0),
injectedExitCode().should.eventually.have.deep.property('exitCode').and.to.be.equal(10)
]);
return Promise.all([ nonInjectedExitCode(), injectedExitCode() ])
.then(([ cleanRun, injectedRun]) => {
cleanRun.should.have.deep.property('exitCode').and.to.be.equal(0);
injectedRun.should.have.deep.property('exitCode').and.to.be.equal(10);
});
});

it('should return the output handler', function () {
Expand Down