From ef6c27e6104c8967cd4ec7fc83a480f71d97b2b5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 5 Oct 2026 06:23:37 +0000 Subject: [PATCH] chore(internals): cover playground browser open branches Adds unit tests that call PlaygroundService.create for the mcp and cli environments while CI is unset, and assert that the open package receives the returned playground URL. Line coverage for service.ts moves from 92% to 100%, and branch coverage moves from 85.71% to 100%. No behavior change. Signed-off-by: Cursor Agent --- .../tools/src/playground/service.test.ts | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/projects/internals/tools/src/playground/service.test.ts b/projects/internals/tools/src/playground/service.test.ts index b2b36d865..b285c309e 100644 --- a/projects/internals/tools/src/playground/service.test.ts +++ b/projects/internals/tools/src/playground/service.test.ts @@ -4,14 +4,41 @@ import { writeFileSync, rmSync, mkdtempSync, symlinkSync, mkdirSync } from 'node:fs'; import { join, relative } from 'node:path'; import { tmpdir } from 'node:os'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import open from 'open'; import { loadTools, type ToolMethod, type ToolOutput } from '../internal/tools.js'; import { PlaygroundService } from './service.js'; import { createPlaygroundURL, MAX_PLAYGROUND_URL_LENGTH } from './utils.js'; +vi.mock('open', () => ({ + default: vi.fn(() => Promise.resolve()) +})); + // when ELEMENTS_PLAYGROUND_BASE_URL is not configured, createPlaygroundURL returns '' const hasPlaygroundBaseURL = createPlaygroundURL('test', []).length > 0; +async function expectPlaygroundToOpen(environment: 'mcp' | 'cli') { + process.env.ELEMENTS_ENV = environment; + const ci = process.env.CI; + delete process.env.CI; + vi.mocked(open).mockClear(); + + try { + const result = await PlaygroundService.create({ + template: 'valid', + start: false + }); + expect(vi.mocked(open)).toHaveBeenCalledTimes(1); + expect(vi.mocked(open)).toHaveBeenCalledWith(result); + } finally { + if (ci === undefined) { + delete process.env.CI; + } else { + process.env.CI = ci; + } + } +} + describe('PlaygroundService', () => { it('should provide validate', async () => { const env = process.env.ELEMENTS_ENV; @@ -183,6 +210,14 @@ describe('PlaygroundService', () => { } }); + it('should open the playground url outside ci in the mcp environment', async () => { + await expectPlaygroundToOpen('mcp'); + }); + + it('should open the playground url outside ci in the cli environment', async () => { + await expectPlaygroundToOpen('cli'); + }); + it('should return URL when template passes lint in mcp environment', async () => { process.env.ELEMENTS_ENV = 'mcp'; const CI = process.env.CI;