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

feat: add support for test files colocated with models #1187

Conversation

Lucianolo
Copy link
Contributor

@Lucianolo Lucianolo commented Nov 3, 2022

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Description of change

The models/index.js file is an auto-generated file used to automatically register all models from the models folder
It works under the assumption that the only files you have in your /models folder are models.
This works for most of the cases, but it causes an issue for projects using tests colocated with the tested file, e.g.

models/
    person.js
    person.test.js
    dog.js
    dog.test.js
    index.js

for such cases, if you want to add unit tests, you would have to either move to a symmetric /tests folder that replicates the structure of your project (for example as this project does), or follow this approach only for the models folder (quite inconsistent), or not write tests for models (quite bad)

This PR addresses the issue by adding a condition that will skip filenames containing .test.js.

@Lucianolo
Copy link
Contributor Author

i looked for a file with relevant test cases for this code but couldn't find it. If anyone knows where this logic is tested i'm happy to add additional test cases in there

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

I'm also not sure how to test this, but I think we can look into that later. Thanks for this PR!

@WikiRik WikiRik merged commit 6ba32e1 into sequelize:main Nov 5, 2022
@github-actions
Copy link

🎉 This PR is included in version 6.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants