-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Broken types for extended test context #6660
Comments
Looks like it fails even with a regular it.extend<{ userId: number }>({ userId: 100 }).each([null, undefined])('test', async (_initialState) => {
//
})
it.for([null, undefined])('test', async (_initialState) => {
//
})
it.each([null, undefined])('test', async (_initialState) => {
//
}) Seems like it.each([100, undefined]).each('test', value => {
// vlaue is a "number"
}) |
We do have errors reported even when it.each(["Wait", "WaitForProceed"] as const)("deals with wait state %s", async (state) => {
// tsc -b reports error TS7006: Parameter 'state' implicitly has an 'any' type.
}); But it only does this in the application projects importing the test context from the shared code, not within the shared code, so I'm not sure if there's some interaction with using TypeScript's paths/references to get to the context? The application projects still reference the same version of Vitest. If I write a basic test: import { customTest as it } from "@shared/_test/testUtils";
it.each(["foo", "bar", "baz"])("tests string %s", (str) => {
expect(str).toHaveLength(3);
}); it reports a compiler error, but if I comment out the import so we use the default |
Okay I may have a lead: the shared code generates a export declare const customTest: import("@vitest/runner").CustomAPI<{
user: UserEvent;
}>; We don't have a reference to |
Confirmed that adding a package reference to |
There was no breaking change. I don't know why your TypeScript code generates a I generally don't understand why your code is bundled. Vitest is meant to run on unbundled code. |
It's not bundled, the shared code is just run through |
Narrowed it down further: I completely removed the |
Do you have a reproducible repository? Vitest ships the |
@dosolkowski-work Can you check if you don't have multiple versions of vitest installed? That could potentially mess up tsc. You can search |
I can confirm we don't have multiple versions installed (we actually enforce this using syncpack). As part of the upgrade I completely deleted node_modules and the pnpm lockfile, and then reviewed after upgrading, to ensure there wasn't anything strange left over (e.g. It's possible that pnpm is a factor: because it does not include transient dependencies in Correction/further information on my prior comment: the shared code project being compiled to I'll attempt to fork and update the repository I linked to in order to reproduce more clearly, sorry it's taking some time. |
I forked the repository to https://github.com/dosolkowski-work/vite-workspace-experiment and updated it to show the bug and the workaround (before and after the most recent commit). The bug is seen in this workflow run: https://github.com/dosolkowski-work/vite-workspace-experiment/actions/runs/11239311536/job/31246077526 whereas with the workaround, the run is clean: https://github.com/dosolkowski-work/vite-workspace-experiment/actions/runs/11239342625/job/31246177713 The return type of |
Thanks for the repro. It's still hard to believe Vitest would affect this behavior. Can you test how v2.0.5 looks then? Also it would be great if you can strip down the repro further without all those dependencies. If it can be reproduced with just |
I made a separate branch with vitest 2.0.5 for comparison: https://github.com/dosolkowski-work/vite-workspace-experiment/tree/vitest-2.0 In this branch we can see that custom contexts used to depend on export declare const myTest: import("vitest").TestAPI<{
user: UserEvent;
}>; |
The https://www.npmjs.com/package/vitest/v/2.0.5?activeTab=code |
That's not the type that TypeScript thinks is returned by |
Export of - export { CancelReason, DoneCallback, ExtendedContext, HookCleanupCallback, HookListener, OnTestFailedHandler, RunMode, Custom as RunnerCustomCase, Task as RunnerTask, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, RuntimeContext, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, TaskBase, TaskContext, TaskCustomOptions, TaskMeta, TaskResult, TaskResultPack, TaskState, TestAPI, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
+ export { CancelReason, ExtendedContext, HookCleanupCallback, HookListener, OnTestFailedHandler, OnTestFinishedHandler, RunMode, Custom as RunnerCustomCase, Task as RunnerTask, TaskBase as RunnerTaskBase, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SuiteAPI, SuiteCollector, SuiteFactory, TaskContext, TaskCustomOptions, TaskMeta, TaskState, TestAPI, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner'; |
I made a minimal repro here https://github.com/hi-ogawa/reproductions/tree/main/vitest-6660-test-extend-dts Previously |
Describe the bug
When upgrading from vitest 2.0.5 to 2.1.2, something has changed with the types for custom test contexts (
export const myTest = test.extend(...)
) that results intsc
reporting all test function parameters as havingany
type, when it previously used to be able to identify their types. An example error:In this case, it should be able to tell that
initialState
has a type ofnull | undefined
. Vitest was the only library changed, and reverting back to 2.0.5 restores the prior behavior where types were identified correctly.Reproduction
Our repository is set up similar to this arrangement: https://github.com/qidydl/vite-workspace-experiment where we use
paths
andreferences
intsconfig.json
to refer to shared code. The test context in the shared code is not complex:The usage is also not complex:
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: