fix(test-runner): with automatic fixtures workerInfo was undefined after conditional skip (#7521)
This commit is contained in:
parent
b2742976a8
commit
e604f185ca
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
import { wrapInPromise } from './util';
|
import { wrapInPromise } from './util';
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { FixturesWithLocation, Location } from './types';
|
import { FixturesWithLocation, Location, WorkerInfo, TestInfo } from './types';
|
||||||
|
|
||||||
type FixtureScope = 'test' | 'worker';
|
type FixtureScope = 'test' | 'worker';
|
||||||
type FixtureRegistration = {
|
type FixtureRegistration = {
|
||||||
|
|
@ -228,7 +228,7 @@ export class FixtureRunner {
|
||||||
this.testScopeClean = true;
|
this.testScopeClean = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async resolveParametersAndRunHookOrTest(fn: Function, scope: FixtureScope, info: any) {
|
async resolveParametersAndRunHookOrTest(fn: Function, scope: FixtureScope, info: WorkerInfo|TestInfo) {
|
||||||
// Install all automatic fixtures.
|
// Install all automatic fixtures.
|
||||||
for (const registration of this.pool!.registrations.values()) {
|
for (const registration of this.pool!.registrations.values()) {
|
||||||
const shouldSkip = scope === 'worker' && registration.scope === 'test';
|
const shouldSkip = scope === 'worker' && registration.scope === 'test';
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ export class WorkerRunner extends EventEmitter {
|
||||||
if (!this._fixtureRunner.dependsOnWorkerFixturesOnly(beforeAllModifier.fn, beforeAllModifier.location))
|
if (!this._fixtureRunner.dependsOnWorkerFixturesOnly(beforeAllModifier.fn, beforeAllModifier.location))
|
||||||
continue;
|
continue;
|
||||||
// TODO: separate timeout for beforeAll modifiers?
|
// TODO: separate timeout for beforeAll modifiers?
|
||||||
const result = await raceAgainstDeadline(this._fixtureRunner.resolveParametersAndRunHookOrTest(beforeAllModifier.fn, 'worker', undefined), this._deadline());
|
const result = await raceAgainstDeadline(this._fixtureRunner.resolveParametersAndRunHookOrTest(beforeAllModifier.fn, 'worker', this._workerInfo), this._deadline());
|
||||||
if (result.timedOut) {
|
if (result.timedOut) {
|
||||||
this._fatalError = serializeError(new Error(`Timeout of ${this._project.config.timeout}ms exceeded while running ${beforeAllModifier.type} modifier`));
|
this._fatalError = serializeError(new Error(`Timeout of ${this._project.config.timeout}ms exceeded while running ${beforeAllModifier.type} modifier`));
|
||||||
this._reportDoneAndStop();
|
this._reportDoneAndStop();
|
||||||
|
|
|
||||||
|
|
@ -340,6 +340,34 @@ test('automatic fixtures should work', async ({ runInlineTest }) => {
|
||||||
expect(result.results.map(r => r.status)).toEqual(['passed', 'passed']);
|
expect(result.results.map(r => r.status)).toEqual(['passed', 'passed']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('automatic fixtures should keep workerInfo after conditional skip', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.js': `
|
||||||
|
const test = pwt.test;
|
||||||
|
test.use({
|
||||||
|
automaticTestFixture: [ async ({}, runTest, workerInfo) => {
|
||||||
|
await runTest();
|
||||||
|
expect(workerInfo.workerIndex).toBe(0);
|
||||||
|
console.log('success test fixture')
|
||||||
|
}, { auto: true } ],
|
||||||
|
|
||||||
|
automaticWorkerFixture: [ async ({}, runTest, workerInfo) => {
|
||||||
|
await runTest();
|
||||||
|
expect(workerInfo.workerIndex).toBe(0);
|
||||||
|
console.log('success worker fixture')
|
||||||
|
}, { scope: 'worker', auto: true } ],
|
||||||
|
});
|
||||||
|
test.skip(({ }) => false);
|
||||||
|
test('good', async ({ }) => {
|
||||||
|
});
|
||||||
|
`
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.output).toContain('success test fixture');
|
||||||
|
expect(result.output).toContain('success worker fixture');
|
||||||
|
expect(result.results.map(r => r.status)).toEqual(['passed']);
|
||||||
|
});
|
||||||
|
|
||||||
test('tests does not run non-automatic worker fixtures', async ({ runInlineTest }) => {
|
test('tests does not run non-automatic worker fixtures', async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.test.js': `
|
'a.test.js': `
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue