Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core-generators/src/constants/core-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const CORE_PACKAGES = {
'prettier-plugin-packagejson': '2.5.19',

// Testing
vitest: '3.0.7',
vitest: '3.2.4',
'vite-tsconfig-paths': '5.1.4',

// Utils
Expand Down
18 changes: 7 additions & 11 deletions packages/sync/src/generators/generators.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { describe, expect, expectTypeOf, it } from 'vitest';

import type { GeneratorTaskOutputBuilder } from '#src/output/generator-task-output.js';

import { createProviderType } from '#src/providers/index.js';

import type {
InferDependencyProviderMap,
InferExportProviderMap,
ProviderDependencyMap,
ProviderExportMap,
} from './generators.js';

Expand All @@ -29,23 +28,23 @@ describe('generators type definitions', () => {
}>;

// Test ProviderDependencyMap
interface TestDependencyMap {
type TestDependencyMap = ProviderDependencyMap<{
test: TestProvider;
config: ConfigProvider;
}
}>;

// Test InferExportProviderMap
type InferredExportMap = InferExportProviderMap<TestExportMap>;
expectTypeOf<InferredExportMap>().toMatchTypeOf<{
expectTypeOf<InferredExportMap>().toMatchObjectType<{
test: TestProvider;
config: ConfigProvider;
}>();
Comment on lines +38 to 41
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the vitest API change for type assertions.

The change from toMatchTypeOf to toMatchObjectType appears to be related to the vitest upgrade. Please ensure this is the correct API method in vitest 3.2.4.


🌐 Web query:

What are the correct type assertion methods in vitest 3.2.4 for TypeScript type testing?

💡 Result:

In Vitest 3.2.4, you can perform TypeScript type assertions using the following methods:

  1. expectTypeOf: This function allows you to assert the type of a value.

    • Usage:

      import { expectTypeOf } from 'vitest';
      
      expectTypeOf(value).toEqualTypeOf<ExpectedType>();
      expectTypeOf(value).toMatchTypeOf<ExpectedType>();
    • Matchers:

      • toEqualTypeOf: Asserts that the value's type is exactly equal to the expected type.
      • toMatchTypeOf: Asserts that the value's type matches the expected type, allowing for structural compatibility.
    • Example:

      import { expectTypeOf } from 'vitest';
      
      const num = 42;
      expectTypeOf(num).toEqualTypeOf<number>();
      expectTypeOf(num).toMatchTypeOf<number | string>();

    (vitest.dev)

  2. assertType: This function is used to assert that a value matches a specific type.

    • Usage:

      import { assertType } from 'vitest';
      
      assertType<ExpectedType>(value);
    • Example:

      import { assertType } from 'vitest';
      
      const str = 'Hello, world!';
      assertType<string>(str);

    (v0.vitest.dev)

To enable type checking during your tests, ensure you run Vitest with the --typecheck flag:

vitest --typecheck

This setup will allow you to perform type assertions effectively in your TypeScript tests using Vitest.

Citations:


Fix incorrect Vitest matcher in type assertion

Vitest 3.2.4’s expectTypeOf API does not include toMatchObjectType. To assert structural compatibility, use toMatchTypeOf (or toEqualTypeOf for exact matches).

• File: packages/sync/src/generators/generators.unit.test.ts
Lines 38–41:

- expectTypeOf<InferredExportMap>().toMatchObjectType<{
-   test: TestProvider;
-   config: ConfigProvider;
- }>();
+ expectTypeOf<InferredExportMap>().toMatchTypeOf<{
+   test: TestProvider;
+   config: ConfigProvider;
+ }>();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expectTypeOf<InferredExportMap>().toMatchObjectType<{
test: TestProvider;
config: ConfigProvider;
}>();
expectTypeOf<InferredExportMap>().toMatchTypeOf<{
test: TestProvider;
config: ConfigProvider;
}>();
🤖 Prompt for AI Agents
In packages/sync/src/generators/generators.unit.test.ts at lines 38 to 41,
replace the incorrect Vitest matcher `toMatchObjectType` with the correct
matcher `toMatchTypeOf` to properly assert structural compatibility using the
`expectTypeOf` API.


// Test InferDependencyProviderMap
type InferredDependencyMap = InferDependencyProviderMap<TestDependencyMap>;
expectTypeOf<InferredDependencyMap>().toMatchTypeOf<{
test: TestProvider;
config: ConfigProvider;
expectTypeOf<InferredDependencyMap>().toMatchObjectType<{
test: TestProvider | undefined;
config: ConfigProvider | undefined;
}>();
});

Expand All @@ -55,9 +54,6 @@ describe('generators type definitions', () => {
run: () => ({}),
});

expectTypeOf<ReturnType<(typeof taskOutput)['run']>>().toMatchTypeOf<{
build?: (builder: GeneratorTaskOutputBuilder) => Promise<void> | void;
}>();
expect(taskOutput).toBeDefined();
});

Expand Down
Loading
Loading