Skip to content

Commit 546e62e

Browse files
committed
chore: fix barrel exports
1 parent 74d109c commit 546e62e

7 files changed

Lines changed: 111 additions & 111 deletions

File tree

integration/testUtils/createTestUtils.ts

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

integration/testUtils/index.ts

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,91 @@
1+
import { createClerkClient as backendCreateClerkClient } from '@clerk/backend';
2+
import { createAppPageObject, createPageObjects, type EnhancedPage } from '@clerk/testing/playwright/unstable';
3+
import type { Browser, BrowserContext, Page } from '@playwright/test';
4+
5+
import type { Application } from '../models/application';
6+
import { createEmailService } from './emailService';
7+
import { createInvitationService } from './invitationsService';
8+
import { createOrganizationsService } from './organizationsService';
9+
import { withRetry } from './retryableClerkClient';
110
import type { FakeAPIKey, FakeOrganization, FakeUser, FakeUserWithEmail } from './usersService';
2-
export type { CreateAppPageObjectArgs } from './createTestUtils';
3-
export { createTestUtils } from './createTestUtils';
11+
import { createUserService } from './usersService';
12+
import { createWaitlistService } from './waitlistService';
413

514
export type { FakeAPIKey, FakeOrganization, FakeUser, FakeUserWithEmail };
6-
export type { FakeMachineNetwork, FakeOAuthApp, MachineAuthTestAdapter } from './machineAuthHelpers';
7-
export {
8-
createFakeMachineNetwork,
9-
createFakeOAuthApp,
10-
createJwtM2MToken,
11-
obtainOAuthAccessToken,
12-
registerApiKeyAuthTests,
13-
registerM2MAuthTests,
14-
registerOAuthAuthTests,
15-
} from './machineAuthHelpers';
15+
16+
const createClerkClient = (app: Application) => {
17+
return backendCreateClerkClient({
18+
apiUrl: app.env.privateVariables.get('CLERK_API_URL'),
19+
secretKey: app.env.privateVariables.get('CLERK_SECRET_KEY'),
20+
publishableKey: app.env.publicVariables.get('CLERK_PUBLISHABLE_KEY'),
21+
});
22+
};
23+
24+
export type CreateAppPageObjectArgs = { page: Page; context: BrowserContext; browser: Browser };
25+
26+
export const createTestUtils = <
27+
Params extends { app: Application; useTestingToken?: boolean } & Partial<CreateAppPageObjectArgs>,
28+
Services = typeof services,
29+
PO = typeof pageObjects,
30+
BH = typeof browserHelpers,
31+
FullReturn = { services: Services; po: PO; tabs: BH; page: EnhancedPage; nextJsVersion: string },
32+
OnlyAppReturn = { services: Services },
33+
>(
34+
params: Params,
35+
): Params extends Partial<CreateAppPageObjectArgs> ? FullReturn : OnlyAppReturn => {
36+
const { app, context, browser, useTestingToken = true } = params || {};
37+
38+
const clerkClient = withRetry(createClerkClient(app));
39+
const services = {
40+
clerk: clerkClient,
41+
email: createEmailService(),
42+
users: createUserService(clerkClient),
43+
invitations: createInvitationService(clerkClient),
44+
organizations: createOrganizationsService(clerkClient),
45+
waitlist: createWaitlistService(clerkClient),
46+
};
47+
48+
if (!params.page) {
49+
return { services } as any;
50+
}
51+
52+
const pageObjects = createPageObjects({ page: params.page, useTestingToken, baseURL: app.serverUrl });
53+
54+
const browserHelpers = {
55+
runInNewTab: async (
56+
cb: (u: { services: Services; po: PO; page: EnhancedPage }, context: BrowserContext) => Promise<unknown>,
57+
) => {
58+
const u = createTestUtils({
59+
app,
60+
page: createAppPageObject({ page: await context.newPage(), useTestingToken }, { baseURL: app.serverUrl }),
61+
});
62+
await cb(u as any, context);
63+
return u;
64+
},
65+
runInNewBrowser: async (
66+
cb: (u: { services: Services; po: PO; page: EnhancedPage }, context: BrowserContext) => Promise<unknown>,
67+
) => {
68+
if (!browser) {
69+
throw new Error('Browser is not defined. Did you forget to pass it to createPageObjects?');
70+
}
71+
const context = await browser.newContext();
72+
const u = createTestUtils({
73+
app,
74+
page: createAppPageObject({ page: await context.newPage(), useTestingToken }, { baseURL: app.serverUrl }),
75+
});
76+
await cb(u as any, context);
77+
return u;
78+
},
79+
};
80+
81+
return {
82+
page: pageObjects.page,
83+
services,
84+
po: pageObjects,
85+
tabs: browserHelpers,
86+
// eslint-disable-next-line turbo/no-undeclared-env-vars
87+
nextJsVersion: process.env.E2E_NEXTJS_VERSION,
88+
} as any;
89+
};
1690

1791
export { testAgainstRunningApps } from './testAgainstRunningApps';

