Skip to content

Commit 8bde9b4

Browse files
authored
test: improve test coverage in a few areas (#227)
1 parent 138bb90 commit 8bde9b4

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

lib/rules/prefer-output-null.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ module.exports = {
4545
*/
4646
function getTestInfo (key) {
4747
if (test.type === 'ObjectExpression') {
48-
const res = test.properties.filter(item => item.key.name === key);
49-
return res.length > 0 ? res[res.length - 1] : null;
48+
return test.properties.find(item => item.key.name === key);
5049
}
51-
return key === 'code' ? test : null;
50+
return null;
5251
}
5352

5453
const code = getTestInfo('code');

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"estraverse": "^5.2.0"
3535
},
3636
"nyc": {
37-
"branches": 98,
38-
"functions": 98,
37+
"branches": 99,
38+
"functions": 99,
3939
"lines": 99,
4040
"statements": 99
4141
},

tests/lib/rules/prefer-message-ids.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ ruleTester.run('prefer-message-ids', rule, {
104104
}
105105
};
106106
`,
107+
// `meta.messages` has no static value.
108+
`
109+
module.exports = {
110+
meta: { messages },
111+
create(context) {
112+
context.report({ node, messageId: FOO });
113+
}
114+
};
115+
`,
116+
// `context.report` with no args.
117+
`
118+
module.exports = {
119+
meta: { messages },
120+
create(context) {
121+
context.report();
122+
}
123+
};
124+
`,
107125
],
108126

109127
invalid: [

tests/lib/rules/prefer-output-null.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ ruleTester.run('prefer-output-null', rule, {
4545
invalid: []
4646
});
4747
`,
48-
48+
// Dynamic cases.
49+
`
50+
new RuleTester().run('foo', bar, {
51+
valid: [
52+
FOO_CASE
53+
],
54+
invalid: [
55+
FOO_CASE,
56+
]
57+
});
58+
`,
4959
],
5060

5161
invalid: [

tests/lib/rules/require-meta-schema.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ schema: []
150150
},
151151
],
152152
},
153+
{
154+
// No `meta`, uses `context.options`. Two violations on `create`.
155+
code: 'module.exports = { create(context) { const options = context.options; } };',
156+
output: null,
157+
errors: [
158+
{
159+
messageId: 'foundOptionsUsage',
160+
type: 'FunctionExpression',
161+
suggestions: [],
162+
},
163+
{
164+
messageId: 'missing',
165+
type: 'FunctionExpression',
166+
suggestions: [],
167+
},
168+
],
169+
},
153170
{
154171
// requireSchemaPropertyWhenOptionless = true.
155172
code: `

0 commit comments

Comments
 (0)