-
Notifications
You must be signed in to change notification settings - Fork 49
/
max-asserts.js
77 lines (73 loc) · 1.84 KB
/
max-asserts.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
import test from 'ava';
import avaRuleTester from 'eslint-ava-rule-tester';
import rule from '../rules/max-asserts';
const ruleTester = avaRuleTester(test, {
env: {
es6: true
}
});
const errors = [{ruleId: 'max-asserts'}];
const header = `const test = require('ava');\n`;
function nbAssertions(n) {
return Array.from({length: n}).map(() => 't.is(1, 1);').join('\n');
}
ruleTester.run('max-asserts', rule, {
valid: [
`${header} test(t => { ${nbAssertions(3)} });`,
`${header}
test(t => { ${nbAssertions(3)} });
test(t => { ${nbAssertions(3)} });
`,
`${header} test(t => { t.plan(5); ${nbAssertions(5)} });`,
`${header} test(t => { t.is.skip(1, 1); ${nbAssertions(4)} });`,
`${header} test.cb(t => { ${nbAssertions(5)} t.end(); });`,
{
code: `${header} test(t => { ${nbAssertions(3)} });`,
options: [3]
},
{
code: `${header} test(t => { notT.is(1, 1); notT.is(1, 1); notT.is(1, 1); });`,
options: [2]
},
// shouldn't be triggered since it's not a test file
`test(t => { ${nbAssertions(10)} });`
],
invalid: [
{
code: `${header} test(t => { ${nbAssertions(6)} });`,
errors
},
{
code: `${header}
test(t => { ${nbAssertions(3)} });
test(t => { ${nbAssertions(6)} });
`,
errors
},
{
code: `${header} test(t => { t.plan(5); ${nbAssertions(6)} });`,
errors
},
{
code: `${header} test(t => { t.skip.is(1, 1); ${nbAssertions(5)} });`,
errors
},
{
code: `${header} test.cb(t => { ${nbAssertions(6)} t.end(); });`,
errors
},
{
code: `${header} test(t => { ${nbAssertions(4)} });`,
options: [3],
errors
},
{
code: `${header} test(t => { ${nbAssertions(10)} });`,
errors
},
{
code: `${header} test(t => { ${nbAssertions(10)} }); test(t => { ${nbAssertions(10)} });`,
errors: errors.concat(errors) // Should have two errors, one per test
}
]
});