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

feat(backend): Migrate to vitest #4296

Merged
merged 2 commits into from
Nov 2, 2024
Merged

feat(backend): Migrate to vitest #4296

merged 2 commits into from
Nov 2, 2024

Conversation

jacekradko
Copy link
Member

@jacekradko jacekradko commented Oct 7, 2024

Description

Spiking out vitest test runner as a replacement for qunit in @clerk/backend.

Changes

  • Using vitest runner
  • Using msw instead of mocking fetch

Related: https://linear.app/clerk/issue/SDKI-694/refactor-clerkbackend-to-use-vitest-instead-of-qunit

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Oct 7, 2024

🦋 Changeset detected

Latest commit: 01e60b6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jacekradko jacekradko force-pushed the jacek/backend-vitest branch from d33a518 to c70d74d Compare October 9, 2024 13:56
@@ -88,7 +88,7 @@ export function buildRequest(options: BuildRequestOptions) {
let res: Response | undefined;
try {
if (formData) {
res = await runtime.fetch(finalUrl.href, {
res = await (process.env.NODE_ENV === 'test' ? fetch : runtime.fetch)(finalUrl.href, {
Copy link
Member Author

@jacekradko jacekradko Oct 9, 2024

Choose a reason for hiding this comment

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

Will need to think about a more ergonomic way of accomplishing this. With the way fetch is handled in the package, msw can't intercept requests without it for now

Copy link
Member Author

Choose a reason for hiding this comment

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

@BRKalow Any thoughts on how you would like to move forward here?

Copy link
Member

Choose a reason for hiding this comment

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

@jacekradko can we try to consolidate into the runtime module? so at least usage of runtime.fetch doesn't need to be aware of the NODE_ENV

Comment on lines +25 to +36
{
"name": "Debug Vitest",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/scripts/vitest-debug.mjs",
"args": ["${file}"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"autoAttachChildProcesses": true,
"smartStep": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"]
Copy link
Member Author

Choose a reason for hiding this comment

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

Added a debug configuration for any vitest spec

@jacekradko jacekradko marked this pull request as ready for review October 28, 2024 20:40
@jacekradko jacekradko changed the title feat(backend): vitest feat(backend): Migrate to vitest Oct 29, 2024
Copy link
Member

@BRKalow BRKalow left a comment

Choose a reason for hiding this comment

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

Really nice work! Would be great to shift the NODE_ENV fetch check into the runtime module. Left a few minor questions.

packages/backend/src/__tests__/exports.test.ts Outdated Show resolved Hide resolved
packages/backend/src/api/__tests__/factory.test.ts Outdated Show resolved Hide resolved
packages/backend/src/jwt/__tests__/signJwt.test.ts Outdated Show resolved Hide resolved
packages/backend/src/jwt/__tests__/verifyJwt.test.ts Outdated Show resolved Hide resolved
packages/backend/vitest.setup.mts Outdated Show resolved Hide resolved
Copy link
Member

@BRKalow BRKalow left a comment

Choose a reason for hiding this comment

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

:shipit:

packages/backend/src/api/request.ts Show resolved Hide resolved
packages/backend/src/api/request.ts Show resolved Hide resolved
@jacekradko jacekradko force-pushed the jacek/backend-vitest branch from 5f074a9 to 53f6585 Compare November 1, 2024 23:59
@jacekradko jacekradko merged commit 52dd05f into main Nov 2, 2024
23 checks passed
@jacekradko jacekradko deleted the jacek/backend-vitest branch November 2, 2024 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants