Skip to content

Commit 51344b0

Browse files
authored
test(e2e): isolate enterprise sso test runs (#8660)
1 parent 4e08924 commit 51344b0

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

integration/tests/tanstack-start/enterprise-sso.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { randomBytes } from 'node:crypto';
2+
13
import type { EnterpriseConnection } from '@clerk/backend';
24
import { expect, test } from '@playwright/test';
35

@@ -36,14 +38,17 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEnterpriseSso] })(
3638
({ app }) => {
3739
test.describe.configure({ mode: 'serial' });
3840

39-
const testDomain = 'e2e-enterprise-test.dev';
41+
// Per-run suffix so a failed afterAll on a previous run can't brick the shared
42+
// long-running instance with a duplicate-domain 422 on the next run.
43+
const runId = randomBytes(4).toString('hex');
44+
const testDomain = `e2e-enterprise-test-${runId}.dev`;
4045
const fakeIdpHost = `fake-idp.${testDomain}`;
41-
let enterpriseConnection: EnterpriseConnection;
46+
let enterpriseConnection: EnterpriseConnection | undefined;
4247

4348
test.beforeAll(async () => {
4449
const u = createTestUtils({ app });
4550
enterpriseConnection = await createActiveEnterpriseConnection(u.services.clerk, {
46-
name: 'E2E Test SAML Connection',
51+
name: `E2E Test SAML Connection ${runId}`,
4752
domain: testDomain,
4853
idpEntityId: `https://${fakeIdpHost}`,
4954
idpSsoUrl: `https://${fakeIdpHost}/sso`,
@@ -52,7 +57,11 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEnterpriseSso] })(
5257

5358
test.afterAll(async () => {
5459
const u = createTestUtils({ app });
55-
await u.services.clerk.enterpriseConnections.deleteEnterpriseConnection(enterpriseConnection.id);
60+
// Guard against a failed beforeAll: without this, the TypeError here masks
61+
// the real error from beforeAll in the Playwright report.
62+
if (enterpriseConnection) {
63+
await u.services.clerk.enterpriseConnections.deleteEnterpriseConnection(enterpriseConnection.id);
64+
}
5665
await app.teardown();
5766
});
5867

0 commit comments

Comments
 (0)