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
14 changes: 14 additions & 0 deletions docs/src/test-api/class-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,14 @@ Learn more about the execution modes [here](../test-parallel.md).
test('runs second', async ({ page }) => {});
```

* Declaring locks for all tests in a scope.

```js
test.describe.configure({ lock: 'user-settings' });
test('update user settings', async ({ page }) => {});
test('reset user settings', async ({ page }) => {});
```

* Run multiple describes in parallel, but tests inside each describe in order.

```js
Expand All @@ -559,6 +567,12 @@ Learn more about the execution modes [here](../test-parallel.md).
});
```

### option: Test.describe.configure.lock
* since: v1.64
- `lock` <[string]|[Array]<[string]>>

Additional named locks for all tests in the enclosing scope, including nested groups. Locks are added to those declared in [`method: Test.describe`] details and previous calls to [`method: Test.describe.configure`].

### option: Test.describe.configure.mode
* since: v1.10
- `mode` <[TestMode]<"default"|"parallel"|"serial">>
Expand Down
6 changes: 6 additions & 0 deletions docs/src/test-parallel-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ test('reset the database', { lock: ['database', 'external-api'] }, async () => {
});
```

You can also add locks to the enclosing file or describe group with [`method: Test.describe.configure`]. Repeated calls add locks without removing existing ones.

```js
test.describe.configure({ lock: 'user-settings' });
```

Playwright acquires all the locks of a test before the test starts and releases them when it finishes.

:::note
Expand Down
5 changes: 4 additions & 1 deletion packages/playwright/src/common/testType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,15 @@ export class TestTypeImpl {
suite._hooks.push({ type: name, fn: fn!, title, location });
}

private _configure(location: Location, options: { mode?: 'default' | 'parallel' | 'serial', retries?: number, timeout?: number }) {
private _configure(location: Location, options: { mode?: 'default' | 'parallel' | 'serial', retries?: number, timeout?: number, lock?: string | string[] }) {
throwIfRunningInsideJest();
const suite = this._currentSuite(location, `test.describe.configure()`);
if (!suite)
return;

if (options.lock !== undefined)
suite._locks.push(...validateTestDetails({ lock: options.lock }, location).locks);

if (options.timeout !== undefined)
suite._timeout = options.timeout;

Expand Down
10 changes: 9 additions & 1 deletion packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4414,6 +4414,14 @@ export interface TestType<TestArgs extends {}, WorkerArgs extends {}> {
* test('runs second', async ({ page }) => {});
* ```
*
* - Declaring locks for all tests in a scope.
*
* ```js
* test.describe.configure({ lock: 'user-settings' });
* test('update user settings', async ({ page }) => {});
* test('reset user settings', async ({ page }) => {});
* ```
*
* - Run multiple describes in parallel, but tests inside each describe in order.
*
* ```js
Expand All @@ -4434,7 +4442,7 @@ export interface TestType<TestArgs extends {}, WorkerArgs extends {}> {
*
* @param options
*/
configure: (options: { mode?: 'default' | 'parallel' | 'serial', retries?: number, timeout?: number }) => void;
configure: (options: { mode?: 'default' | 'parallel' | 'serial', retries?: number, timeout?: number, lock?: string | string[] }) => void;
};

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/playwright-test/test-locks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ test('should not run tests with the same lock from different projects at the sam
expect(conflictingOverlaps(result.outputLines, [['project1', 'project2']])).toEqual([]);
});

test('should support locks declared on a describe group', async ({ runInlineTest }) => {
test('should support locks declared and configured on describe groups', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { fullyParallel: true };
Expand All @@ -131,6 +131,10 @@ test('should support locks declared on a describe group', async ({ runInlineTest
import { test } from '@playwright/test';
test.describe('locked suite', { lock: 'shared' }, () => {
${lockedTest('test1', 1000)}
});
test.describe('configured suite', () => {
test.describe.configure({ lock: 'shared' });
test.describe.configure({ lock: ['other'] });
${lockedTest('test2', 1000)}
});
`,
Expand Down
2 changes: 1 addition & 1 deletion utils/generate_types/overrides-test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export interface TestType<TestArgs extends {}, WorkerArgs extends {}> {
only(title: string, details: TestDetails, callback: () => void): void;
};

configure: (options: { mode?: 'default' | 'parallel' | 'serial', retries?: number, timeout?: number }) => void;
configure: (options: { mode?: 'default' | 'parallel' | 'serial', retries?: number, timeout?: number, lock?: string | string[] }) => void;
};

skip(title: string, body: TestBody<TestArgs & WorkerArgs>): void;
Expand Down
Loading