diff --git a/.changeset/pink-onions-ring.md b/.changeset/pink-onions-ring.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/pink-onions-ring.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/react-router/package.json b/packages/react-router/package.json index 2684e85f95..25a46923ff 100644 --- a/packages/react-router/package.json +++ b/packages/react-router/package.json @@ -68,7 +68,8 @@ "lint": "eslint src/", "lint:attw": "attw --pack . --ignore-rules cjs-resolves-to-esm", "lint:publint": "publint", - "publish:local": "pnpm dlx yalc push --replace --sig" + "publish:local": "pnpm dlx yalc push --replace --sig", + "test": "vitest" }, "dependencies": { "@clerk/backend": "workspace:^", diff --git a/packages/react-router/src/__tests__/__snapshots__/exports.test.ts.snap b/packages/react-router/src/__tests__/__snapshots__/exports.test.ts.snap new file mode 100644 index 0000000000..90b135b14a --- /dev/null +++ b/packages/react-router/src/__tests__/__snapshots__/exports.test.ts.snap @@ -0,0 +1,50 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`root public exports > should not change unexpectedly 1`] = ` +[ + "AuthenticateWithRedirectCallback", + "ClerkLoaded", + "ClerkLoading", + "ClerkProvider", + "CreateOrganization", + "GoogleOneTap", + "OrganizationList", + "OrganizationProfile", + "OrganizationSwitcher", + "Protect", + "RedirectToCreateOrganization", + "RedirectToOrganizationProfile", + "RedirectToSignIn", + "RedirectToSignUp", + "RedirectToUserProfile", + "SignIn", + "SignInButton", + "SignInWithMetamaskButton", + "SignOutButton", + "SignUp", + "SignUpButton", + "SignedIn", + "SignedOut", + "UserButton", + "UserProfile", + "Waitlist", + "useAuth", + "useClerk", + "useEmailLink", + "useOrganization", + "useOrganizationList", + "useReverification", + "useSession", + "useSessionList", + "useSignIn", + "useSignUp", + "useUser", +] +`; + +exports[`ssr public exports > should not change unexpectedly 1`] = ` +[ + "getAuth", + "rootAuthLoader", +] +`; diff --git a/packages/react-router/src/__tests__/exports.test.ts b/packages/react-router/src/__tests__/exports.test.ts new file mode 100644 index 0000000000..4bba4ec227 --- /dev/null +++ b/packages/react-router/src/__tests__/exports.test.ts @@ -0,0 +1,14 @@ +import * as publicExports from '../index'; +import * as ssrExports from '../ssr/index'; + +describe('root public exports', () => { + it('should not change unexpectedly', () => { + expect(Object.keys(publicExports).sort()).toMatchSnapshot(); + }); +}); + +describe('ssr public exports', () => { + it('should not change unexpectedly', () => { + expect(Object.keys(ssrExports).sort()).toMatchSnapshot(); + }); +}); diff --git a/packages/react-router/src/utils/__tests__/assert.test.ts b/packages/react-router/src/utils/__tests__/assert.test.ts new file mode 100644 index 0000000000..931f362299 --- /dev/null +++ b/packages/react-router/src/utils/__tests__/assert.test.ts @@ -0,0 +1,38 @@ +/* eslint-disable no-global-assign */ +import { isSpaMode } from '../assert'; + +describe('isSpaMode', () => { + const currentWindow = window; + + afterEach(() => { + window = currentWindow; + }); + + it('should return undefined when window is undefined', () => { + expect(isSpaMode()).toBeUndefined(); + }); + + it('should return undefined when window.__reactRouterContext is undefined', () => { + // @ts-expect-error - Tests + window = { __reactRouterContext: undefined }; + expect(isSpaMode()).toBeUndefined(); + }); + + it('should return undefined when window.__reactRouterContext.isSpaMode is undefined', () => { + // @ts-expect-error - Tests + window = { __reactRouterContext: { isSpaMode: undefined } }; + expect(isSpaMode()).toBeUndefined(); + }); + + it('should return true when window.__reactRouterContext.isSpaMode is true', () => { + // @ts-expect-error - Tests + window = { __reactRouterContext: { isSpaMode: true } }; + expect(isSpaMode()).toBe(true); + }); + + it('should return false when window.__reactRouterContext.isSpaMode is false', () => { + // @ts-expect-error - Tests + window = { __reactRouterContext: { isSpaMode: false } }; + expect(isSpaMode()).toBe(false); + }); +}); diff --git a/packages/react-router/vitest.config.mts b/packages/react-router/vitest.config.mts new file mode 100644 index 0000000000..5fcd8bde40 --- /dev/null +++ b/packages/react-router/vitest.config.mts @@ -0,0 +1,9 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + globals: true, + environment: 'jsdom', + setupFiles: './vitest.setup.mts', + }, +}); diff --git a/packages/react-router/vitest.setup.mts b/packages/react-router/vitest.setup.mts new file mode 100644 index 0000000000..2c3b51d11f --- /dev/null +++ b/packages/react-router/vitest.setup.mts @@ -0,0 +1,3 @@ +globalThis.__DEV__ = true; +globalThis.PACKAGE_NAME = '@clerk/react-router'; +globalThis.PACKAGE_VERSION = '0.0.0-test';