1+ import { randomBytes } from 'node:crypto' ;
2+
13import type { EnterpriseConnection } from '@clerk/backend' ;
24import { 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