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(jest): add support for vitest #231

Merged
merged 12 commits into from
Oct 1, 2024

Conversation

YiCChi
Copy link
Contributor

@YiCChi YiCChi commented Jul 3, 2024

Close #216

Some code comes from a nice package https://github.com/stschulte/aws-sdk-client-mock-vitest, which adds custom matchers for only vitest.

change for implemetation of matchers

  • use objectContaining(input).asymmetricMatch(received.input) instead of this.equals(received, expect.objectContaining(input)) for compatibility
  • create new type definition for MatcherContext, ExpectationResult, etc. for compatibility

vitest support

  • use in vitest with import 'aws-sdk-client-mock-jest/vitest'
  • create new error message in a vitest-style. (referring to toHaveBeenCalled, toHaveBeenCalledTimes, toHaveBeenCalledWith, toHaveBeenNthCalledWith)

@YiCChi
Copy link
Contributor Author

YiCChi commented Jul 3, 2024

@m-radzikowski could you please review this PR? thank you!

@stschulte
Copy link

Interesting to see that you can make this compatible for both jest and vitest. I ended up developing https://github.com/stschulte/aws-sdk-client-mock-vitest that may also work for you while this is under review (aws-sdk-client-mock-vitest was heavily inspired by aws-sdk-client-mock-jest)

@YiCChi
Copy link
Contributor Author

YiCChi commented Jul 9, 2024

@stschulte aws-sdk-client-mock-vitest works very well, and helps me a lot! I will always use it after this pr get merged because I only use vitest in my project.
I created this pr (inspired by aws-sdk-client-mock-vitest) for those who cloudn't find aws-sdk-client-mock-vitest. To be honest, if it can be linked in this repo, maybe this is not needed.

@jimmyn
Copy link

jimmyn commented Jul 31, 2024

I would love to see this merged as well!

@m-radzikowski
Copy link
Owner

Hey, that looks nice. I'll try to review it fully this week, there is quite a lot of changes here.

Copy link
Owner

@m-radzikowski m-radzikowski left a comment

Choose a reason for hiding this comment

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

A lot of nice work! I put some comments, generally small things, please check it out.

packages/aws-sdk-client-mock-jest/src/jestMatchers.ts Outdated Show resolved Hide resolved
packages/aws-sdk-client-mock-jest/vitest.serializer.ts Outdated Show resolved Hide resolved
packages/aws-sdk-client-mock-jest/src/jestGlobals.ts Outdated Show resolved Hide resolved
packages/aws-sdk-client-mock-jest/package.json Outdated Show resolved Hide resolved
@m-radzikowski m-radzikowski changed the title feat: add support for vitest feat(jest): add support for vitest Sep 29, 2024
@m-radzikowski
Copy link
Owner

Thanks for the changes! The tests are failing because you didn't update the import in test-d/types.ts.

Apart from that, it looks good. My only concern now is if having dependencies on both expect and @vitest/expect won't cause anyone any problems... But on the other hand, those libs are only referenced if you import aws-sdk-client-mock-jest or aws-sdk-client-mock-jest/vitest, so I hope it will be okay.

If you fix the build, I will merge it and release a beta version.

@YiCChi
Copy link
Contributor Author

YiCChi commented Sep 30, 2024

Updated the import.

My only concern now is if having dependencies on both expect and @vitest/expect won't cause anyone any problems...

I had considered the same thing, so I didn't reference any types from either package in jestMatchers.ts. Instead, I created many type declarations to satisfy the minimum type constraints. I think the best way is to split it into two packages, but that's up to you.

@m-radzikowski m-radzikowski merged commit 3ed37a9 into m-radzikowski:main Oct 1, 2024
2 checks passed
@m-radzikowski
Copy link
Owner

I've merged but the build on main failed: https://github.com/m-radzikowski/aws-sdk-client-mock/actions/runs/11128928698

I'm away now so I can only merge something from mobile. I can fix it and release in 1.5 week or you can make a PR to fix it if you want it released sooner.

@m-radzikowski
Copy link
Owner

Released in v4.1.0-beta.0

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

Successfully merging this pull request may close these issues.

3.1.0 / 4.0.0 breaks existing test-suite/build with Invalid Chai property: toHaveReceivedCommandWith on vitest
4 participants