From 4da0a860b8466e96e6c921a9dc3c1f8c97f7e106 Mon Sep 17 00:00:00 2001 From: "microsoft-playwright-automation[bot]" <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:45:17 -0800 Subject: [PATCH] test(cli): cover the session options before the command The update and skill checks took the first non-option token as the command, so `-s foo list` skipped them and `-s list snapshot` ran them. Since #523 the command comes from the parsed arguments. Document the space-separated session forms and extend the update-check and skill-warning tests. Fixes: https://github.com/microsoft/playwright-cli/issues/505 --- README.md | 4 ++-- tests/integration.spec.ts | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ed86206..d34af1d 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,8 @@ Playwright CLI keeps the browser profile in memory by default. Your cookies and are preserved between CLI calls within the session, but lost when the browser closes. Use `--persistent` to save the profile to disk for persistence across browser restarts. -You can use different instances of the browser for different projects with sessions. Pass `-s=` to -the invocation to talk to a specific browser. +You can use different instances of the browser for different projects with sessions. Pass `-s=name`, +`-s name` or `--session name` to the invocation to talk to a specific browser. ```bash playwright-cli open https://playwright.dev diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index 72e5831..683d837 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -128,7 +128,7 @@ test('warns when installed skill is out of date', async ({ npmRegistry }) => { fs.appendFileSync(skillFile, 'x'); const env = updateCheckEnv(npmRegistry); - expect(await runCli(['list'], env)).toEqual(expect.objectContaining({ + expect(await runCli(['-s', 'foo', 'list'], env)).toEqual(expect.objectContaining({ error: expect.stringContaining('does not match the tool version'), })); @@ -182,7 +182,9 @@ test('caches the update check in the default registry directory', async ({ npmRe expect(JSON.parse(fs.readFileSync(found[0], 'utf8')).lastCheck).toEqual(expect.any(Number)); }); -test('update check asks npm for the latest version on setup commands only', async ({ npmRegistry }) => { +test('update check asks npm for the latest version on setup commands only', { + annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-cli/issues/505' }, +}, async ({ npmRegistry }) => { const env = updateCheckEnv(npmRegistry); expect(await runCli(['--version'], env)).toEqual(expect.objectContaining({ error: '', @@ -190,6 +192,14 @@ test('update check asks npm for the latest version on setup commands only', asyn })); expect(npmRegistry.requests).toEqual([]); + // A session named after a setup command is not the command. + expect(await runCli(['-s', 'list', 'snapshot'], env)).toEqual(expect.objectContaining({ + error: expect.not.stringContaining('Update available for @playwright/cli'), + exitCode: 1, + })); + expect(npmRegistry.requests).toEqual([]); + expect(fs.existsSync(test.info().outputPath('cli-update-check.json'))).toBe(false); + // The command is recognized behind the global options. expect(await runCli(['--session', 'foo', 'list'], env)).toEqual(expect.objectContaining({ error: expect.stringContaining('Update available for @playwright/cli'), @@ -206,7 +216,7 @@ test('update check on install does not warn about the skills being installed', a const skillFile = path.join(test.info().outputPath(), '.claude', 'skills', 'playwright-cli', 'SKILL.md'); fs.appendFileSync(skillFile, 'x'); - const result = await runCli(['install', '--skills'], updateCheckEnv(npmRegistry)); + const result = await runCli(['--session', 'list', 'install', '--skills'], updateCheckEnv(npmRegistry)); expect(result.exitCode).toBe(0); expect(result.error).toContain('Update available for @playwright/cli'); expect(result.error).not.toContain('does not match the tool version');