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

This commit is contained in:
Dmitry Gozman 2022-07-26 08:53:32 -07:00 committed by GitHub
parent ac480240bb
commit c0d78c5642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 2 deletions

View File

@ -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;
}

View File

@ -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.');
});