Skip to content
Open
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: 2 additions & 0 deletions .changeset/backend-drop-miniflare-test-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"@types/react": "catalog:react",
"@types/react-dom": "catalog:react",
"@vitejs/plugin-react": "^4.5.2",
"@vitest/coverage-v8": "3.2.4",
"@vitest/coverage-v8": "4.1.5",
"chalk": "4.1.2",
"citty": "^0.1.6",
"conventional-changelog-conventionalcommits": "^4.6.3",
Expand Down Expand Up @@ -147,7 +147,7 @@
"typescript": "catalog:repo",
"typescript-eslint": "8.58.0",
"uuid": "8.3.2",
"vitest": "3.2.4",
"vitest": "4.1.5",
"zx": "catalog:repo"
},
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319",
Expand Down
9 changes: 3 additions & 6 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@
"lint": "eslint src",
"lint:attw": "attw --pack . --profile node16 --ignore-rules false-cjs",
"lint:publint": "publint",
"test": "run-s test:node test:edge-runtime test:cloudflare-miniflare",
"test:cloudflare-miniflare": "vitest run --environment miniflare",
"test": "run-s test:node test:edge-runtime",
"test:edge-runtime": "vitest run --environment edge-runtime",
"test:node": "vitest run --environment node",
"test:watch": "run-s test:watch:node test:watch:edge-runtime test:watch:cloudflare-miniflare",
"test:watch:cloudflare-miniflare": "vitest watch --environment miniflare",
"test:watch": "run-s test:watch:node test:watch:edge-runtime",
"test:watch:edge-runtime": "vitest watch --environment edge-runtime",
"test:watch:node": "vitest watch --environment node"
},
Expand All @@ -128,8 +126,7 @@
"cookie": "1.0.2",
"msw": "2.11.6",
"npm-run-all": "^4.1.5",
"snakecase-keys": "9.0.2",
"vitest-environment-miniflare": "2.14.4"
"snakecase-keys": "9.0.2"
},
"engines": {
"node": ">=20.9.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/api/endpoints/JwtTemplatesApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ClerkPaginationRequest } from '@clerk/shared/types';
import { joinPaths } from 'src/util/path';

import { joinPaths } from '../../util/path';
import type { DeletedObject, JwtTemplate } from '../resources';
import type { PaginatedResourceResponse } from '../resources/Deserializer';
import { AbstractAPI } from './AbstractApi';
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/api/endpoints/WaitlistEntryApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ClerkPaginationRequest } from '@clerk/shared/types';
import { joinPaths } from 'src/util/path';

import { joinPaths } from '../../util/path';
import type { DeletedObject } from '../resources/DeletedObject';
import type { PaginatedResourceResponse } from '../resources/Deserializer';
import type { WaitlistEntryStatus } from '../resources/Enums';
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getEnvVariable } from '@clerk/shared/getEnvVariable';
import { errorThrower } from 'src/util/shared';
import { Webhook } from 'standardwebhooks';

import type { WebhookEvent } from './api/resources/Webhooks';
import { errorThrower } from './util/shared';

