Skip to content

Commit 1218892

Browse files
GMartignysindresorhus
authored andcommitted
Remove options from the test-title rule (#224)
1 parent 87aeb8e commit 1218892

File tree

3 files changed

+25
-125
lines changed

3 files changed

+25
-125
lines changed

docs/rules/test-title.md

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,12 @@
22

33
Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/related/eslint-plugin-ava/docs/rules/test-title.md)
44

5-
Tests should have a title.
5+
Tests should have a title. AVA [v1.0.1](https://github.com/avajs/ava/releases/tag/v1.0.1) and later enforces this at runtime.
66

77

88
## Fail
99

1010
```js
11-
/*eslint ava/test-title: ["error", "if-multiple"]*/
12-
import test from 'ava';
13-
14-
test(t => {
15-
t.pass();
16-
});
17-
18-
test(t => {
19-
t.pass();
20-
});
21-
22-
/*eslint ava/test-title: ["error", "always"]*/
2311
import test from 'ava';
2412

2513
test(t => {
@@ -31,31 +19,9 @@ test(t => {
3119
## Pass
3220

3321
```js
34-
/*eslint ava/test-title: ["error", "if-multiple"]*/
35-
import test from 'ava';
36-
37-
test(t => {
38-
t.pass();
39-
});
40-
41-
test('foo', t => {
42-
t.pass();
43-
});
44-
45-
/*eslint ava/test-title: ["error", "always"]*/
4622
import test from 'ava';
4723

4824
test('foo', t => {
4925
t.pass();
5026
});
5127
```
52-
53-
## Options
54-
55-
The rule takes one option, a string, which could be either `"always"` or `"if-multiple"`. The default is `"if-multiple"`. If the option is set to `"if-multiple"`, the rule will only trigger if there are multiple tests in a file.
56-
57-
You can set the option in configuration like this:
58-
59-
```js
60-
"ava/test-title": ["error", "always"]
61-
```

rules/test-title.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,31 @@ const util = require('../util');
55

66
const create = context => {
77
const ava = createAvaRule();
8-
const ifMultiple = context.options[0] !== 'always';
9-
let testCount = 0;
108

119
return ava.merge({
1210
CallExpression: visitIf([
1311
ava.isInTestFile,
1412
ava.isTestNode,
1513
ava.hasNoHookModifier
1614
])(node => {
17-
testCount++;
15+
const firstArgumentIsFunction = node.arguments.length < 1 || util.isFunctionExpression(node.arguments[0]);
1816

19-
const requiredLength = ava.hasTestModifier('todo') ? 1 : 2;
20-
const hasNoTitle = node.arguments.length < requiredLength;
21-
const isOverThreshold = !ifMultiple || testCount > 1;
22-
23-
if (hasNoTitle && isOverThreshold) {
17+
if (firstArgumentIsFunction) {
2418
context.report({
2519
node,
2620
message: 'Test should have a title.'
2721
});
2822
}
29-
}),
30-
'Program:exit': () => {
31-
testCount = 0;
32-
}
23+
})
3324
});
3425
};
3526

36-
const schema = [{
37-
enum: [
38-
'always',
39-
'if-multiple'
40-
]
41-
}];
42-
4327
module.exports = {
4428
create,
4529
meta: {
30+
type: 'problem',
4631
docs: {
4732
url: util.getDocsUrl(__filename)
48-
},
49-
schema
33+
}
5034
}
5135
};

test/test-title.js

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,99 +13,49 @@ const header = 'const test = require(\'ava\');\n';
1313

1414
ruleTester.run('test-title', rule, {
1515
valid: [
16-
// Default options should be `['if-multiple']`
17-
header + 'test(t => { t.pass(); t.end(); });',
18-
{
19-
code: header + 'test("my test name", t => { t.pass(); t.end(); });',
20-
options: ['always']
21-
},
22-
{
23-
code: header + 'test(`my test name`, t => { t.pass(); t.end(); });',
24-
options: ['always']
25-
},
26-
{
27-
code: header + 'test(\'my test name\', t => { t.pass(); t.end(); });',
28-
options: ['always']
29-
},
30-
{
31-
code: header + 'test.cb("my test name", t => { t.pass(); t.end(); });',
32-
options: ['always']
33-
},
34-
{
35-
code: header + 'test.todo("my test name");',
36-
options: ['always']
37-
},
38-
{
39-
code: header + 'test.before(t => {});',
40-
options: ['always']
41-
},
42-
{
43-
code: header + 'test.after(t => {});',
44-
options: ['always']
45-
},
46-
{
47-
code: header + 'test.beforeEach(t => {});',
48-
options: ['always']
49-
},
50-
{
51-
code: header + 'test.afterEach(t => {});',
52-
options: ['always']
53-
},
54-
{
55-
code: header + 'test.cb.before(t => {}); test.before.cb(t => {});',
56-
options: ['always']
57-
},
58-
{
59-
code: header + 'test(t => { t.pass(); t.end(); });',
60-
options: ['if-multiple']
61-
},
62-
{
63-
code: header + 'notTest(t => { t.pass(); t.end(); });',
64-
options: ['always']
65-
},
66-
{
67-
code: header + 'test(macroFn, arg1, arg2);',
68-
options: ['always']
69-
},
16+
header + 'test("my test name", t => { t.pass(); t.end(); });',
17+
header + 'test(`my test name`, t => { t.pass(); t.end(); });',
18+
header + 'test(\'my test name\', t => { t.pass(); t.end(); });',
19+
header + 'test.cb("my test name", t => { t.pass(); t.end(); });',
20+
header + 'test.todo("my test name");',
21+
header + 'test.before(t => {});',
22+
header + 'test.after(t => {});',
23+
header + 'test.beforeEach(t => {});',
24+
header + 'test.afterEach(t => {});',
25+
header + 'test.cb.before(t => {}); test.before.cb(t => {});',
26+
header + 'notTest(t => { t.pass(); t.end(); });',
27+
header + 'test([], arg1, arg2);',
28+
header + 'test({}, arg1, arg2);',
7029
// Shouldn't be triggered since it's not a test file
71-
{
72-
code: 'test(t => {});',
73-
options: ['always']
74-
}
30+
'test(t => {});'
7531
],
7632
invalid: [
7733
{
78-
code: header + 'test(t => {}); test(t => {});',
34+
code: header + 'test(t => {});',
35+
errors
36+
},
37+
{
38+
code: header + 'test(t => {}, "my test name");',
7939
errors
8040
},
8141
{
8242
code: header + 'test(t => { t.pass(); t.end(); });',
83-
options: ['always'],
8443
errors
8544
},
8645
{
8746
code: header + 'test.cb(t => { t.pass(); t.end(); });',
88-
options: ['always'],
8947
errors
9048
},
9149
{
9250
code: header + 'test.cb.skip(t => { t.pass(); t.end(); });',
93-
options: ['always'],
9451
errors
9552
},
9653
{
9754
code: header + 'test(t => { t.pass(); t.end(); });',
98-
options: ['always'],
9955
errors
10056
},
10157
{
10258
code: header + 'test.todo();',
103-
options: ['always'],
104-
errors
105-
},
106-
{
107-
code: header + 'test(t => {}); test(t => {});',
108-
options: ['if-multiple'],
10959
errors
11060
}
11161
]

0 commit comments

Comments
 (0)