Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/playwright-core/src/tools/cli-client/minimist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export function minimist(args: string[], opts?: MinimistOptions): MinimistArgs {
} else {
setArg(key, strings[key] ? '' : true);
}
} else if ((/^-[^-]+/).test(arg)) {
} else if ((/^-[A-Za-z]/).test(arg)) {
// Short flags are letters, so '-100' and '-.5' are arguments, not flags.
const letters = arg.slice(1, -1).split('');

let broken = false;
Expand Down
14 changes: 13 additions & 1 deletion tests/mcp/cli-parsing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { test, expect } from './cli-fixtures';
import { test, expect, eventsPage } from './cli-fixtures';

test('unknown option', async ({ cli, server }) => {
const { error, exitCode } = await cli('open', '--some-option', 'value', 'about:blank');
Expand Down Expand Up @@ -73,6 +73,18 @@ test('wrong argument type', async ({ cli, server }) => {
expect(press.exitCode).toBe(0);
});

test('negative number arguments', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42321' } }, async ({ cli, server }) => {
server.setContent('/', eventsPage, 'text/html');
await cli('open', server.PREFIX);
await cli('mousemove', '50', '50');

expect((await cli('mousewheel', '0', '-100')).exitCode).toBe(0);
await expect.poll(() => cli('snapshot').then(result => result.inlineSnapshot)).toContain('wheel 0 -100');

const { error } = await cli('mousewheel', '-.5');
expect(error).toContain(`error: 'dy' argument: expected number, received 'undefined'`);
});

test('should preserve leading zeros in string arguments', async ({ cli, server }) => {
server.setContent('/', `<input type=text>`, 'text/html');
await cli('open', server.PREFIX);
Expand Down
Loading