/**
* @inline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('StorageCache', () => {
describe('get', () => {
afterEach(() => {
vi.restoreAllMocks();
vi.mocked(browser.storage.local.get).mockClear();
});

test('value missing', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const mockLoad = vi.fn().mockResolvedValue(undefined);
const mockUi = { __brand: 'clerk-ui', ClerkUI: vi.fn() };

vi.mock('@clerk/clerk-js/no-rhc', () => {
const Clerk = vi.fn(() => ({
load: mockLoad,
})) as ReturnType<typeof vi.fn> & { sdkMetadata: Record<string, string> };
const Clerk = vi.fn(function () {
return { load: mockLoad };
}) as ReturnType<typeof vi.fn> & { sdkMetadata: Record<string, string> };
Clerk.sdkMetadata = {};
return { Clerk };
});
Expand Down
12 changes: 9 additions & 3 deletions packages/clerk-js/src/core/__tests__/clerk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,9 @@ describe('Clerk singleton', () => {

it('uses ui.ClerkUI when provided', async () => {
const mockClerkUIInstance = { mount: vi.fn() };
const mockClerkUICtor = vi.fn(() => mockClerkUIInstance);
const mockClerkUICtor = vi.fn(function () {
return mockClerkUIInstance;
});

const sut = new Clerk(productionPublishableKey);
await sut.load({
Expand All @@ -2975,7 +2977,9 @@ describe('Clerk singleton', () => {

it('supports legacy clerkUICtor option for backwards compatibility', async () => {
const mockClerkUIInstance = { mount: vi.fn() };
const mockClerkUICtor = vi.fn(() => mockClerkUIInstance);
const mockClerkUICtor = vi.fn(function () {
return mockClerkUIInstance;
});

const sut = new Clerk(productionPublishableKey);
await sut.load({
Expand All @@ -2988,7 +2992,9 @@ describe('Clerk singleton', () => {

it('supports legacy clerkUiCtor option for backwards compatibility', async () => {
const mockClerkUIInstance = { mount: vi.fn() };
const mockClerkUICtor = vi.fn(() => mockClerkUIInstance);
const mockClerkUICtor = vi.fn(function () {
return mockClerkUIInstance;
});

const sut = new Clerk(productionPublishableKey);
await sut.load({
Expand Down
4 changes: 3 additions & 1 deletion packages/clerk-js/src/core/__tests__/tokenCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ describe('SessionTokenCache', () => {
SessionTokenCache.close();

// Now mock BroadcastChannel so next initialization uses the mock
global.BroadcastChannel = vi.fn(() => mockBroadcastChannel) as any;
global.BroadcastChannel = vi.fn(function () {
return mockBroadcastChannel;
}) as any;

SessionTokenCache.clear();

Expand Down
14 changes: 8 additions & 6 deletions packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import { _futureAuthenticateWithPopup } from '../../../utils/authenticateWithPop

// Mock the CaptchaChallenge module
vi.mock('../../../utils/captcha/CaptchaChallenge', () => ({
CaptchaChallenge: vi.fn().mockImplementation(() => ({
managedOrInvisible: vi.fn().mockResolvedValue({
captchaToken: 'mock_captcha_token',
captchaWidgetType: 'invisible',
}),
})),
CaptchaChallenge: vi.fn().mockImplementation(function () {
return {
managedOrInvisible: vi.fn().mockResolvedValue({
captchaToken: 'mock_captcha_token',
captchaWidgetType: 'invisible',
}),
};
}),
}));

describe('SignIn', () => {
Expand Down
14 changes: 8 additions & 6 deletions packages/clerk-js/src/core/resources/__tests__/SignUp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import { CaptchaChallenge } from '../../../utils/captcha/CaptchaChallenge';

// Mock the CaptchaChallenge module
vi.mock('../../../utils/captcha/CaptchaChallenge', () => ({
CaptchaChallenge: vi.fn().mockImplementation(() => ({
managedOrInvisible: vi.fn().mockResolvedValue({
captchaToken: 'mock_token',
captchaWidgetType: 'invisible',
}),
})),
CaptchaChallenge: vi.fn().mockImplementation(function () {
return {
managedOrInvisible: vi.fn().mockResolvedValue({
captchaToken: 'mock_token',
captchaWidgetType: 'invisible',
}),
};
}),
}));

describe('SignUp', () => {
Expand Down
22 changes: 13 additions & 9 deletions packages/clerk-js/vitest.setup.mts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ if (typeof window !== 'undefined') {
// Mock ResizeObserver
window.ResizeObserver =
window.ResizeObserver ||
vi.fn().mockImplementation(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
unobserve: vi.fn(),
}));
(vi.fn().mockImplementation(function () {
return {
disconnect: vi.fn(),
observe: vi.fn(),
unobserve: vi.fn(),
};
}) as unknown as typeof ResizeObserver);

// Mock matchMedia
Object.defineProperty(window, 'matchMedia', {
Expand Down Expand Up @@ -278,10 +280,12 @@ vi.mock('@formkit/auto-animate', () => ({
// Mock browser-tabs-lock to prevent window access errors in tests
vi.mock('browser-tabs-lock', () => {
return {
default: vi.fn().mockImplementation(() => ({
acquireLock: vi.fn().mockResolvedValue(true),
releaseLock: vi.fn().mockResolvedValue(true),
})),
default: vi.fn().mockImplementation(function () {
return {
acquireLock: vi.fn().mockResolvedValue(true),
releaseLock: vi.fn().mockResolvedValue(true),
};
}),
};
});

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,3 @@ exports[`constants > from environment variables 1`] = `
"SECRET_KEY": "TEST_SECRET_KEY",
}
`;

exports[`constants from environment variables 1`] = `
{
"API_URL": "CLERK_API_URL",
"API_VERSION": "CLERK_API_VERSION",
"JWT_KEY": "CLERK_JWT_KEY",
"PUBLISHABLE_KEY": "CLERK_PUBLISHABLE_KEY",
"SDK_METADATA": {
"environment": "test",
"name": "@clerk/fastify",
"version": "0.0.0-test",
},
"SECRET_KEY": "CLERK_SECRET_KEY",
}
`;
14 changes: 0 additions & 14 deletions packages/fastify/src/__tests__/__snapshots__/getAuth.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,3 @@ For more info, check out the docs: https://clerk.com/docs,
or come say hi in our discord server: https://clerk.com/discord
]
`;

exports[`getAuth(req) throws error if clerkPlugin is on registered 1`] = `
"🔒 Clerk: The "clerkPlugin" should be registered before using the "getAuth".
Example:

import { clerkPlugin } from '@clerk/fastify';

const server: FastifyInstance = Fastify({ logger: true });
server.register(clerkPlugin);

For more info, check out the docs: https://clerk.com/docs,
or come say hi in our discord server: https://clerk.com/discord
"
`;
4 changes: 3 additions & 1 deletion packages/react/src/__tests__/isomorphicClerk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ describe('isomorphicClerk', () => {
load: vi.fn().mockResolvedValue(undefined),
loaded: false,
};
const mockClerkCtor = vi.fn().mockImplementation(() => mockInstance);
const mockClerkCtor = vi.fn().mockImplementation(function () {
return mockInstance;
});
mockClerkCtor.prototype = {};

const clerk = new IsomorphicClerk({
Expand Down
1 change: 1 addition & 0 deletions packages/testing/src/common/__tests__/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('fetchWithRetry (via fetchEnvVars)', () => {
const mockCreateTestingToken = vi.fn();

beforeEach(() => {
mockCreateTestingToken.mockReset();
vi.useFakeTimers();
vi.stubEnv('CLERK_PUBLISHABLE_KEY', 'pk_test_abc');
vi.stubEnv('CLERK_SECRET_KEY', 'sk_test_abc');
Expand Down
Loading
Loading