Issue 1:
Hi there! I am writing a suite of Playwright tests. So far it has mostly been a joy to use.

However, I have run into some issues when parallelizing tests. I am pretty sure that this functionality does not exist, but if it does, happy to learn more about it.

The vast majority of my tests are independent and can be run in parallel without any issues. Test objects are created at the start of the test and cleaned up at the end. No problem. However, I have a few tests that necessarily affect global state in the application. These can still clean themselves up at the end so the state at the end of the test is the same as the start. However, they can't be run in parallel with any other test because their effects while running will mess with other tests.

So far I have solved this by only using one worker and running no tests in parallel. This is not ideal, as it slows tests down a bit. Is there (or can there be) some way to run all tests with the specified number of workers but run x tests (demarcated somehow in the test) only by themselves?

I looked into https://playwright.dev/docs/api/class-test#test-describe-serial and thought I had found a way to do this, but this appears to only run tests in a given describe block in serial and not be what I'm actually looking for.

My next attempt is probably going to be to try to use some sort of semaphore to get certain tests only to run on their own, but this will be kinda hacky and it would be nice if the framework natively supported this feature.

Thank you!

Issue 2:
System info

Playwright Version: 8.19.1

Operating System: All

Browser: All

Other info:

Source code

test.describe('Test', () => {
// should be WorkerInfo but is typed as TestInfo
test.beforeAll(async ({ browser }, workerInfo) => {});
// correctly typed as TestInfo
test.afterEach(async ({}, testInfo) => {});

Steps

No special config or steps are needed - you can also simply check the test.d.ts type definitions file to confirm this:

/**
* Declares a `beforeAll` hook that is executed once per worker process before all tests.
*
* **Details**
*
* When called in the scope of a test file, runs before all tests in the file. When called inside a
* [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe-1) group, runs before all
* tests in the group. If multiple `beforeAll` hooks are added, they will run in the order of their registration.
*
* Note that worker process is restarted on test failures, and `beforeAll` hook runs again in the new worker. Learn
* more about [workers and failures](https://playwright.dev/docs/test-retries).
*
* You can use [test.afterAll(hookFunction)](https://playwright.dev/docs/api/class-test#test-after-all) to teardown
* any resources set up in `beforeAll`.
*
* **Usage**
*
* ```js
* // example.spec.ts
* import { test, expect } from '@playwright/test';
*
* test.beforeAll(async () => {
* console.log('Before tests');
* });
*
* test.afterAll(async () => {
* console.log('After tests');
* });
*
* test('my test', async ({ page }) => {
* // ...
* });
* ```
*
* @param hookFunction Hook function that takes one or two arguments: an object with worker fixtures and optional [TestInfo].
*/
beforeAll(inner: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<any> | any): void;
/**
* Declares an `afterAll` hook that is executed once per worker after all tests.
*
* **Details**
*
* When called in the scope of a test file, runs after all tests in the file. When called inside a
* [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe-1) group, runs after all
* tests in the group. If multiple `afterAll` hooks are added, they will run in the order of their registration.
*
* Note that worker process is restarted on test failures, and `afterAll` hook runs again in the new worker. Learn
* more about [workers and failures](https://playwright.dev/docs/test-retries).
*
* **Usage**
*
* ```js
* test.afterAll(async () => {
* console.log('Done with tests');
* // ...
* });
* ```
*
* @param hookFunction Hook function that takes one or two arguments: an object with worker fixtures and optional [TestInfo].
*/
afterAll(inner: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<any> | any): void;

Expected

According to the documentation the WorkerInfo class is available to beforeAll and afterAll hooks as well as worker scoped fixtures.

The docs describing the beforeAll and afterAll hooks contradict the WorkerInfo docs. They probably need updating too.

Actual

A TestInfo type is returned instead of the correct WorkerInfo type.