Skip to content

Commit 97965d8

Browse files
authored
feat(repo): Enable sessions staging e2e runs (#6855)
1 parent 8e8bfb5 commit 97965d8

6 files changed

Lines changed: 68 additions & 15 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ jobs:
285285
'elements',
286286
'localhost',
287287
'sessions',
288+
'sessions:staging',
289+
'handshake',
290+
'handshake:staging',
288291
'astro',
289292
'expo-web',
290293
'tanstack-react-start',

integration/tests/handshake/handshake.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,33 @@ import type { Server, ServerOptions } from 'node:https';
33
import { expect, test } from '@playwright/test';
44

55
import { constants } from '../../constants';
6+
import type { Application } from '../../models/application';
67
import { fs } from '../../scripts';
78
import { createProxyServer } from '../../scripts/proxyServer';
89
import type { FakeUserWithEmail } from '../../testUtils';
9-
import { createTestUtils, testAgainstRunningApps } from '../../testUtils';
10+
import { createTestUtils } from '../../testUtils';
11+
import { prepareApplication } from '../sessions/utils';
1012

11-
testAgainstRunningApps({ withPattern: ['next.appRouter.sessionsProd1'] })('handshake flow @handshake', ({ app }) => {
13+
test.describe('handshake flow @handshake', () => {
1214
test.describe.configure({ mode: 'serial' });
1315

1416
test.describe('with Production instance', () => {
1517
// TODO: change host name (see integration/README.md#production-hosts)
16-
const host = 'multiple-apps-e2e.clerk.app:8443';
18+
// eslint-disable-next-line turbo/no-undeclared-env-vars
19+
const host = `${process.env.E2E_SESSIONS_APP_1_HOST}:8443`;
20+
// eslint-disable-next-line turbo/no-undeclared-env-vars
21+
const APP_1_ENV_KEY = process.env.E2E_APP_1_ENV_KEY;
1722

1823
let fakeUser: FakeUserWithEmail;
1924
let server: Server;
25+
let app: Application;
26+
let serverUrl: string;
27+
28+
test.beforeAll(async () => {
29+
const res = await prepareApplication(APP_1_ENV_KEY);
30+
app = res.app;
31+
serverUrl = res.serverUrl;
32+
});
2033

2134
test.afterAll(async () => {
2235
await fakeUser.deleteIfExists();
@@ -34,7 +47,7 @@ testAgainstRunningApps({ withPattern: ['next.appRouter.sessionsProd1'] })('hands
3447
server = createProxyServer({
3548
ssl,
3649
targets: {
37-
[host]: app.serverUrl,
50+
[host]: serverUrl,
3851
},
3952
});
4053

integration/tests/sessions/root-subdomain-prod-instances.test.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import type { FakeUser } from '../../testUtils';
1010
import { createTestUtils } from '../../testUtils';
1111
import { prepareApplication } from './utils';
1212

13+
// eslint-disable-next-line turbo/no-undeclared-env-vars
14+
const APP_1_ENV_KEY = process.env.E2E_SESSIONS_APP_1_ENV_KEY;
15+
// eslint-disable-next-line turbo/no-undeclared-env-vars
16+
const APP_1_HOST = process.env.E2E_SESSIONS_APP_1_HOST;
17+
// eslint-disable-next-line turbo/no-undeclared-env-vars
18+
const APP_2_ENV_KEY = process.env.E2E_SESSIONS_APP_2_ENV_KEY;
19+
1320
/**
1421
* These two suites need to run in serial mode because they are both using a local proxy server
1522
* that listens to port 443. We can't run them in parallel because they would conflict with each other, unless
@@ -40,7 +47,7 @@ test.describe('root and subdomain production apps @sessions', () => {
4047
* 5. The second app is going to be served on sub-1.multiple-apps-e2e.clerk.app
4148
*/
4249
test.describe('multiple apps same domain for the same production instances', () => {
43-
const hosts = ['multiple-apps-e2e.clerk.app:8443', 'sub-1.multiple-apps-e2e.clerk.app:8443'];
50+
const hosts = [`${APP_1_HOST}:8443`, `sub-1.${APP_1_HOST}:8443`];
4451

4552
let fakeUser: FakeUser;
4653
let server: Server;
@@ -49,9 +56,9 @@ test.describe('root and subdomain production apps @sessions', () => {
4956
test.beforeAll(async () => {
5057
apps = await Promise.all([
5158
// first app
52-
prepareApplication('sessions-prod-1'),
59+
prepareApplication(APP_1_ENV_KEY),
5360
// second app using the same instance keys
54-
prepareApplication('sessions-prod-1'),
61+
prepareApplication(APP_1_ENV_KEY),
5562
]);
5663

5764
// TODO: Move this into createProxyServer
@@ -70,7 +77,11 @@ test.describe('root and subdomain production apps @sessions', () => {
7077

7178
const u = createTestUtils({ app: apps[0].app });
7279
fakeUser = u.services.users.createFakeUser();
73-
await u.services.users.createBapiUser(fakeUser);
80+
try {
81+
await u.services.users.createBapiUser(fakeUser);
82+
} catch (error) {
83+
console.error(error);
84+
}
7485
});
7586

7687
test.afterAll(async () => {
@@ -180,13 +191,13 @@ test.describe('root and subdomain production apps @sessions', () => {
180191
* 5. The second app is going to be served on sub-1.multiple-apps-e2e.clerk.app
181192
*/
182193
test.describe('multiple apps same domain for different production instances', () => {
183-
const hosts = ['multiple-apps-e2e.clerk.app:8443', 'sub-2.multiple-apps-e2e.clerk.app:8443'];
194+
const hosts = [`${APP_1_HOST}:8443`, `sub-2.${APP_1_HOST}:8443`];
184195
let fakeUsers: FakeUser[];
185196
let server: Server;
186197
let apps: Array<{ app: Application; serverUrl: string }>;
187198

188199
test.beforeAll(async () => {
189-
apps = await Promise.all([prepareApplication('sessions-prod-1'), prepareApplication('sessions-prod-2')]);
200+
apps = await Promise.all([prepareApplication(APP_1_ENV_KEY), prepareApplication(APP_2_ENV_KEY)]);
190201

191202
// TODO: Move this into createProxyServer
192203
const ssl: Pick<ServerOptions, 'ca' | 'cert' | 'key'> = {
@@ -312,13 +323,13 @@ test.describe('root and subdomain production apps @sessions', () => {
312323
*
313324
*/
314325
test.describe('multiple apps different same-level subdomains for different production instances', () => {
315-
const hosts = ['sub-1.multiple-apps-e2e.clerk.app:8443', 'sub-2.multiple-apps-e2e.clerk.app:8443'];
326+
const hosts = [`sub-1.${APP_1_HOST}:8443`, `sub-2.${APP_1_HOST}:8443`];
316327
let fakeUsers: FakeUser[];
317328
let server: Server;
318329
let apps: Array<{ app: Application; serverUrl: string }>;
319330

320331
test.beforeAll(async () => {
321-
apps = await Promise.all([prepareApplication('sessions-prod-1'), prepareApplication('sessions-prod-2')]);
332+
apps = await Promise.all([prepareApplication(APP_1_ENV_KEY), prepareApplication(APP_2_ENV_KEY)]);
322333

323334
// TODO: Move this into createProxyServer
324335
const ssl: Pick<ServerOptions, 'ca' | 'cert' | 'key'> = {

integration/tests/sessions/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { appConfigs } from '../../presets';
22

33
export const getEnvForMultiAppInstance = (envKey: string) => {
4-
return appConfigs.envs.base
4+
const res = appConfigs.envs.base
55
.clone()
66
.setEnvVariable('private', 'CLERK_SECRET_KEY', appConfigs.secrets.instanceKeys.get(envKey).sk)
77
.setEnvVariable('public', 'CLERK_PUBLISHABLE_KEY', appConfigs.secrets.instanceKeys.get(envKey).pk);
8+
9+
if (envKey.includes('clerkstage')) {
10+
res.setEnvVariable('private', 'CLERK_API_URL', 'https://api.clerkstage.dev');
11+
}
12+
13+
return res;
814
};
915

1016
export const prepareApplication = async (envKey: string, port?: number) => {

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@
4141
"test:integration:expo-web": "E2E_APP_ID=expo.expo-web pnpm test:integration:base --grep @expo-web",
4242
"test:integration:express": "E2E_APP_ID=express.* pnpm test:integration:base --grep @express",
4343
"test:integration:generic": "E2E_APP_ID=react.vite.*,next.appRouter.withEmailCodes* pnpm test:integration:base --grep @generic",
44-
"test:integration:handshake": "DISABLE_WEB_SECURITY=true E2E_APP_ID=next.appRouter.sessionsProd1 pnpm test:integration:base --grep @handshake",
44+
"test:integration:handshake": "DISABLE_WEB_SECURITY=true E2E_APP_1_ENV_KEY=sessions-prod-1 E2E_SESSIONS_APP_1_HOST=multiple-apps-e2e.clerk.app pnpm test:integration:base --grep @handshake",
45+
"test:integration:handshake:staging": "DISABLE_WEB_SECURITY=true E2E_APP_1_ENV_KEY=clerkstage-sessions-prod-1 E2E_SESSIONS_APP_1_HOST=clerkstage-sessions-prod-1-e2e.clerk.app pnpm test:integration:base --grep @handshake",
4546
"test:integration:localhost": "pnpm test:integration:base --grep @localhost",
4647
"test:integration:machine": "E2E_APP_ID=withMachine.* pnpm test:integration:base --grep @machine",
4748
"test:integration:nextjs": "E2E_APP_ID=next.appRouter.* pnpm test:integration:base --grep @nextjs",
4849
"test:integration:nuxt": "E2E_APP_ID=nuxt.node npm run test:integration:base -- --grep @nuxt",
4950
"test:integration:quickstart": "E2E_APP_ID=quickstart.* pnpm test:integration:base --grep @quickstart",
5051
"test:integration:react-router": "E2E_APP_ID=react-router.* npm run test:integration:base -- --grep @react-router",
51-
"test:integration:sessions": "DISABLE_WEB_SECURITY=true pnpm test:integration:base --grep @sessions",
52+
"test:integration:sessions": "DISABLE_WEB_SECURITY=true E2E_SESSIONS_APP_1_ENV_KEY=sessions-prod-1 E2E_SESSIONS_APP_2_ENV_KEY=sessions-prod-2 E2E_SESSIONS_APP_1_HOST=multiple-apps-e2e.clerk.app pnpm test:integration:base --grep @sessions",
53+
"test:integration:sessions:staging": "DISABLE_WEB_SECURITY=true E2E_SESSIONS_APP_1_ENV_KEY=clerkstage-sessions-prod-1 E2E_SESSIONS_APP_2_ENV_KEY=clerkstage-sessions-prod-2 E2E_SESSIONS_APP_1_HOST=clerkstage-sessions-prod-1-e2e.clerk.app pnpm test:integration:base --grep @sessions",
5254
"test:integration:tanstack-react-router": "E2E_APP_ID=tanstack.react-router pnpm test:integration:base --grep @tanstack-react-router",
5355
"test:integration:tanstack-react-start": "E2E_APP_ID=tanstack.react-start pnpm test:integration:base --grep @tanstack-react-start",
5456
"test:integration:vue": "E2E_APP_ID=vue.vite pnpm test:integration:base --grep @vue",

turbo.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,24 @@
258258
"inputs": ["integration/**"],
259259
"outputLogs": "new-only"
260260
},
261+
"//#test:integration:sessions:staging": {
262+
"dependsOn": ["@clerk/testing#build", "@clerk/clerk-js#build", "@clerk/backend#build", "@clerk/nextjs#build"],
263+
"env": ["CLEANUP", "DEBUG", "DISABLE_WEB_SECURITY", "E2E_*", "INTEGRATION_INSTANCE_KEYS", "NODE_EXTRA_CA_CERTS"],
264+
"inputs": ["integration/**"],
265+
"outputLogs": "new-only"
266+
},
267+
"//#test:integration:handshake": {
268+
"dependsOn": ["@clerk/testing#build", "@clerk/clerk-js#build", "@clerk/backend#build", "@clerk/nextjs#build"],
269+
"env": ["CLEANUP", "DEBUG", "DISABLE_WEB_SECURITY", "E2E_*", "INTEGRATION_INSTANCE_KEYS", "NODE_EXTRA_CA_CERTS"],
270+
"inputs": ["integration/**"],
271+
"outputLogs": "new-only"
272+
},
273+
"//#test:integration:handshake:staging": {
274+
"dependsOn": ["@clerk/testing#build", "@clerk/clerk-js#build", "@clerk/backend#build", "@clerk/nextjs#build"],
275+
"env": ["CLEANUP", "DEBUG", "DISABLE_WEB_SECURITY", "E2E_*", "INTEGRATION_INSTANCE_KEYS", "NODE_EXTRA_CA_CERTS"],
276+
"inputs": ["integration/**"],
277+
"outputLogs": "new-only"
278+
},
261279
"//#test:integration:elements": {
262280
"dependsOn": [
263281
"@clerk/testing#build",

0 commit comments

Comments
 (0)