Skip to content

Commit

Permalink
Merge 4cf53e0 into 53dbda7
Browse files Browse the repository at this point in the history
  • Loading branch information
vsiakka committed May 4, 2019
2 parents 53dbda7 + 4cf53e0 commit e82ee8a
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 40 deletions.
7 changes: 3 additions & 4 deletions src/rules.js
Expand Up @@ -35,14 +35,12 @@ function isRuleEnabled(ruleConfig) {

function runAllEnabledRules(feature, file, configuration, additionalRulesDirs) {
var errors = [];
var ignoreFutureErrors = false;
var rules = getAllRules(additionalRulesDirs);
Object.keys(rules).forEach(function(ruleName) {
var rule = rules[ruleName];
if (isRuleEnabled(configuration[rule.name]) && !ignoreFutureErrors) {
if (isRuleEnabled(configuration[rule.name])) {
var ruleConfig = Array.isArray(configuration[rule.name]) ? configuration[rule.name][1] : {};
var error = rule.run(feature, file, ruleConfig);

if (error) {
errors = errors.concat(error);
}
Expand All @@ -56,5 +54,6 @@ module.exports = {
doesRuleExist: doesRuleExist,
isRuleEnabled: isRuleEnabled,
runAllEnabledRules: runAllEnabledRules,
getRule: getRule
getRule: getRule,
getAllRules: getAllRules
};
4 changes: 3 additions & 1 deletion src/rules/max-scenarios-per-file.js
Expand Up @@ -22,7 +22,9 @@ function maxScenariosPerFile(feature, unused, config) {
if (scenario.examples) {
count = count - 1;
scenario.examples.forEach(function (example) {
count = count + example.tableBody.length;
if (example.tableBody) {
count = count + example.tableBody.length;
}
});
}
});
Expand Down
22 changes: 14 additions & 8 deletions src/rules/required-tags.js
Expand Up @@ -24,14 +24,20 @@ const checkTagExists = (requiredTag, scenarioTags, scenarioType) => {

const checkRequiredTagsExistInScenarios = (feature, file, config) => {
let errors = [];
feature.children.forEach((scenario) => {
// Check each Scenario for the required tags
const requiredTagErrors = config.tags.map((requiredTag) => {
return checkTagExists(requiredTag, scenario.tags || [], scenario.type);
}).filter((item) => typeof item === 'object' && item.message);
// Update errors
errors = errors.concat(requiredTagErrors);
});
if (feature.children) {
feature.children.forEach((scenario) => {
// Check each Scenario for the required tags
const requiredTagErrors = config.tags
.map((requiredTag) => {
return checkTagExists(requiredTag, scenario.tags || [], scenario.type);
})
.filter((item) =>
typeof item === 'object' && item.message
);
// Update errors
errors = errors.concat(requiredTagErrors);
});
}
return errors;
};

Expand Down
7 changes: 6 additions & 1 deletion src/rules/scenario-size.js
@@ -1,3 +1,5 @@
var _ = require('lodash');

var rule = 'scenario-size';
var availableConfigs = {
'steps-length': {
Expand All @@ -6,7 +8,10 @@ var availableConfigs = {
}
};

function scenarioSize(feature, fileName, configuration = availableConfigs) {
function scenarioSize(feature, fileName, configuration) {
if (_.isEmpty(configuration)) {
configuration = availableConfigs;
}
const errors = [];
if (feature.children) {
feature.children.forEach((child) => {
Expand Down
1 change: 1 addition & 0 deletions test/rules/all-rules/ChildlessFeature.feature
@@ -0,0 +1 @@
Feature: This is a childless feature
6 changes: 6 additions & 0 deletions test/rules/all-rules/EmptyExamples.feature
@@ -0,0 +1,6 @@
Feature: Some Feature

Scenario Outline: Some Scenario Outline
Given this is a step

Examples:
File renamed without changes.
7 changes: 7 additions & 0 deletions test/rules/all-rules/SteplessFeature.feature
@@ -0,0 +1,7 @@
Feature:

Background:

Scenario:

Scenario Outline:
40 changes: 40 additions & 0 deletions test/rules/all-rules/all-rules.js
@@ -0,0 +1,40 @@
var rules = require('../../../dist/rules.js');
var linter = require('../../../dist/linter.js');

// Test cases for incomplete feature files that have broken over time accross multiple rules
describe('All rules', function() {

function runAllEnabledRulesAgainstFile(featureFile) {
var allRules = rules.getAllRules();
var configuration = {};
Object.keys(allRules).forEach(function(rule) {
if (rule == 'new-line-at-eof') {
configuration[rule] = ['on', 'yes'];
} else if (rule == 'required-tags') {
configuration[rule] = ['on', {'tags': [] }];
} else {
configuration[rule] = 'on';
}
});

const {feature, file} = linter.readAndParseFile('test/rules/all-rules/' + featureFile, 'utf8');

rules.runAllEnabledRules(feature, file, configuration);
}

it('do not throw exceptions when processing an empty feature', function() {
runAllEnabledRulesAgainstFile('EmptyFeature.feature');
});

it('do not throw exceptions when processing a feature with no children', function() {
runAllEnabledRulesAgainstFile('ChildlessFeature.feature');
});

it('do not throw exceptions when processing a feature with no steps', function() {
runAllEnabledRulesAgainstFile('SteplessFeature.feature');
});

it('do not throw exceptions when processing a scenario outline with an empty examples table', function() {
runAllEnabledRulesAgainstFile('EmptyExamples.feature');
});
});
4 changes: 0 additions & 4 deletions test/rules/indentation/indentation.js
Expand Up @@ -59,10 +59,6 @@ describe('Indentation rule', function() {
runTest('indentation/CorrectIndentationTabs.feature', {}, []);
});

it('doesn\'t raise errors when parsing an empty feature', function() {
runTest('indentation/EmptyFeature.feature', {}, []);
});

it('detects errors for features, backgrounds, scenarios, scenario outlines and steps (spaces)', function() {
runTest('indentation/WrongIndentationSpaces.feature', {}, wrongIndenatationErrors);
});
Expand Down
Empty file.
4 changes: 0 additions & 4 deletions test/rules/name-length/name-length.js
Expand Up @@ -8,10 +8,6 @@ describe('Name length rule', function() {
runTest('name-length/CorrectLength.feature', {}, []);
});

it('doesn\'t raise errors when parsing an empty feature', function() {
runTest('name-length/EmptyFeature.feature', {}, []);
});

it('detects errors for features, scenarios, scenario outlines and steps', function() {
runTest('name-length/WrongLength.feature', {}, [{
messageElements: {element: 'Feature', length: 89},
Expand Down
Empty file.
6 changes: 1 addition & 5 deletions test/rules/no-unnamed-scenarios/no-unnamed-scenarios.js
Expand Up @@ -6,11 +6,7 @@ describe('No Unnamed Scenarios Rule', function() {
it('doesn\'t raise errors when there are no violations', function() {
runTest('no-unnamed-scenarios/NoViolations.feature', {}, []);
});

it('doesn\'t raise errors for an empty feature', function() {
runTest('no-unnamed-scenarios/EmptyFeature.feature', {}, []);
});


it('doesn\'t raise errors for a feature with no scenarios', function() {
runTest('no-unnamed-scenarios/FeatureWithNoScenarios.feature', {}, []);
});
Expand Down
Empty file.
5 changes: 0 additions & 5 deletions test/rules/no-unused-variables/no-unused-variables.js
Expand Up @@ -7,11 +7,6 @@ describe('No Unused Variables Rule', function() {
runTest('no-unused-variables/NoViolations.feature', {}, []);
});

it('doesn\'t raise errors when parsing an empty feature', function() {
var runTest = ruleTestBase.createRuleTest(rule, '');
runTest('no-unused-variables/EmptyFeature.feature', {}, []);
});

it('detects unused scenario variables', function() {
var runTest = ruleTestBase.createRuleTest(rule,
'Step variable "<%= variable %>" does not exist the in examples table');
Expand Down
Empty file.
4 changes: 0 additions & 4 deletions test/rules/one-space-between-tags/one-space-between-tags.js
Expand Up @@ -8,10 +8,6 @@ describe('One Space Between Tags Rule', function() {
runTest('one-space-between-tags/NoViolations.feature', {}, []);
});

it('doesn\'t raise errors when parsing an empty feature', function() {
runTest('one-space-between-tags/EmptyFeature.feature', {}, []);
});

it('detects errors for tags on features, scenarios, and scenario outlines', function() {
runTest('one-space-between-tags/Violations.feature', {}, [{
line: 1,
Expand Down
Empty file.
4 changes: 0 additions & 4 deletions test/rules/use-and/use-and.js
Expand Up @@ -8,10 +8,6 @@ describe('Use And Rule', function() {
runTest('use-and/NoViolations.feature', {}, []);
});

it('doesn\'t raise errors when parsing an empty feature', function() {
runTest('use-and/EmptyFeature.feature', {}, []);
});

it('raises erros when there are violations', function() {
runTest('use-and/Violations.feature', {}, [
{
Expand Down

0 comments on commit e82ee8a

Please sign in to comment.