integration/testUtils/machineAuthHelpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import type { ApplicationConfig } from '../models/applicationConfig';
1212
import type { EnvironmentConfig } from '../models/environment';
1313
import { appConfigs } from '../presets';
1414
import { instanceKeys } from '../presets/envs';
15-
import { createTestUtils } from './createTestUtils';
1615
import type { FakeAPIKey, FakeUser } from './usersService';
16+
import { createTestUtils } from './index';
1717

1818
export type FakeMachineNetwork = {
1919
primaryServer: Machine;
@@ -24,7 +24,7 @@ export type FakeMachineNetwork = {
2424
cleanup: () => Promise<void>;
2525
};
2626

27-
export async function createFakeMachineNetwork(clerkClient: ClerkClient): Promise<FakeMachineNetwork> {
27+
async function createFakeMachineNetwork(clerkClient: ClerkClient): Promise<FakeMachineNetwork> {
2828
const fakeCompanyName = faker.company.name();
2929

3030
const primaryServer = await clerkClient.machines.create({
@@ -68,7 +68,7 @@ export async function createFakeMachineNetwork(clerkClient: ClerkClient): Promis
6868
};
6969
}
7070

71-
export async function createJwtM2MToken(clerkClient: ClerkClient, senderSecretKey: string): Promise<M2MToken> {
71+
async function createJwtM2MToken(clerkClient: ClerkClient, senderSecretKey: string): Promise<M2MToken> {
7272
return clerkClient.m2m.createToken({
7373
machineSecretKey: senderSecretKey,
7474
secondsUntilExpiration: 60 * 30,
@@ -81,7 +81,7 @@ export type FakeOAuthApp = {
8181
cleanup: () => Promise<void>;
8282
};
8383

84-
export async function createFakeOAuthApp(clerkClient: ClerkClient, callbackUrl: string): Promise<FakeOAuthApp> {
84+
async function createFakeOAuthApp(clerkClient: ClerkClient, callbackUrl: string): Promise<FakeOAuthApp> {
8585
const oAuthApp = await clerkClient.oauthApplications.create({
8686
name: `Integration Test OAuth App - ${Date.now()}`,
8787
redirectUris: [callbackUrl],
@@ -107,7 +107,7 @@ export type ObtainOAuthAccessTokenParams = {
107107
};
108108
};
109109

110-
export async function obtainOAuthAccessToken({
110+
async function obtainOAuthAccessToken({
111111
page,
112112
oAuthApp,
113113
redirectUri,

integration/tests/astro/machine.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { test } from '@playwright/test';
22

33
import { appConfigs } from '../../presets';
4-
import type { MachineAuthTestAdapter } from '../../testUtils';
5-
import { registerApiKeyAuthTests, registerM2MAuthTests, registerOAuthAuthTests } from '../../testUtils';
4+
import type { MachineAuthTestAdapter } from '../../testUtils/machineAuthHelpers';
5+
import {
6+
registerApiKeyAuthTests,
7+
registerM2MAuthTests,
8+
registerOAuthAuthTests,
9+
} from '../../testUtils/machineAuthHelpers';
610

711
const adapter: MachineAuthTestAdapter = {
812
baseConfig: appConfigs.astro.node,

integration/tests/next-machine.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { test } from '@playwright/test';
22

33
import { appConfigs } from '../presets';
4-
import type { MachineAuthTestAdapter } from '../testUtils';
5-
import { registerApiKeyAuthTests, registerM2MAuthTests, registerOAuthAuthTests } from '../testUtils';
4+
import type { MachineAuthTestAdapter } from '../testUtils/machineAuthHelpers';
5+
import { registerApiKeyAuthTests, registerM2MAuthTests, registerOAuthAuthTests } from '../testUtils/machineAuthHelpers';
66

77
const adapter: MachineAuthTestAdapter = {
88
baseConfig: appConfigs.next.appRouter,

integration/tests/react-router/machine.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { test } from '@playwright/test';
22

33
import { appConfigs } from '../../presets';
4-
import type { MachineAuthTestAdapter } from '../../testUtils';
5-
import { registerApiKeyAuthTests, registerM2MAuthTests, registerOAuthAuthTests } from '../../testUtils';
4+
import type { MachineAuthTestAdapter } from '../../testUtils/machineAuthHelpers';
5+
import {
6+
registerApiKeyAuthTests,
7+
registerM2MAuthTests,
8+
registerOAuthAuthTests,
9+
} from '../../testUtils/machineAuthHelpers';
610

711
const adapter: MachineAuthTestAdapter = {
812
baseConfig: appConfigs.reactRouter.reactRouterNode,

integration/tests/tanstack-start/machine.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { test } from '@playwright/test';
22

33
import { appConfigs } from '../../presets';
4-
import type { MachineAuthTestAdapter } from '../../testUtils';
5-
import { registerApiKeyAuthTests, registerM2MAuthTests, registerOAuthAuthTests } from '../../testUtils';
4+
import type { MachineAuthTestAdapter } from '../../testUtils/machineAuthHelpers';
5+
import {
6+
registerApiKeyAuthTests,
7+
registerM2MAuthTests,
8+
registerOAuthAuthTests,
9+
} from '../../testUtils/machineAuthHelpers';
610

711
const adapter: MachineAuthTestAdapter = {
812
baseConfig: appConfigs.tanstack.reactStart,

0 commit comments

Comments
 (0)