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

instanceof checks are failing after updating to the latest version #3676

Closed
6 tasks done
gajus opened this issue Jun 26, 2023 · 14 comments
Closed
6 tasks done

instanceof checks are failing after updating to the latest version #3676

gajus opened this issue Jun 26, 2023 · 14 comments

Comments

@gajus
Copy link

gajus commented Jun 26, 2023

Describe the bug

After updating to the latest version, our instanceof checks started to fail, e.g.

expect(
  services.paidProjectAnalytics.logFirstPaymentReceivedEvent,
).toHaveBeenCalledWith({
  paidProjectId,
  paidProjectTerms: expect.any(PaidProjectTerms),
});

While previously this was working, now it is failing with:

-     "paidProjectTerms": Any<PaidProjectTerms>,
+     "paidProjectTerms": PaidProjectTerms {

From the error it seems like they both share the same constructor.

However, checking the referenced object indeed confirms that the property is not an instance of PaidProjectTerms.

services.paidProjectAnalytics.logFirstPaymentReceivedEvent.mock
          .calls[0][0].paidProjectTerms instanceof PaidProjectTerms
// false
console.log(
  '>>>',
  services.paidProjectAnalytics.logFirstPaymentReceivedEvent.mock
    .calls[0][0].paidProjectTerms.constructor,
  services.paidProjectAnalytics.logFirstPaymentReceivedEvent.mock
    .calls[0][0].paidProjectTerms.constructor instanceof PaidProjectTerms,
  PaidProjectTerms,
  services.paidProjectAnalytics.logFirstPaymentReceivedEvent.mock
    .calls[0][0].paidProjectTerms.constructor === PaidProjectTerms,
);
// >>> [class PaidProjectTerms] false [class PaidProjectTerms] false

Reproduction

I am unclear as to how to debug this further or how to reproduce it in isolation.

System Info

System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.05 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.9.0 - ~/.nvm/versions/node/v19.9.0/bin/node
    npm: 9.6.3 - ~/.nvm/versions/node/v19.9.0/bin/npm
    Watchman: 2023.06.08.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 114.0.5735.133
    Edge: 114.0.1823.43
    Firefox: 113.0.2
    Safari: 16.3


  System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.01 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.9.0 - ~/.nvm/versions/node/v19.9.0/bin/node
    npm: 9.6.3 - ~/.nvm/versions/node/v19.9.0/bin/npm
    Watchman: 2023.06.08.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 114.0.5735.133
    Edge: 114.0.1823.43
    Firefox: 113.0.2
    Safari: 16.3
  npmPackages:
    vitest: ^0.32.2 => 0.32.2

Used Package Manager

npm

Validations

@gajus
Copy link
Author

gajus commented Jun 26, 2023

This does have a smell of #2824

devDependencies:
vitest 0.32.2
├─┬ @vitest/expect 0.32.2
│ └─┬ @vitest/spy 0.32.2
│   └── tinyspy 2.1.1
└─┬ @vitest/spy 0.32.2
  └── tinyspy 2.1.1
vitest-mock-extended 1.1.3
└─┬ vitest 0.32.2 peer
  ├─┬ @vitest/expect 0.32.2
  │ └─┬ @vitest/spy 0.32.2
  │   └── tinyspy 2.1.1
  └─┬ @vitest/spy 0.32.2
    └── tinyspy 2.1.1

CC @sheremet-va

@sheremet-va
Copy link
Member

sheremet-va commented Jun 27, 2023

And why does it use different dependencies there? 🤷🏻 Maybe deleting/reinstalling helps? Or lockfile is wrong?

@github-actions
Copy link

Hello @gajus. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@gajus
Copy link
Author

gajus commented Jun 27, 2023

And why does it use different dependencies there? 🤷🏻 Maybe deleting/reinstalling helps? Or lockfile is wrong?

Where do you see different dependencies?

As far as I can tell, they are all the same version.

@gajus
Copy link
Author

gajus commented Jun 27, 2023

I don't see how to repro this in StackBlitz.

@gajus gajus closed this as completed Jun 27, 2023
@sheremet-va
Copy link
Member

You don't have to use stackblitz

@gajus
Copy link
Author

gajus commented Jun 27, 2023

The last working version is v0.31.1. It breaks in v0.31.2.

Tagging contributors to v0.31.2

@ghiscoding @PCreations @jcbhmr @fenghan34 @gtm-nayan @ghry5 @dammy001 @Dunqing @fooddilsn @rxliuli @btea @rluvaton @sheremet-va @AriPerkkio

Trying to look at what changed in the code between those versions.

@gajus gajus reopened this Jun 27, 2023
@gajus
Copy link
Author

gajus commented Jun 27, 2023

It is definitely vitest related change. I removed all other changes from our PR and isolated just to dependency update, and it breaks all instanceof checks.

@sheremet-va
Copy link
Member

Please, provide reproduction.

@gajus
Copy link
Author

gajus commented Jun 27, 2023

Pretty sure it is going to be this PR #3446 That's a breaking change

@gajus
Copy link
Author

gajus commented Jun 27, 2023

Indeed it was. Undoing these configs fixes the issue.

@sheremet-va
Copy link
Member

Please, provide a reproduction.

@gajus
Copy link
Author

gajus commented Jun 27, 2023

I am not going to provide a reproduction, but please add a note to the release log that this is a breaking change.

@gajus gajus closed this as completed Jun 27, 2023
@gajus
Copy link
Author

gajus commented Jun 27, 2023

Just for added context, this is a breaking change in monorepos where your directory structure is something like:

./apps/...
./packages/...

@github-actions github-actions bot locked and limited conversation to collaborators Jul 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants