-
Notifications
You must be signed in to change notification settings - Fork 73
/
scenario-size.js
42 lines (38 loc) · 1.2 KB
/
scenario-size.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var _ = require('lodash');
var rule = 'scenario-size';
var availableConfigs = {
'steps-length': {
'Background': 15,
'Scenario': 15
}
};
function scenarioSize(feature, fileName, configuration) {
if (_.isEmpty(configuration)) {
configuration = availableConfigs;
}
const errors = [];
if (feature.children) {
feature.children.forEach((child) => {
if (child.type ==='Background') {
if (configuration['steps-length']['Background'] && child.steps.length > configuration['steps-length']['Background']) {
errors.push(createError(child, configuration['steps-length']['Background']));
}
} else {
if (configuration['steps-length']['Scenario'] && child.steps.length > configuration['steps-length']['Scenario']) {
errors.push(createError(child, configuration['steps-length']['Scenario']));
}
}
});
}
return errors;
}
function createError(child, maxSize) {
return {message: `Element ${child.type} too long: actual ${child.steps.length}, expected ${maxSize}`,
rule : 'scenario-size',
line : child.location.line};
}
module.exports = {
name: rule,
run: scenarioSize,
availableConfigs: availableConfigs
};