eslint-plugin-jest 1.0.1 → 19.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,167 +0,0 @@
1
- /* eslint-disable no-template-curly-in-string */
2
- 'use strict';
3
-
4
- var RuleTester = require('eslint').RuleTester;
5
- var rules = require('../../').rules;
6
-
7
- var ruleTester = new RuleTester();
8
-
9
- ruleTester.run('no-identical-title', rules['no-identical-title'], {
10
- valid: [
11
- [
12
- 'describe("describe", function() {',
13
- ' it("it", function() {});',
14
- '});'
15
- ].join('\n'),
16
- [
17
- 'describe("describe1", function() {',
18
- ' it("it1", function() {});',
19
- ' it("it2", function() {});',
20
- '});'
21
- ].join('\n'),
22
- [
23
- 'it("it1", function() {});',
24
- 'it("it2", function() {});'
25
- ].join('\n'),
26
- [
27
- 'it.only("it1", function() {});',
28
- 'it("it2", function() {});'
29
- ].join('\n'),
30
- [
31
- 'it.only("it1", function() {});',
32
- 'it.only("it2", function() {});'
33
- ].join('\n'),
34
- [
35
- 'describe("title", function() {});',
36
- 'it("title", function() {});'
37
- ].join('\n'),
38
- [
39
- 'describe("describe1", function() {',
40
- ' it("it1", function() {});',
41
- ' describe("describe2", function() {',
42
- ' it("it1", function() {});',
43
- ' });',
44
- '});'
45
- ].join('\n'),
46
- [
47
- 'describe("describe1", function() {',
48
- ' describe("describe2", function() {',
49
- ' it("it1", function() {});',
50
- ' });',
51
- ' it("it1", function() {});',
52
- '});'
53
- ].join('\n'),
54
- [
55
- 'describe("describe1", function() {',
56
- ' describe("describe2", function() {});',
57
- '});'
58
- ].join('\n'),
59
- [
60
- 'describe("describe1", function() {',
61
- ' describe("describe2", function() {});',
62
- '});',
63
- 'describe("describe2", function() {});'
64
- ].join('\n'),
65
- [
66
- 'describe("describe1", function() {});',
67
- 'describe("describe2", function() {});'
68
- ].join('\n'),
69
- [
70
- 'it("it" + n, function() {});',
71
- 'it("it" + n, function() {});'
72
- ].join('\n'),
73
- {
74
- code: [
75
- 'it(`it${n}`, function() {});',
76
- 'it(`it${n}`, function() {});'
77
- ].join('\n'),
78
- env: {
79
- es6: true
80
- }
81
- },
82
- [
83
- 'describe("title " + foo, function() {',
84
- ' describe("describe1", function() {});',
85
- '});',
86
- 'describe("describe1", function() {});'
87
- ].join('\n'),
88
- [
89
- 'describe("describe1", function() {',
90
- ' describe("describe2", function() {});',
91
- ' describe("title " + foo, function() {',
92
- ' describe("describe2", function() {});',
93
- ' });',
94
- '});'
95
- ].join('\n')
96
- ],
97
-
98
- invalid: [
99
- {
100
- code: [
101
- 'describe("describe1", function() {',
102
- ' it("it1", function() {});',
103
- ' it("it1", function() {});',
104
- '});'
105
- ].join('\n'),
106
- errors: [{ message: 'Test title is used multiple times in the same test suite.', column: 4, line: 3 }]
107
- },
108
- {
109
- code: [
110
- 'it("it1", function() {});',
111
- 'it("it1", function() {});'
112
- ].join('\n'),
113
- errors: [{ message: 'Test title is used multiple times in the same test suite.', column: 1, line: 2 }]
114
- },
115
- {
116
- code: [
117
- 'it.only("it1", function() {});',
118
- 'it("it1", function() {});'
119
- ].join('\n'),
120
- errors: [{ message: 'Test title is used multiple times in the same test suite.', column: 1, line: 2 }]
121
- },
122
- {
123
- code: [
124
- 'fit("it1", function() {});',
125
- 'it("it1", function() {});'
126
- ].join('\n'),
127
- errors: [{ message: 'Test title is used multiple times in the same test suite.', column: 1, line: 2 }]
128
- },
129
- {
130
- code: [
131
- 'it.only("it1", function() {});',
132
- 'it.only("it1", function() {});'
133
- ].join('\n'),
134
- errors: [{ message: 'Test title is used multiple times in the same test suite.', column: 1, line: 2 }]
135
- },
136
- {
137
- code: [
138
- 'describe("describe1", function() {});',
139
- 'describe("describe1", function() {});'
140
- ].join('\n'),
141
- errors: [{ message: 'Test suite title is used multiple times.', column: 1, line: 2 }]
142
- },
143
- {
144
- code: [
145
- 'describe("describe1", function() {});',
146
- 'xdescribe("describe1", function() {});'
147
- ].join('\n'),
148
- errors: [{ message: 'Test suite title is used multiple times.', column: 1, line: 2 }]
149
- },
150
- {
151
- code: [
152
- 'fdescribe("describe1", function() {});',
153
- 'describe("describe1", function() {});'
154
- ].join('\n'),
155
- errors: [{ message: 'Test suite title is used multiple times.', column: 1, line: 2 }]
156
- },
157
- {
158
- code: [
159
- 'describe("describe1", function() {',
160
- ' describe("describe2", function() {});',
161
- '});',
162
- 'describe("describe1", function() {});'
163
- ].join('\n'),
164
- errors: [{ message: 'Test suite title is used multiple times.', column: 1, line: 4 }]
165
- }
166
- ],
167
- });
@@ -1,62 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = function(context) {
4
- var jestTestFunctions = [
5
- 'it',
6
- 'describe',
7
- 'test',
8
- ];
9
-
10
- function matchesTestFunction(object) {
11
- return object && jestTestFunctions.indexOf(object.name) !== -1;
12
- }
13
-
14
- function matchesExclusiveTestFunction(object) {
15
- return (
16
- object &&
17
- object.name.charAt(0) === 'f' &&
18
- jestTestFunctions.indexOf(object.name.substring(1)) !== -1
19
- );
20
- }
21
-
22
- function isPropertyNamedOnly(property) {
23
- return property && (property.name === 'only' || property.value === 'only');
24
- }
25
-
26
- function isCallToJestOnlyFunction(callee) {
27
- return callee.type === 'MemberExpression' && (
28
- matchesTestFunction(callee.object) && isPropertyNamedOnly(callee.property)
29
- );
30
- }
31
-
32
- function isCallToExclusiveJestFunction(callee) {
33
- return callee.type === 'Identifier' && (
34
- matchesExclusiveTestFunction(callee)
35
- );
36
- }
37
-
38
- return {
39
- CallExpression: function(node) {
40
- var callee = node.callee;
41
- if (!callee) {
42
- return;
43
- }
44
-
45
- if (isCallToJestOnlyFunction(callee)) {
46
- context.report({
47
- node: callee.property,
48
- message: 'Unexpected exclusive test.',
49
- });
50
- return;
51
- }
52
-
53
- if (isCallToExclusiveJestFunction(callee)) {
54
- context.report({
55
- node: callee,
56
- message: 'Unexpected exclusive test.',
57
- });
58
- return;
59
- }
60
- },
61
- };
62
- };
@@ -1,101 +0,0 @@
1
- 'use strict';
2
-
3
- var describeAliases = [
4
- 'describe',
5
- 'xdescribe',
6
- 'describe.only',
7
- 'describe.skip',
8
- 'fdescribe',
9
- ];
10
-
11
- var testCaseNames = [
12
- 'it',
13
- 'it.only',
14
- 'it.skip',
15
- 'fit',
16
- 'test',
17
- 'test.only',
18
- 'test.skip',
19
- 'ftest',
20
- ];
21
-
22
- function getNodeName(node) {
23
- if (node.type === 'MemberExpression') {
24
- return node.object.name + '.' + node.property.name;
25
- }
26
- return node.name;
27
- }
28
-
29
- function isDescribe(node) {
30
- return node
31
- && node.type === 'CallExpression'
32
- && describeAliases.indexOf(getNodeName(node.callee)) > -1;
33
- }
34
-
35
- function isTestCase(node) {
36
- return node
37
- && node.type === 'CallExpression'
38
- && testCaseNames.indexOf(getNodeName(node.callee)) > -1;
39
- }
40
-
41
- function newDescribeContext() {
42
- return {
43
- describeTitles: [],
44
- testTitles: []
45
- };
46
- }
47
-
48
- function handlTestCaseTitles(context, titles, node, title) {
49
- if (isTestCase(node)) {
50
- if (titles.indexOf(title) !== -1) {
51
- context.report({
52
- node: node,
53
- message: 'Test title is used multiple times in the same test suite.'
54
- });
55
- }
56
- titles.push(title);
57
- }
58
- }
59
-
60
- function handlTestSuiteTitles(context, titles, node, title) {
61
- if (!isDescribe(node)) {
62
- return;
63
- }
64
- if (titles.indexOf(title) !== -1) {
65
- context.report({
66
- node: node,
67
- message: 'Test suite title is used multiple times.'
68
- });
69
- }
70
- titles.push(title);
71
- }
72
-
73
- function isFirstArgLiteral(node) {
74
- return node.arguments && node.arguments[0] && node.arguments[0].type === 'Literal';
75
- }
76
-
77
- module.exports = function(context) {
78
- var contexts = [
79
- newDescribeContext()
80
- ];
81
- return {
82
- CallExpression: function(node) {
83
- var currentLayer = contexts[contexts.length - 1];
84
- if (isDescribe(node)) {
85
- contexts.push(newDescribeContext());
86
- }
87
- if (!isFirstArgLiteral(node)) {
88
- return;
89
- }
90
-
91
- var title = node.arguments[0].value;
92
- handlTestCaseTitles(context, currentLayer.testTitles, node, title);
93
- handlTestSuiteTitles(context, currentLayer.describeTitles, node, title);
94
- },
95
- 'CallExpression:exit': function(node) {
96
- if (isDescribe(node)) {
97
- contexts.pop();
98
- }
99
- }
100
- };
101
- };