-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathno-exclusive-tests.js
58 lines (52 loc) · 1.31 KB
/
no-exclusive-tests.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
/**
* @fileoverview Generates an error if describe.only() or it.only() is found.
*/
const minimatch = require('minimatch');
const names = {
describe: true,
it: true
};
const only = 'only';
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'generates an error if a test file calls describe.only() or it.only()',
category: 'Possible Errors',
recommended: true
},
schema: [
{
type: 'object',
properties: {
include: {
type: 'string'
}
},
additionalProperties: false
}
]
},
create: function(context) {
return {
CallExpression(node) {
if (node.callee.type !== 'MemberExpression') {
return;
}
const filename = context.getFilename();
const include = context.options.include || '**/*.test.js';
if (!minimatch(filename, include)) {
return;
}
const object = node.callee.object;
const property = node.callee.property;
if (object.type === 'Identifier' && object.name in names && property.type === 'Identifier' && property.name === only) {
return context.report({
node: property,
message: 'Exlusive tests are not allowed'
});
}
}
};
}
};