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

Replace Should.js with Chai #1167

Open
matthew-white opened this issue Jul 30, 2024 · 3 comments
Open

Replace Should.js with Chai #1167

matthew-white opened this issue Jul 30, 2024 · 3 comments
Labels
infrastructure Changes to core libraries or setup testing Integration tests, unit tests

Comments

@matthew-white
Copy link
Member

Should.js hasn't been updated on npm since 2018, and its repo is archived. We had to move from Should.js to Chai in Frontend (getodk/central-frontend#1015). There are a lot of similarities between the two, but Chai is better documented. There are also some differences, and I think trying to remember those differences while switching between Backend and Frontend will end up causing friction. This issue is to replace Should.js with Chai in Backend. We should time work on this issue such that no large Backend work is in progress.

@matthew-white matthew-white added testing Integration tests, unit tests refactor Improves code without altering behavior labels Jul 30, 2024
@matthew-white matthew-white added infrastructure Changes to core libraries or setup and removed refactor Improves code without altering behavior labels Nov 10, 2024
@alxndrsn
Copy link
Contributor

We had to move from Should.js to Chai in Frontend

Is there any background on what forced the change?

@alxndrsn
Copy link
Contributor

Would it be acceptable to replace should incrementally? E.g. in different test suites individually?

@matthew-white
Copy link
Member Author

We had to move from Should.js to Chai in Frontend

Is there any background on what forced the change?

I'm working on replacing Vue CLI with Vite (getodk/central-frontend#671). As part of that, I'm replacing Karma with Vitest (specifically, Vitest's browser mode). However, Should.js doesn't play well with Vitest: I see an error when I try to use it. I think it's because Should.js doesn't play well with ES Modules.

It actually didn't take too long to replace Should.js with Chai in Frontend, which is part of what made me think that we might as well make the switch in Backend as well. I like that Chai is much better documented and that it's maintained.

Would it be acceptable to replace should incrementally? E.g. in different test suites individually?

I think it'd be reasonable for migration tests to start using Chai right away. If anything, it'd be one fewer instance of Should.js for us to convert later. 😅

Chai has three options for assertion style: assert, expect, and should. I adopted the should style in Frontend, since that allowed me to minimize the number of changes. However, like Should.js, the should style of Chai extends Object.prototype, so I don't think that Should.js and Chai can coexist in tests that are run together. It's not like one integration test could use Should.js while another uses Chai. But since migration tests are separate, I think it would work for them to use Chai from the start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Changes to core libraries or setup testing Integration tests, unit tests
Projects
None yet
Development

No branches or pull requests

2 participants