Skip to content

Commit a6cd6f3

Browse files
authored
chore(repo): Switch Express unit tests to Vitest (#6413)
1 parent af615b8 commit a6cd6f3

File tree

11 files changed

+55
-40
lines changed

11 files changed

+55
-40
lines changed

.changeset/twelve-rocks-refuse.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/express/jest.config.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/express/jest.setup.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/express/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@
6363
"lint:attw": "attw --pack . --profile node16",
6464
"lint:publint": "publint",
6565
"publish:local": "pnpm yalc push --replace --sig",
66-
"test": "jest",
67-
"test:cache:clear": "jest --clearCache --useStderr",
68-
"test:ci": "jest --maxWorkers=70%"
66+
"test": "vitest run",
67+
"test:watch": "vitest watch"
6968
},
7069
"dependencies": {
7170
"@clerk/backend": "workspace:^",

packages/express/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`module exports > should not change unless explicitly set 1`] = `
4+
[
5+
"authenticateRequest",
6+
"clerkClient",
7+
"clerkMiddleware",
8+
"createClerkClient",
9+
"getAuth",
10+
"requireAuth",
11+
"verifyToken",
12+
]
13+
`;
214

315
exports[`module exports should not change unless explicitly set 1`] = `
416
[

packages/express/src/__tests__/clerkMiddleware.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Request, RequestHandler, Response } from 'express';
2+
import { vi } from 'vitest';
23

34
import { clerkMiddleware } from '../clerkMiddleware';
45
import { getAuth } from '../getAuth';
@@ -121,7 +122,7 @@ describe('clerkMiddleware', () => {
121122
headers: { host: 'example.com' },
122123
} as Request;
123124
const res = {} as Response;
124-
const mockNext = jest.fn();
125+
const mockNext = vi.fn();
125126

126127
clerkMiddleware()(req, res, mockNext);
127128

packages/express/src/__tests__/helpers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { AuthObject } from '@clerk/backend';
22
import type { Application, Request as ExpressRequest, RequestHandler, Response as ExpressResponse } from 'express';
33
import express from 'express';
44
import supertest from 'supertest';
5+
import { vi } from 'vitest';
56

67
import type { ExpressRequestWithAuth } from '../types';
78

@@ -16,9 +17,9 @@ export function runMiddleware(middleware: RequestHandler | RequestHandler[], hea
1617

1718
export function mockResponse(): ExpressResponse {
1819
return {
19-
status: jest.fn().mockReturnThis(),
20-
send: jest.fn().mockReturnThis(),
21-
redirect: jest.fn().mockReturnThis(),
20+
status: vi.fn().mockReturnThis(),
21+
send: vi.fn().mockReturnThis(),
22+
redirect: vi.fn().mockReturnThis(),
2223
} as unknown as ExpressResponse;
2324
}
2425

packages/express/src/__tests__/requireAuth.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import type { RequestHandler } from 'express';
2+
import type { Mock } from 'vitest';
3+
import { vi } from 'vitest';
24

35
import { clerkMiddleware } from '../clerkMiddleware';
46
import { requireAuth } from '../requireAuth';
57
import type { ExpressRequestWithAuth } from '../types';
68
import { mockRequestWithAuth, runMiddleware } from './helpers';
79

8-
let mockAuthenticateAndDecorateRequest: jest.Mock;
9-
let mockAuthenticateRequest: jest.Mock;
10+
let mockAuthenticateAndDecorateRequest: Mock;
11+
let mockAuthenticateRequest: Mock;
1012

11-
jest.mock('../authenticateRequest', () => ({
13+
vi.mock('../authenticateRequest', () => ({
1214
authenticateAndDecorateRequest: (options = {}) => mockAuthenticateAndDecorateRequest(options),
1315
authenticateRequest: (options = {}) => mockAuthenticateRequest(options),
1416
}));
1517

1618
describe('requireAuth', () => {
1719
beforeEach(() => {
18-
mockAuthenticateAndDecorateRequest = jest.fn();
19-
mockAuthenticateRequest = jest.fn();
20-
jest.clearAllMocks();
20+
vi.clearAllMocks();
21+
mockAuthenticateAndDecorateRequest = vi.fn();
22+
mockAuthenticateRequest = vi.fn();
2123
});
2224

2325
it('should redirect to sign-in page when user is not authenticated', async () => {

packages/express/tsconfig.test.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/express/vitest.config.mts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
plugins: [],
5+
test: {
6+
globals: true,
7+
coverage: {
8+
provider: 'v8',
9+
enabled: true,
10+
reporter: ['text', 'json', 'html'],
11+
},
12+
env: {
13+
CLERK_SECRET_KEY: 'sk_test_....',
14+
CLERK_PUBLISHABLE_KEY: 'pk_test_Y2xlcmsuaW5jbHVkZWQua2F0eWRpZC05Mi5sY2wuZGV2JA',
15+
},
16+
setupFiles: './vitest.setup.mts',
17+
},
18+
});

0 commit comments

Comments
 (0)