m-radzikowski / aws-sdk-client-mock

AWS JavaScript SDK v3 mocks for easy unit testing. 🖋️ Typed 🔬 Tested 📄 Documented 🛠️ Maintained
https://m-radzikowski.github.io/aws-sdk-client-mock/
MIT License
811 stars 40 forks source link

feat(jest): add support for vitest #231

Closed YiCChi closed 1 month ago

YiCChi commented 4 months ago

Close https://github.com/m-radzikowski/aws-sdk-client-mock/issues/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

vitest support

YiCChi commented 4 months ago

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

stschulte commented 4 months ago

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 commented 4 months ago

@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 commented 3 months ago

I would love to see this merged as well!

m-radzikowski commented 2 months ago

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

m-radzikowski commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

Released in v4.1.0-beta.0