Skip to content

Upgrade to Vitest v3 #2168

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

Merged
merged 6 commits into from
Feb 24, 2025
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"size-limit": "^11.1.6",
"turbo": "^2.3.4",
"typescript": "^5.7.3",
"vitest": "^2.1.8"
"vitest": "^3.0.6"
},
"size-limit": [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"axios": "^1.7.9",
"del-cli": "^5.1.0",
"esbuild": "^0.24.2",
"execa": "^8.0.1",
"execa": "^9.5.2",
"express": "^4.21.2",
"feature-fetch": "^0.0.15",
"node-forge": "^1.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-fetch/test/http-methods/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ describe("TRACE()", () => {
// Node.js does not support TRACE with new Request().
test("(not supported in Node.js)", async () => {
const client = createObservedClient<paths>();
expect(() => client.TRACE("/resources/{id}", { params: { path: { id: 123 } } })).rejects.toThrow();
await expect(() => client.TRACE("/resources/{id}", { params: { path: { id: 123 } } })).rejects.toThrow();
});
});
2 changes: 1 addition & 1 deletion packages/openapi-metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
"devDependencies": {
"@types/node": "^22.10.5",
"@vitest/coverage-v8": "^2.1.8",
"@vitest/coverage-v8": "^3.0.6",
"reflect-metadata": "^0.2.2",
"typescript": "^5.7.2",
"unbuild": "^3.3.1",
Expand Down
6 changes: 4 additions & 2 deletions packages/openapi-react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@
"devDependencies": {
"@tanstack/react-query": "^5.64.2",
"@testing-library/react": "^16.2.0",
"@types/react": "18.3.1",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.4",
"del-cli": "^5.1.0",
"esbuild": "^0.24.2",
"execa": "^8.0.1",
"execa": "^9.5.2",
"msw": "^2.7.0",
"openapi-fetch": "workspace:^",
"openapi-typescript": "workspace:^",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-error-boundary": "^4.1.2"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-react-query/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ describe("client", () => {
wrapper,
});

expect(result.current.mutateAsync({ body: { message: "Hello", replied_at: 0 } })).rejects.toThrow();
await expect(result.current.mutateAsync({ body: { message: "Hello", replied_at: 0 } })).rejects.toThrow();
});

