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

expect type export broken in 1.0.0 #4273

Closed
6 tasks done
embiem opened this issue Oct 8, 2023 · 10 comments
Closed
6 tasks done

expect type export broken in 1.0.0 #4273

embiem opened this issue Oct 8, 2023 · 10 comments
Labels
p5-urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)

Comments

@embiem
Copy link

embiem commented Oct 8, 2023

Describe the bug

While testing version 1.0.0-beta.1, I now get lots of type errors like:

This expression is not callable. Type 'ExpectStatic' has no call signatures.

And my previous expect.extend call now results in Property 'extend' does not exist on type 'ExpectStatic'.

I am importing expect as usual: import { expect } from 'vitest'.

My previously used vitest version was 0.34.5. There, the ExpectStatic interface in @vitest/expect/dist was:

interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
    <T>(actual: T, message?: string): Assertion<T>;
    unreachable(message?: string): never;
    soft<T>(actual: T, message?: string): Assertion<T>;
    extend(expects: MatchersObject): void;
    assertions(expected: number): void;
    hasAssertions(): void;
    anything(): any;
    any(constructor: unknown): any;
    getState(): MatcherState;
    setState(state: Partial<MatcherState>): void;
    not: AsymmetricMatchersContaining;
}

With the beta version, the type is:

interface ExpectStatic {
    addSnapshotSerializer(plugin: Plugin_2): void;
}

Reproduction

  • have tests using expect api on vitest version 0.34.5
  • update vitest to the 1.0.0 beta version
  • run a typecheck, like tsc

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900K
    Memory: 16.81 GB / 31.79 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.2283.0), Chromium (117.0.2045.47)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vitejs/plugin-react: ^4.1.0 => 4.1.0
    @vitest/coverage-v8: ^1.0.0-beta.1 => 1.0.0-beta.1
    vite: ^4.4.9 => 4.4.9
    vitest: ^1.0.0-beta.1 => 1.0.0-beta.1

Used Package Manager

npm

Validations

@sheremet-va sheremet-va added bug p5-urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) and removed pending triage labels Oct 9, 2023
@Dunqing
Copy link
Member

Dunqing commented Oct 9, 2023

image

Looks like everything is fine, did you try to clean and re-install the node_modules?

@embiem
Copy link
Author

embiem commented Oct 9, 2023

Hmm yes, I tried it also on Ubuntu now with the same problem.

Here is a branch where I just updated the vitest version: https://github.com/embiem/epic-stack/tree/embiem/vitest-v1-update-issue-repro

If you run npm install && npm run typecheck you'll see the type errors.

Looking into node_modules/vitest/dist/reporters-7bd09217.d.ts shows this module declaration:

declare module '@vitest/expect' {
    interface MatcherState {
        environment: VitestEnvironment;
        snapshotState: SnapshotState;
    }
    interface ExpectStatic {
        addSnapshotSerializer(plugin: Plugin_2): void;
    }
    interface Assertion<T> {
        matchSnapshot<U extends {
            [P in keyof T]: any;
        }>(snapshot: Partial<U>, message?: string): void;
        matchSnapshot(message?: string): void;
        toMatchSnapshot<U extends {
            [P in keyof T]: any;
        }>(snapshot: Partial<U>, message?: string): void;
        toMatchSnapshot(message?: string): void;
        toMatchInlineSnapshot<U extends {
            [P in keyof T]: any;
        }>(properties: Partial<U>, snapshot?: string, message?: string): void;
        toMatchInlineSnapshot(snapshot?: string, message?: string): void;
        toThrowErrorMatchingSnapshot(message?: string): void;
        toThrowErrorMatchingInlineSnapshot(snapshot?: string, message?: string): void;
        toMatchFileSnapshot(filepath: string, message?: string): Promise<void>;
    }
}

I can probably look into this on the vitest (specifically @vitest/expect) side later today. Need to get accustomed first as this is my first dive into the vitest codebase.

@sheremet-va
Copy link
Member

sheremet-va commented Oct 9, 2023

shows this module declaration

This just augments types, the types themselves are inside @vitest/expect package which should also be the latest version. Might be a problem with npm package manager specifically

@sheremet-va
Copy link
Member

Looks like everything is fine, did you try to clean and re-install the node_modules?

Did you try npm instead of pnpm?

@embiem
Copy link
Author

embiem commented Oct 9, 2023

I downloaded the tarball from https://registry.npmjs.org/vitest/-/vitest-1.0.0-beta.1.tgz (got this from npm view vitest@1.0.0-beta.1). This includes the incorrect @vitest/expect module types as I posted above.

So it might be build or npm (publish) related.

@sheremet-va
Copy link
Member

This includes the incorrect @vitest/expect module types as I posted above.

These types are correct.

@Dunqing
Copy link
Member

Dunqing commented Oct 10, 2023

Did you try npm instead of pnpm?

I tested it and works fine

@alexhanga
Copy link

Have the same problem with yarn v3 (node-modules linker) setup. 1.0.0-beta.2, TypeScript 5.2.2

@sheremet-va
Copy link
Member

Should probably be fixed by this PR: #4322

You can manually update files to see if it does it for you.

@alexhanga
Copy link

Yes. It works

@sheremet-va sheremet-va removed the bug label Feb 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p5-urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)
Projects
None yet
Development

No branches or pull requests

4 participants