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

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

Closed
1 task done
WtfJoke opened this issue Mar 22, 2024 · 4 comments · Fixed by #231
Closed
1 task done
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@WtfJoke
Copy link

WtfJoke commented Mar 22, 2024

Checklist

  • I have read Caveats documentation and didn't find a solution for this problem there.

Bug description

When we upgrade from version 3.0.1 to 3.1.0 our build/tests break.

Maybe related to #198

Reproduction

  1. Clone https://github.com/WtfJoke/aws-sdk-client-mock-reproducer-3.1.0
  2. npm install
  3. npm run build or npm run test fails

Commit is broken (updates the dependency to 3.1.0), where as the initial commit works

Environment

  • Node version: v20.11.0
  • Testing lib and version: vitest 1.4.0
  • Typescript version: 5.4.3
  • AWS SDK v3 Client mock version: 3.1.0
  • AWS JS SDK libs and versions: @aws-sdk/client-secrets-manager v3.535.0
@WtfJoke WtfJoke added the bug Something isn't working label Mar 22, 2024
@WtfJoke WtfJoke changed the title 3.1.0 / 4.0.0 breaks existing test-suite/build 3.1.0 / 4.0.0 breaks existing test-suite/build with Invalid Chai property: toHaveReceivedCommandWith Mar 22, 2024
@jurijzahn8019
Copy link
Contributor

Hi,

the expect is supposed to be a global which works with both jest and vitest (if globals: true).

importing it from the transitive dependency breaks functionality with vitest.

@m-radzikowski
Copy link
Owner

I'm sorry for the problem and unexpected breaking change. However, the aws-sdk-client-mock-jest package was created with Jest in mind, and the ability to use it with Vitest as-is was not a nice addition (see #139).

You are right that the breaking change is #198, which adds an explicit dependency on the expect. This was done to accommodate Jest with and without using globals (#180).

That being said, I would love to support Vitest properly, including unit tests not to break anything in the future. I found a similar case in testing-library/jest-dom#511. Their solution provides three different imports for Jest and Vitest:

import '@testing-library/jest-dom'; // default for Jest
import '@testing-library/jest-dom/jest-globals'; // for Jest using @jest/globals
import '@testing-library/jest-dom/vitest'; // for Vitest

and I think something similar could be done here. We have the current import for Jest:

import 'aws-sdk-client-mock-jest';

and a separate one could be created for Vitest:

import 'aws-sdk-client-mock-jest/vitest';

If someone is willing to give it a try and make a PR - I would be glad to review it. Otherwise, I can't commit to any specific timeline from myself.

@WtfJoke WtfJoke changed the title 3.1.0 / 4.0.0 breaks existing test-suite/build with Invalid Chai property: toHaveReceivedCommandWith 3.1.0 / 4.0.0 breaks existing test-suite/build with Invalid Chai property: toHaveReceivedCommandWith on vitest Mar 25, 2024
@rehos
Copy link

rehos commented Apr 10, 2024

While migrating from jest to vitest also stumbled upon this issue. I was able to resolve this by replacing aws-sdk-client-mock-jest with aws-sdk-client-mock-vitest

@m-radzikowski m-radzikowski added the help wanted Extra attention is needed label Jun 1, 2024
@m-radzikowski
Copy link
Owner

The latest v4.1.0-beta.0 adds proper support for vitest thanks to @YiCChi

You can test it, I'll release it as a regular version if no one reports any problems.

See https://github.com/m-radzikowski/aws-sdk-client-mock?tab=readme-ov-file#vitest for instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants