Skip to content

Multiple utils-module for several test types #348

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

Closed
Belco90 opened this issue Apr 20, 2021 · 8 comments
Closed

Multiple utils-module for several test types #348

Belco90 opened this issue Apr 20, 2021 · 8 comments
Labels
awaiting response Waiting for a reply from the OP question Further information is requested

Comments

@Belco90
Copy link
Member

Belco90 commented Apr 20, 2021

I would definitely like to have this feature, but I understand that this is not trival to implement.

We have two different types of tests: unit and integration. Both use a different custom render function and re-export testing-library stuff. Each type has its own module.

Originally posted by @rosczja in #315 (comment)

@Belco90 Belco90 added the question Further information is requested label Apr 20, 2021
@Belco90
Copy link
Member Author

Belco90 commented Apr 20, 2021

Hey @rosczja! I'm moving here your petition for allowing to set a list of modules into utils-module.

This is a feature that will take time to implement and won't happen soon to be honest. However, I'd like you to give us more info about your setup since it might be possible for you to achieve what you want with the current plugin version + ESLint overrides.

Can you share more details about how you differentiate between those two types of tests? Do they have different filename suffix? Or perhaps are located under different folders?

@rosczja
Copy link

rosczja commented Apr 20, 2021

Hey @Belco90 , thank you very much.

Yes, we differentiate between those two types by filename suffix. So you are right, I could try to use overrides. Will definitely try this out.

@Belco90
Copy link
Member Author

Belco90 commented Apr 20, 2021

Alright. Assuming you use .unit and .integration suffixes for differentiate them, you could do something like this:

// .eslintrc
{
  "plugins": [/* other plugins */, "testing-library"],
  "extends": [/* other extends */, "plugin:testing-library/react"],

  "overrides": [
    {
      // unit tests
      "files": ["**/?(*.)+(spec|test).unit.[jt]s?(x)"],
      settings: {
        "testing-library/utils-module": "unit-test-utils"
      }
    },
    {
      // integration tests
      "files": ["**/?(*.)+(spec|test).integration.[jt]s?(x)"],
      settings: {
        "testing-library/utils-module": "integration-test-utils"
      }
    }
  ],
};

However, if you have your tests files identified properly, I'd leave the new Aggressive Reporting doing its thing and run eslint-plugin-testing-library only against your test files (no matter if unit or integration).

Let me know if any of these options work for you!

@Belco90 Belco90 added the awaiting response Waiting for a reply from the OP label Apr 20, 2021
@gndelia
Copy link
Collaborator

gndelia commented Apr 20, 2021

@Belco90 I've seen this kind of snippet mentioned a couple of times (About using the file extension to separate files); Maybe it's worth documenting somewhere (like a FAQ or as part of the readme)

@Belco90
Copy link
Member Author

Belco90 commented Apr 20, 2021

@gndelia we added it to our README!

@gndelia
Copy link
Collaborator

gndelia commented Apr 20, 2021

🤦‍♂️ for me

@rosczja
Copy link

rosczja commented Jun 8, 2021

Hi @Belco90 , thanks again. Works for me, too.

@Belco90
Copy link
Member Author

Belco90 commented Jun 8, 2021

@rosczja I'm glad it works! I'm closing the issue then.

@Belco90 Belco90 closed this as completed Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Waiting for a reply from the OP question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants