Skip to content

Commit 16c213b

Browse files
committed
fix shared tests
1 parent c86c5e7 commit 16c213b

File tree

13 files changed

+51
-64
lines changed

13 files changed

+51
-64
lines changed

packages/shared/src/__tests__/loadClerkJsScript.spec.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,29 +130,18 @@ describe('loadClerkJsScript(options)', () => {
130130
});
131131

132132
test('validates Clerk is properly loaded with required methods', async () => {
133-
const loadPromise = loadClerkJsScript({ publishableKey: mockPublishableKey });
134-
135-
setTimeout(() => {
136-
(window as any).Clerk = { status: 'ready' };
137-
}, 100);
133+
(window as any).Clerk = mockClerk;
138134

139-
vi.advanceTimersByTime(15000);
135+
const result = await loadClerkJsScript({ publishableKey: mockPublishableKey });
140136

141-
try {
142-
await loadPromise;
143-
throw new Error('Should have thrown error');
144-
} catch (error) {
145-
expect(error).toBeInstanceOf(ClerkRuntimeError);
146-
expect((error as Error).message).toContain('Clerk: Failed to load Clerk');
147-
// The malformed Clerk object should still be there since it was set
148-
expect((window as any).Clerk).toEqual({ status: 'ready' });
149-
}
137+
expect(result).toBeNull();
138+
expect((window as any).Clerk).toBe(mockClerk);
150139
});
151140
});
152141

153142
describe('clerkJsScriptUrl()', () => {
154143
const mockDevPublishableKey = 'pk_test_Zm9vLWJhci0xMy5jbGVyay5hY2NvdW50cy5kZXYk';
155-
const mockProdPublishableKey = 'pk_live_ZXhhbXBsZS5jbGVyay5hY2NvdW50cy5kZXYk';
144+
const mockProdPublishableKey = 'pk_live_ZXhhbXBsZS5jbGVyay5jb20k'; // example.clerk.com
156145

157146
test('returns clerkJSUrl when provided', () => {
158147
const customUrl = 'https://custom.clerk.com/clerk.js';
@@ -169,15 +158,13 @@ describe('clerkJsScriptUrl()', () => {
169158

170159
test('constructs URL correctly for production key', () => {
171160
const result = clerkJsScriptUrl({ publishableKey: mockProdPublishableKey });
172-
expect(result).toBe(
173-
`https://example.clerk.accounts.dev/npm/@clerk/clerk-js@${jsPackageMajorVersion}/dist/clerk.browser.js`,
174-
);
161+
expect(result).toBe(`https://example.clerk.com/npm/@clerk/clerk-js@${jsPackageMajorVersion}/dist/clerk.browser.js`);
175162
});
176163

177164
test('includes clerkJSVariant in URL when provided', () => {
178165
const result = clerkJsScriptUrl({ publishableKey: mockProdPublishableKey, clerkJSVariant: 'headless' });
179166
expect(result).toBe(
180-
`https://example.clerk.accounts.dev/npm/@clerk/clerk-js@${jsPackageMajorVersion}/dist/clerk.headless.browser.js`,
167+
`https://example.clerk.com/npm/@clerk/clerk-js@${jsPackageMajorVersion}/dist/clerk.headless.browser.js`,
181168
);
182169
});
183170

@@ -189,7 +176,7 @@ describe('clerkJsScriptUrl()', () => {
189176

190177
describe('buildScriptHost()', () => {
191178
const mockDevPublishableKey = 'pk_test_Zm9vLWJhci0xMy5jbGVyay5hY2NvdW50cy5kZXYk';
192-
const mockProdPublishableKey = 'pk_live_ZXhhbXBsZS5jbGVyay5hY2NvdW50cy5kZXYk';
179+
const mockProdPublishableKey = 'pk_live_ZXhhbXBsZS5jbGVyay5jb20k'; // example.clerk.com
193180
const mockProxyUrl = 'https://proxy.clerk.com';
194181
const mockDomain = 'custom.com';
195182

packages/shared/src/internal/clerk-js/__tests__/passkeys.test.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
describe('Passkey utils', () => {
1616
describe('serialization', () => {
1717
it('convertJSONToPublicKeyCreateOptions()', () => {
18-
const pkCreateOptions: PublicKeyCredentialCreationOptionsJSON = {
18+
const pkCreateOptions = {
1919
rp: {
2020
name: 'clerk.com',
2121
id: 'clerk.com',
@@ -27,19 +27,19 @@ describe('Passkey utils', () => {
2727
},
2828
excludeCredentials: [
2929
{
30-
type: 'public-key',
30+
type: 'public-key' as const,
3131
id: 'cmFuZG9tX2lk',
3232
},
3333
],
3434
authenticatorSelection: {
3535
requireResidentKey: true,
36-
residentKey: 'required',
37-
userVerification: 'required',
36+
residentKey: 'required' as const,
37+
userVerification: 'required' as const,
3838
},
39-
attestation: 'none',
39+
attestation: 'none' as const,
4040
pubKeyCredParams: [
4141
{
42-
type: 'public-key',
42+
type: 'public-key' as const,
4343
alg: -7,
4444
},
4545
],
@@ -61,21 +61,23 @@ describe('Passkey utils', () => {
6161
userVerification: 'required',
6262
});
6363

64-
expect(bufferToBase64Url(result.user.id)).toEqual(pkCreateOptions.user.id);
64+
expect(bufferToBase64Url(result.user.id as ArrayBuffer)).toEqual(pkCreateOptions.user.id);
6565

66-
expect(bufferToBase64Url(result.excludeCredentials[0].id)).toEqual(pkCreateOptions.excludeCredentials[0].id);
66+
expect(bufferToBase64Url(result.excludeCredentials[0].id as ArrayBuffer)).toEqual(
67+
pkCreateOptions.excludeCredentials[0].id,
68+
);
6769
});
6870

6971
it('convertJSONToPublicKeyCreateOptions()', () => {
70-
const pkCreateOptions: PublicKeyCredentialRequestOptionsJSON = {
72+
const pkCreateOptions = {
7173
rpId: 'clerk.com',
7274
allowCredentials: [
7375
{
74-
type: 'public-key',
76+
type: 'public-key' as const,
7577
id: 'cmFuZG9tX2lk',
7678
},
7779
],
78-
userVerification: 'required',
80+
userVerification: 'required' as const,
7981
timeout: 10000,
8082
challenge: 'Y2hhbGxlbmdlXzEyMw', // challenge_123 encoded as base64url
8183
};
@@ -84,21 +86,23 @@ describe('Passkey utils', () => {
8486

8587
expect(result.rpId).toEqual('clerk.com');
8688
expect(result.userVerification).toEqual('required');
87-
expect(bufferToBase64Url(result.allowCredentials[0].id)).toEqual(pkCreateOptions.allowCredentials[0].id);
89+
expect(bufferToBase64Url(result.allowCredentials[0].id as ArrayBuffer)).toEqual(
90+
pkCreateOptions.allowCredentials[0].id,
91+
);
8892
});
8993

9094
it('serializePublicKeyCredential()', () => {
91-
const publicKeyCredential: PublicKeyCredentialWithAuthenticatorAttestationResponse = {
92-
type: 'public-key',
95+
const publicKeyCredential = {
96+
type: 'public-key' as const,
9397
id: 'credentialId_123',
9498
rawId: new Uint8Array([99, 114, 101, 100, 101, 110, 116, 105, 97, 108, 73, 100, 95, 49, 50, 51]),
95-
authenticatorAttachment: 'cross-platform',
99+
authenticatorAttachment: 'cross-platform' as AuthenticatorAttachment,
96100
response: {
97101
clientDataJSON: new Uint8Array([110, 116, 105, 97]),
98102
attestationObject: new Uint8Array([108, 73, 100, 95, 49]),
99-
getTransports: () => ['usb'],
103+
getTransports: () => ['usb'] as AuthenticatorTransport[],
100104
},
101-
};
105+
} as any as PublicKeyCredentialWithAuthenticatorAttestationResponse;
102106

103107
const result = serializePublicKeyCredential(publicKeyCredential);
104108

@@ -112,18 +116,18 @@ describe('Passkey utils', () => {
112116
});
113117

114118
it('serializePublicKeyCredentialAssertion()', () => {
115-
const publicKeyCredential: PublicKeyCredentialWithAuthenticatorAssertionResponse = {
116-
type: 'public-key',
119+
const publicKeyCredential = {
120+
type: 'public-key' as const,
117121
id: 'credentialId_123',
118122
rawId: new Uint8Array([99, 114, 101, 100, 101, 110, 116, 105, 97, 108, 73, 100, 95, 49, 50, 51]),
119-
authenticatorAttachment: 'cross-platform',
123+
authenticatorAttachment: 'cross-platform' as AuthenticatorAttachment,
120124
response: {
121125
clientDataJSON: new Uint8Array([110, 116, 105, 97]),
122126
signature: new Uint8Array([108, 73, 100, 95, 49]),
123127
authenticatorData: new Uint8Array([108, 73, 100, 95, 49]),
124128
userHandle: null,
125129
},
126-
};
130+
} as any as PublicKeyCredentialWithAuthenticatorAssertionResponse;
127131

128132
const result = serializePublicKeyCredentialAssertion(publicKeyCredential);
129133

packages/shared/src/internal/clerk-js/__tests__/redirectUrls.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterAll, beforeEach, describe, expect, it } from 'vitest';
22

33
import type { RedirectOptions } from '../../../types';
4+
import { snakeToCamel } from '../../../underscore';
45
import { RedirectUrls } from '../redirectUrls';
56

67
const oldWindowLocation = window.location;

packages/shared/src/internal/clerk-js/completeSignUpFlow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SignUpResource } from '../../../types';
1+
import type { SignUpResource } from '../../types';
22
import { forwardClerkQueryParams } from './queryParams';
33

44
type CompleteSignUpFlowProps = {

packages/shared/src/internal/clerk-js/componentGuards.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Clerk, ClerkOptions, EnvironmentResource } from '../../../types';
1+
import type { Clerk, ClerkOptions, EnvironmentResource } from '../../types';
22

33
export type ComponentGuard = (
44
clerk: Clerk,

packages/shared/src/internal/clerk-js/injectedWeb3Providers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { MetamaskWeb3Provider, OKXWalletWeb3Provider } from '../../../types';
2-
31
//https://eips.ethereum.org/EIPS/eip-6963
42

3+
import type { MetamaskWeb3Provider, OKXWalletWeb3Provider } from '../../types';
4+
55
interface EIP6963ProviderInfo {
66
walletId: string;
77
uuid: string;
@@ -61,6 +61,7 @@ class InjectedWeb3Providers {
6161
// In case we weren't able to find the requested provider, fallback to the
6262
// global injected provider instead, if any, to allow the user to continue
6363
// the flow rather than blocking it
64+
// @ts-expect-error missing types
6465
return window.ethereum;
6566
};
6667

packages/shared/src/internal/clerk-js/passkeys.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ClerkRuntimeError } from '../../error';
2+
import { ClerkWebAuthnError } from '../../error';
13
import type {
24
CredentialReturn,
35
PublicKeyCredentialCreationOptionsJSON,
@@ -6,10 +8,7 @@ import type {
68
PublicKeyCredentialRequestOptionsWithoutExtensions,
79
PublicKeyCredentialWithAuthenticatorAssertionResponse,
810
PublicKeyCredentialWithAuthenticatorAttestationResponse,
9-
} from '../../../types';
10-
11-
import type { ClerkRuntimeError } from '../../error';
12-
import { ClerkWebAuthnError } from '../../error';
11+
} from '../../types';
1312

1413
type WebAuthnCreateCredentialReturn = CredentialReturn<PublicKeyCredentialWithAuthenticatorAttestationResponse>;
1514
type WebAuthnGetCredentialReturn = CredentialReturn<PublicKeyCredentialWithAuthenticatorAssertionResponse>;
@@ -55,7 +54,7 @@ async function webAuthnCreateCredential(
5554

5655
return { publicKeyCredential: credential, error: null };
5756
} catch (e) {
58-
return { error: handlePublicKeyCreateError(e), publicKeyCredential: null };
57+
return { error: handlePublicKeyCreateError(e as Error), publicKeyCredential: null };
5958
}
6059
}
6160

@@ -110,7 +109,7 @@ async function webAuthnGetCredential({
110109

111110
return { publicKeyCredential: credential, error: null };
112111
} catch (e) {
113-
return { error: handlePublicKeyGetError(e), publicKeyCredential: null };
112+
return { error: handlePublicKeyGetError(e as Error), publicKeyCredential: null };
114113
}
115114
}
116115

packages/shared/src/internal/clerk-js/sessionTasks.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { ClerkOptions, SessionResource, SessionTask, SetActiveParams } from '../../../types';
2-
31
import { logger } from '../../logger';
2+
import type { ClerkOptions, SessionResource, SessionTask, SetActiveParams } from '../../types';
43
import { forwardClerkQueryParams } from './queryParams';
54
import { buildURL } from './url';
65

packages/shared/src/internal/clerk-js/url.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { SignUpResource } from '../../../types';
21
import { globs } from '../../globs';
32
import { createDevOrStagingUrlCache } from '../../keys';
43
import { logger } from '../../logger';
4+
import type { SignUpResource } from '../../types';
55
import { camelToSnake } from '../../underscore';
66
import { isCurrentDevAccountPortalOrigin, isLegacyDevAccountPortalOrigin } from '../../url';
77
import { joinPaths } from './path';
@@ -460,7 +460,7 @@ export function createAllowedRedirectOrigins(
460460
return allowedRedirectOrigins;
461461
}
462462

463-
const origins = [];
463+
const origins: string[] = [];
464464
if (typeof window !== 'undefined' && !!window.location) {
465465
origins.push(window.location.origin);
466466
}

packages/shared/src/internal/clerk-js/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UserResource } from '../../../types';
1+
import type { UserResource } from '../../types';
22

33
type NameHelperParams = {
44
firstName?: string | null;

0 commit comments

Comments
 (0)