From c0d78c5642b59a158ed3b12a9bea9bf58e72a8bb Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 26 Jul 2022 08:53:32 -0700 Subject: [PATCH] fix(runner): friendly error message instead of "digests do not match" (#15939) --- packages/playwright-test/src/fixtures.ts | 10 ++++-- tests/playwright-test/fixture-errors.spec.ts | 36 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) 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.'); +});