Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(runner): friendly error message instead of "digests do not match" (#15939)

Dmitry Gozmanc0d78c5642b5
diff --git a/packages/playwright-test/src/fixtures.ts b/packages/playwright-test/src/fixtures.ts
index 9d19ed547e..a3b1d8f1cc 100644
--- a/packages/playwright-test/src/fixtures.ts
+++ b/packages/playwright-test/src/fixtures.ts
@@ -300,8 +300,14 @@ export class FixtureRunner {
setPool(pool: FixturePool) {
if (!this.testScopeClean)
throw new Error('Did not teardown test scope');
- if (this.pool && pool.digest !== this.pool.digest)
- throw new Error('Digests do not match');
+ if (this.pool && pool.digest !== this.pool.digest) {
+ throw new Error([
+ `Playwright detected inconsistent test.use() options.`,
+ `Most common mistakes that lead to this issue:`,
+ ` - Calling test.use() outside of the test file, for example in a common helper.`,
+ ` - One test file imports from another test file.`,
+ ].join('\n'));
+ }
this.pool = pool;
}
diff --git a/tests/playwright-test/fixture-errors.spec.ts b/tests/playwright-test/fixture-errors.spec.ts
index f6dee67709..5d63304297 100644
--- a/tests/playwright-test/fixture-errors.spec.ts
+++ b/tests/playwright-test/fixture-errors.spec.ts
@@ -584,3 +584,39 @@ test('should not run user fn when require fixture has failed', async ({ runInlin
'%%foo',
]);
});
+
+test('should provide helpful error message when digests do not match', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'helper.ts': `
+ export const test = pwt.test.extend({
+ foo: [ async ({}, use) => use(), { scope: 'worker' } ],
+ });
+
+ test.use({ foo: 'foo' });
+ `,
+ 'a.spec.ts': `
+ import { test } from './helper';
+
+ test('test-a', ({ foo }) => {
+ expect(foo).toBe('foo');
+ });
+ `,
+ 'b.spec.ts': `
+ import { test } from './helper';
+
+ test('test-b', ({ foo }) => {
+ expect(foo).toBe('foo');
+ });
+ `,
+ 'c.spec.ts': `
+ import { test } from './helper';
+
+ test('test-c', ({ foo }) => {
+ expect(foo).toBe('foo');
+ });
+ `,
+ }, { workers: 1 });
+ expect(result.exitCode).toBe(1);
+ expect(result.failed).toBe(1);
+ expect(stripAnsi(result.output)).toContain('Playwright detected inconsistent test.use() options.');
+});