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

[new-rule] enforce describe blocks match module exports #675

Open
remcohaszing opened this issue Sep 21, 2020 · 2 comments
Open

[new-rule] enforce describe blocks match module exports #675

remcohaszing opened this issue Sep 21, 2020 · 2 comments

Comments

@remcohaszing
Copy link

I like to write my tests, so each describe block matches an export of the similar named module.

For example, given the following module:

// module.js
export function foo() {}

export const bar = () => {}

I would like to enforce the following layout for a test file:

// module.test.js
describe('foo' () => {});

describe('bar' () => {});

I would like to propose a rule that verifies the name of a top-level describe block match the name of an export in the module with the same name, minus the .test / .spec postfix.

@G-Rath
Copy link
Collaborator

G-Rath commented Sep 21, 2020

I like it! but unfortunately I don't know if it's possible, since we can't parse other files with eslint - additionally we recommend using overrides to apply our rules to only test files which might affect things.

In saying that, iirc eslint-plugin-node might do something like this so maybe it is possible? 🤔

When I have a chance I'll play around with some things, see if there's maybe some eslint utils that could be used.

I definitely love the idea, so 🤞 it can be done!

@remcohaszing
Copy link
Author

I like it!

Cool! I thought you’d either love or hate the idea.


Actually this is very similar to import/named.

I believe their logic to process the referenced module is in eslint-module-utils.

@G-Rath G-Rath changed the title Rule proposal: enforce describe blocks match module exports [new-rule] enforce describe blocks match module exports Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants