Skip to content
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

fix(no-large-snapshots): run on files of any type #581

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/rules/__tests__/no-large-snapshots.test.ts
Expand Up @@ -41,11 +41,6 @@ ruleTester.run('no-large-snapshots', rule, {
'toThrowErrorMatchingInlineSnapshot',
),
},
{
// "it should return an empty object for non snapshot files"
Copy link
Member

Choose a reason for hiding this comment

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

nove it to invalid to validate it fails for non .js?

Copy link
Author

Choose a reason for hiding this comment

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

I'm sorry @SimenB, I don't get your question. Could you rephrase it?

Copy link
Author

Choose a reason for hiding this comment

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

@SimenB bumping up

Copy link
Member

Choose a reason for hiding this comment

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

There is no test that asserts test files with any extension is tested - instead of removing the test that asserts unknown extensions are not tested, change it to verify it is tested

filename: 'mock.jsx',
code: generateExpectInlineSnapsCode(50, 'toMatchInlineSnapshot'),
},
{
filename: 'mock.jsx',
code: generateExpectInlineSnapsCode(20, 'toMatchInlineSnapshot'),
Expand Down
39 changes: 17 additions & 22 deletions src/rules/no-large-snapshots.ts
Expand Up @@ -115,29 +115,24 @@ export default createRule<[RuleOptions], MessageId>({
reportOnViolation(context, node, options);
},
};
} else if (context.getFilename().endsWith('.js')) {
return {
CallExpression(node) {
if (
'property' in node.callee &&
(isSupportedAccessor(
node.callee.property,
'toMatchInlineSnapshot',
) ||
isSupportedAccessor(
node.callee.property,
'toThrowErrorMatchingInlineSnapshot',
))
) {
reportOnViolation(context, node, {
...options,
maxSize: options.inlineMaxSize ?? options.maxSize,
});
}
},
};
}

return {};
return {
CallExpression(node) {
if (
'property' in node.callee &&
(isSupportedAccessor(node.callee.property, 'toMatchInlineSnapshot') ||
isSupportedAccessor(
node.callee.property,
'toThrowErrorMatchingInlineSnapshot',
))
) {
reportOnViolation(context, node, {
...options,
maxSize: options.inlineMaxSize ?? options.maxSize,
});
}
},
};
},
});