diff --git a/packages/b2c-cli/test/functional/e2e/sandbox-lifecycle.test.ts b/packages/b2c-cli/test/functional/e2e/sandbox-lifecycle.test.ts index 2a5f52e9..1d1f816b 100644 --- a/packages/b2c-cli/test/functional/e2e/sandbox-lifecycle.test.ts +++ b/packages/b2c-cli/test/functional/e2e/sandbox-lifecycle.test.ts @@ -439,10 +439,28 @@ describe('Sandbox Lifecycle E2E Tests', function () { describe('Realm Management', function () { const realmId = process.env.TEST_REALM; - before(function () { + before(async function () { if (!realmId) { this.skip(); } + + // Perform a lightweight realm health check so all realm tests can + // assume the realm is basically available. If the realm is missing + // or misconfigured skip the Realm Management tests + const result = await runCLIWithRetry(['sandbox', 'realm', 'get', realmId!, '--json'], {verbose: true}); + + if (result.exitCode !== 0) { + const errorText = String(result.stderr || result.stdout || ''); + if ( + errorText.includes('Realm not found') || + errorText.includes('Failed to fetch configuration for realm') || + errorText.includes('ConnectTimeoutError') || + errorText.includes('CronExpression') + ) { + console.log(' ⚠ Realm not available or misconfigured; skipping Realm Management tests:', errorText); + this.skip(); + } + } }); it('should get realm details', async function () { diff --git a/packages/b2c-cli/test/functional/e2e/test-utils.ts b/packages/b2c-cli/test/functional/e2e/test-utils.ts index 2bc361c5..1a9c0618 100644 --- a/packages/b2c-cli/test/functional/e2e/test-utils.ts +++ b/packages/b2c-cli/test/functional/e2e/test-utils.ts @@ -154,7 +154,13 @@ export async function runCLI(args: string[], options: CLIOptions = {}): Promise< cwd, }); - return result; + const normalizedExitCode = + typeof result.exitCode === 'number' ? result.exitCode : ((result as any).code ?? (result as any).status ?? 1); + + return { + ...result, + exitCode: normalizedExitCode, + }; } /**