-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrule-tester.js
90 lines (63 loc) · 1.75 KB
/
rule-tester.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* global it, describe, beforeEach */
const assert = require('assert');
const Linter = require('bpmnlint/lib/linter');
function createResolver(rule) {
return {
resolveRule: () => Promise.resolve(rule)
};
}
function expectEqual(a, b) {
assert.deepStrictEqual(a, b);
}
function verify(ruleName, rule, testCases) {
const linterConfig = {
rules: { [ruleName]: 2 }
};
describe(`rules/${ruleName}`, function() {
let linter;
beforeEach(function() {
linter = new Linter({
resolver: createResolver(rule)
});
});
describe('should lint valid', function() {
testCases.valid.forEach(({ moddleElement }, idx) => (
it(`test case #${idx + 1}`, function() {
return (
Promise.resolve(moddleElement)
.then(moddleRoot => {
return linter.lint(moddleRoot.root, linterConfig);
})
.then(lintResults => {
expectEqual(lintResults, {});
})
);
})
));
});
describe('should lint invalid', function() {
testCases.invalid.forEach(({ moddleElement, report }, idx) => (
it(`test case #${idx}`, function() {
const expectedResult = report instanceof Array ? report : [{
...report,
category: 'error'
}];
return (
Promise.resolve(moddleElement)
.then(moddleRoot => {
return linter.lint(moddleRoot.root, linterConfig);
})
.then(lintResults => {
expectEqual(lintResults, {
[ruleName]: expectedResult
});
})
);
})
));
});
});
}
module.exports = {
verify
};