[Bug]: CLI numeric options are not validated: `--timeout 30s` runs with a 30ms timeout, `--timeout abc` / `--retries abc` silently disable timeouts and retries

Đã đóng Phù hợp với người mới
#43,533 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@CloneOfAlex đang làm issue này rồi.

Từ ngày 19/10/2026.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, playwright, typescript
Lĩnh vực
cli, testing

Hướng nghiên cứu

Bắt đầu tại packages/playwright/src/cli/testActions.ts, ở overridesFromOptions(), và kiểm tra cách phân tích năm tùy chọn CLI dạng số; so sánh với phần xác thực trong configLoader.ts. Thêm các bài kiểm thử tập trung cho giá trị sai định dạng và hợp lệ, rồi chạy các bài kiểm thử đó. Công việc hoàn tất khi giá trị không hợp lệ tạo ra lỗi hướng dẫn sử dụng rõ ràng và các số nguyên không âm hợp lệ vẫn hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Version

1.64.1 (also reproduces on main at cdcef0b)

Steps to reproduce

No browser needed. Fresh project with npm i -D @playwright/[email protected] and two files:

// tests/a.spec.ts
import { test } from '@playwright/test';
test('waits 200ms', async () => { await new Promise(f => setTimeout(f, 200)); });
// tests/d.spec.ts
import { test } from '@playwright/test';
test('reports config', async ({}, testInfo) => {
  console.log('timeout=' + testInfo.timeout + ' retries=' + testInfo.project.retries);
});
  1. npx playwright test tests/a.spec.ts --timeout 30s
  2. npx playwright test tests/d.spec.ts --timeout abc --retries abc
Expected behavior

Both commands fail fast with a usage error, the same way invalid config-file values are rejected (config.timeout must be a non-negative number). For example: --timeout "30s" must be a non-negative integer.

Actual behavior
  1. The test fails with Test timeout of 30ms exceeded. because "30s" is read as 30 ms. --timeout 1m likewise becomes a 1 ms timeout.
  2. The run prints timeout=null retries=null and passes with exit code 0. The run has no test timeout and no retries, with no warning.

The same applies to --global-timeout, --repeat-each and --max-failures.

Additional context

Root cause: overridesFromOptions() in packages/playwright/src/cli/testActions.ts uses parseInt(value, 10) for --timeout, --global-timeout, --retries, --repeat-each and --max-failures. parseInt('30s') is 30, and parseInt('abc') is NaN. NaN is serialized as null over IPC, and !slot.timeout then means "no timeout". Values from the config file are validated in configLoader.ts, but CLI overrides are not.

I have a fix with tests ready: a strict non-negative-integer check that throws a clear usage error. Happy to open a PR if that approach works for you.

Environment
System:
  OS: Linux 6.18 Ubuntu 24.04.5 LTS (Noble Numbat)
  CPU: (2) x64 Intel(R) Xeon(R) Processor @ 2.10GHz
  Memory: 7.84 GB
  Container: Yes
Binaries:
  Node: 22.22.0
  npm: 10.9.4
npmPackages:
  @playwright/test: 1.64.1
Ngôn ngữ chính
TypeScript
Star
98.5k
Fork
6.7k
Merge trung bình
15 giờ 58 phút
Pull request đã merge (30 ngày)
302

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/playwright

Tất cả issue của microsoft/playwright

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.