mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-06 03:16:17 +03:00
fix(test runner): do not validate fixtures in tests/hooks that are never run (#10328)
This commit is contained in:
parent
fd3ec50cf6
commit
638ebd6dd6
@ -80,12 +80,6 @@ export class ProjectImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _cloneEntries(from: Suite, to: Suite, repeatEachIndex: number, filter: (test: TestCase) => boolean): boolean {
|
private _cloneEntries(from: Suite, to: Suite, repeatEachIndex: number, filter: (test: TestCase) => boolean): boolean {
|
||||||
for (const hook of from._allHooks) {
|
|
||||||
const clone = hook._clone();
|
|
||||||
clone._pool = this.buildPool(hook);
|
|
||||||
clone._projectIndex = this.index;
|
|
||||||
to._addAllHook(clone);
|
|
||||||
}
|
|
||||||
for (const entry of from._entries) {
|
for (const entry of from._entries) {
|
||||||
if (entry instanceof Suite) {
|
if (entry instanceof Suite) {
|
||||||
const suite = entry._clone();
|
const suite = entry._clone();
|
||||||
@ -95,22 +89,31 @@ export class ProjectImpl {
|
|||||||
to.suites.pop();
|
to.suites.pop();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const pool = this.buildPool(entry);
|
|
||||||
const test = entry._clone();
|
const test = entry._clone();
|
||||||
test.retries = this.config.retries;
|
test.retries = this.config.retries;
|
||||||
test._workerHash = `run${this.index}-${pool.digest}-repeat${repeatEachIndex}`;
|
|
||||||
test._id = `${entry._ordinalInFile}@${entry._requireFile}#run${this.index}-repeat${repeatEachIndex}`;
|
test._id = `${entry._ordinalInFile}@${entry._requireFile}#run${this.index}-repeat${repeatEachIndex}`;
|
||||||
test._pool = pool;
|
|
||||||
test._repeatEachIndex = repeatEachIndex;
|
test._repeatEachIndex = repeatEachIndex;
|
||||||
test._projectIndex = this.index;
|
test._projectIndex = this.index;
|
||||||
to._addTest(test);
|
to._addTest(test);
|
||||||
if (!filter(test)) {
|
if (!filter(test)) {
|
||||||
to._entries.pop();
|
to._entries.pop();
|
||||||
to.suites.pop();
|
to.tests.pop();
|
||||||
|
} else {
|
||||||
|
const pool = this.buildPool(entry);
|
||||||
|
test._workerHash = `run${this.index}-${pool.digest}-repeat${repeatEachIndex}`;
|
||||||
|
test._pool = pool;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return to._entries.length > 0;
|
if (!to._entries.length)
|
||||||
|
return false;
|
||||||
|
for (const hook of from._allHooks) {
|
||||||
|
const clone = hook._clone();
|
||||||
|
clone._pool = this.buildPool(hook);
|
||||||
|
clone._projectIndex = this.index;
|
||||||
|
to._addAllHook(clone);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneFileSuite(suite: Suite, repeatEachIndex: number, filter: (test: TestCase) => boolean): Suite | undefined {
|
cloneFileSuite(suite: Suite, repeatEachIndex: number, filter: (test: TestCase) => boolean): Suite | undefined {
|
||||||
|
@ -27,7 +27,7 @@ import { Loader } from './loader';
|
|||||||
import { Modifier, Suite, TestCase } from './test';
|
import { Modifier, Suite, TestCase } from './test';
|
||||||
import { Annotations, TestError, TestInfo, TestInfoImpl, TestStepInternal, WorkerInfo } from './types';
|
import { Annotations, TestError, TestInfo, TestInfoImpl, TestStepInternal, WorkerInfo } from './types';
|
||||||
import { ProjectImpl } from './project';
|
import { ProjectImpl } from './project';
|
||||||
import { FixturePool, FixtureRunner } from './fixtures';
|
import { FixtureRunner } from './fixtures';
|
||||||
import { DeadlineRunner, raceAgainstDeadline } from 'playwright-core/lib/utils/async';
|
import { DeadlineRunner, raceAgainstDeadline } from 'playwright-core/lib/utils/async';
|
||||||
|
|
||||||
const removeFolderAsync = util.promisify(rimraf);
|
const removeFolderAsync = util.promisify(rimraf);
|
||||||
@ -148,15 +148,14 @@ export class WorkerRunner extends EventEmitter {
|
|||||||
this._entries = new Map(runPayload.entries.map(e => [ e.testId, e ]));
|
this._entries = new Map(runPayload.entries.map(e => [ e.testId, e ]));
|
||||||
await this._loadIfNeeded();
|
await this._loadIfNeeded();
|
||||||
const fileSuite = await this._loader.loadTestFile(runPayload.file);
|
const fileSuite = await this._loader.loadTestFile(runPayload.file);
|
||||||
let anyPool: FixturePool | undefined;
|
|
||||||
const suite = this._project.cloneFileSuite(fileSuite, this._params.repeatEachIndex, test => {
|
const suite = this._project.cloneFileSuite(fileSuite, this._params.repeatEachIndex, test => {
|
||||||
if (!this._entries.has(test._id))
|
if (!this._entries.has(test._id))
|
||||||
return false;
|
return false;
|
||||||
anyPool = test._pool;
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
if (suite && anyPool) {
|
if (suite) {
|
||||||
this._fixtureRunner.setPool(anyPool);
|
const firstPool = suite.allTests()[0]._pool!;
|
||||||
|
this._fixtureRunner.setPool(firstPool);
|
||||||
await this._runSuite(suite, []);
|
await this._runSuite(suite, []);
|
||||||
}
|
}
|
||||||
if (this._failedTest)
|
if (this._failedTest)
|
||||||
|
@ -699,3 +699,30 @@ test('worker teardown errors reflected in timed-out tests', async ({ runInlineTe
|
|||||||
expect(result.output).toContain('Timeout of 1000ms exceeded.');
|
expect(result.output).toContain('Timeout of 1000ms exceeded.');
|
||||||
expect(result.output).toContain('Rejecting!');
|
expect(result.output).toContain('Rejecting!');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not complain about fixtures of non-focused tests', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.js': `
|
||||||
|
const { test } = pwt;
|
||||||
|
test.only('works', () => {});
|
||||||
|
test('unknown fixture', ({ foo }) => {});
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not complain about fixtures of unused hooks', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.js': `
|
||||||
|
const { test } = pwt;
|
||||||
|
test.only('works', () => {});
|
||||||
|
test.describe('unused suite', () => {
|
||||||
|
test.beforeAll(({ foo }) => {});
|
||||||
|
test('unused test', () => {});
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user