it("should use provided custom queryClient", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"degit": "^2.8.4",
"del-cli": "^5.1.0",
"esbuild": "^0.24.2",
"execa": "^8.0.1",
"execa": "^9.5.2",
"strip-ansi": "^7.1.0",
"typescript": "^5.7.3",
"vite-node": "^2.1.8"
Expand Down
9 changes: 6 additions & 3 deletions packages/openapi-typescript/test/cjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ describe("CJS bundle", () => {
test(
"basic",
async () => {
const contents = astToString(await openapiTS(new URL("../examples/stripe-api.yaml", import.meta.url)));

const output = `/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/

${astToString(await openapiTS(new URL("../examples/stripe-api.yaml", import.meta.url)))}`;
expect(output).toMatchFileSnapshot(fileURLToPath(new URL("../examples/stripe-api.ts", import.meta.url)));
${contents}`;

await expect(output).toMatchFileSnapshot(fileURLToPath(new URL("../examples/stripe-api.ts", import.meta.url)));
},
{ timeout: TIMEOUT },
TIMEOUT,
);
});
15 changes: 8 additions & 7 deletions packages/openapi-typescript/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ describe("CLI", () => {
test.skipIf(ci?.skipIf)(
testName,
async () => {
const { stdout } = await execa(cmd, given, { cwd });
const { stdout } = await execa(cmd, given, { cwd, stripFinalNewline: false });
if (want instanceof URL) {
expect(stdout).toMatchFileSnapshot(fileURLToPath(want));
await expect(stdout).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(stdout).toBe(`${want}\n`);
}
Expand All @@ -97,8 +97,8 @@ describe("CLI", () => {
"stdin",
async () => {
const input = fs.readFileSync(new URL("./examples/stripe-api.yaml", root));
const { stdout } = await execa(cmd, { input, cwd });
expect(stdout).toMatchFileSnapshot(fileURLToPath(new URL("./examples/stripe-api.ts", root)));
const { stdout } = await execa(cmd, { input, cwd, stripFinalNewline: false });
await expect(stdout).toMatchFileSnapshot(fileURLToPath(new URL("./examples/stripe-api.ts", root)));
},
TIMEOUT,
);
Expand All @@ -119,8 +119,9 @@ describe("CLI", () => {
async () => {
const { stdout } = await execa(cmd, ["--properties-required-by-default=true", "./examples/github-api.yaml"], {
cwd,
stripFinalNewline: false,
});
expect(stdout).toMatchFileSnapshot(fileURLToPath(new URL("./examples/github-api-required.ts", root)));
await expect(stdout).toMatchFileSnapshot(fileURLToPath(new URL("./examples/github-api-required.ts", root)));
},
TIMEOUT,
);
Expand All @@ -134,7 +135,7 @@ describe("CLI", () => {
cwd: fileURLToPath(cwd),
});
for (const schema of ["a", "b", "c"]) {
expect(fs.readFileSync(new URL(`./output/${schema}.ts`, cwd), "utf8")).toMatchFileSnapshot(
await expect(fs.readFileSync(new URL(`./output/${schema}.ts`, cwd), "utf8")).toMatchFileSnapshot(
fileURLToPath(new URL("../../../examples/simple-example.ts", cwd)),
);
}
Expand All @@ -145,7 +146,7 @@ describe("CLI", () => {
cwd,
});
for (const schema of ["a", "b", "c"]) {
expect(
await expect(
fs.readFileSync(new URL(`./test/fixtures/redocly-flag/output/${schema}.ts`, root), "utf8"),
).toMatchFileSnapshot(fileURLToPath(new URL("./examples/simple-example.ts", root)));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-typescript/test/discriminators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ export type operations = Record<string, never>;`,
async () => {
const result = astToString(await openapiTS(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-typescript/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ export type operations = Record<string, never>;`,
async () => {
const result = astToString(await openapiTS(given, options));
if (want instanceof URL) {
expect(want).toMatchFileSnapshot(fileURLToPath(want));
await expect(want).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-typescript/test/node-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ export type operations = Record<string, never>;`,
async () => {
const result = astToString(await openapiTS(given, options));
if (want instanceof URL) {
expect(`${COMMENT_HEADER}${result}`).toMatchFileSnapshot(fileURLToPath(want));
await expect(`${COMMENT_HEADER}${result}`).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ export type Error = components['schemas']['Error'];
async () => {
const result = astToString(transformComponentsObject(given, options ?? DEFAULT_OPTIONS));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result.trim()).toBe(want.trim());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("transformHeaderObject", () => {
test.skipIf(ci?.skipIf)(testName, async () => {
const result = astToString(transformHeaderObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ responses: {
async () => {
const result = astToString(transformOperationObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ describe("transformPathItemObject", () => {
async () => {
const result = astToString(transformPathItemObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("transformPathsObjectToEnum", () => {
async () => {
const result = astToString(makeApiPathsEnum(given));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ describe("transformPathsObject", () => {
async () => {
const result = astToString(transformPathsObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe("transformRequestBodyObject", () => {
async () => {
const result = astToString(transformRequestBodyObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("transformResponseObject", () => {
async () => {
const result = astToString(transformResponseObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe("transformSchemaObject > array", () => {
async () => {
const result = astToString(transformSchemaObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("transformSchemaObject > boolean", () => {
async () => {
const result = astToString(transformSchemaObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ describe("composition", () => {
async () => {
const result = astToString(transformSchemaObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("transformSchemaObject > empty/unknown", () => {
async () => {
const result = astToString(transformSchemaObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("transformSchemaObject > number", () => {
async () => {
const result = astToString(transformSchemaObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ describe("transformSchemaObject > object", () => {
async () => {
const result = astToString(transformSchemaObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe("transformSchemaObject > string", () => {
async () => {
const result = astToString(transformSchemaObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
Copy link
Contributor

Choose a reason for hiding this comment

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

Love all these cleanups. The test output had quite a lot of unnecessary warnings.

Does this PR clean up all of them? If so, it would be pretty great to switch these from warnings to errors in the vitest config to prevent new ones from sneaking in.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd be glad to make these errors, but I'm not finding a relevant Vitest config option to do that. If you know of one, would you mind sharing a link to its docs?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to merge for now, but am happy to add additional rules once we find them!

Copy link
Contributor

Choose a reason for hiding this comment

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

The way I typically handle this isn't in vitest, but with the no-floating-promises typescript-eslint rule.

} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe("transformWebhooksObject", () => {
async () => {
const result = astToString(transformWebhooksObject(given, options));
if (want instanceof URL) {
expect(result).toMatchFileSnapshot(fileURLToPath(want));
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
} else {
expect(result).toBe(`${want}\n`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/openapi-typescript/test/yaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface operations {
};
}`);
},
{ timeout: TIMEOUT },
TIMEOUT,
);

test(
Expand Down Expand Up @@ -174,6 +174,6 @@ export interface operations {
};
}`);
},
{ timeout: TIMEOUT },
TIMEOUT,
);
});
1 change: 1 addition & 0 deletions packages/swr-openapi/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

/* If transpiling with TypeScript: */
"module": "NodeNext",
"moduleResolution": "nodenext",
// "outDir": "dist",
// "rootDir": "src",
"sourceMap": true,
Expand Down
Loading