Skip to content

test: improve test coverage in a few areas #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/rules/prefer-output-null.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ module.exports = {
*/
function getTestInfo (key) {
if (test.type === 'ObjectExpression') {
const res = test.properties.filter(item => item.key.name === key);
return res.length > 0 ? res[res.length - 1] : null;
return test.properties.find(item => item.key.name === key);
}
return key === 'code' ? test : null;
return null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No functional change here. Just removing some dead codepaths that can't be hit for invalid test cases.

}

const code = getTestInfo('code');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"estraverse": "^5.2.0"
},
"nyc": {
"branches": 98,
"functions": 98,
"branches": 99,
"functions": 99,
"lines": 99,
"statements": 99
},
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/prefer-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ ruleTester.run('prefer-message-ids', rule, {
}
};
`,
// `meta.messages` has no static value.
`
module.exports = {
meta: { messages },
create(context) {
context.report({ node, messageId: FOO });
}
};
`,
// `context.report` with no args.
`
module.exports = {
meta: { messages },
create(context) {
context.report();
}
};
`,
],

invalid: [
Expand Down
12 changes: 11 additions & 1 deletion tests/lib/rules/prefer-output-null.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ ruleTester.run('prefer-output-null', rule, {
invalid: []
});
`,

// Dynamic cases.
`
new RuleTester().run('foo', bar, {
valid: [
FOO_CASE
],
invalid: [
FOO_CASE,
]
});
`,
],

invalid: [
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/require-meta-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ schema: []
},
],
},
{
// No `meta`, uses `context.options`. Two violations on `create`.
code: 'module.exports = { create(context) { const options = context.options; } };',
output: null,
errors: [
{
messageId: 'foundOptionsUsage',
type: 'FunctionExpression',
suggestions: [],
},
{
messageId: 'missing',
type: 'FunctionExpression',
suggestions: [],
},
],
},
{
// requireSchemaPropertyWhenOptionless = true.
code: `
Expand Down