| 26 | import type { Location } from '../../types/testReporter'; |
| 27 | |
| 28 | class Fixture { |
| 29 | runner: FixtureRunner; |
| 30 | registration: fixtures.FixtureRegistration; |
| 31 | value: any; |
| 32 | failed = false; |
| 33 | |
| 34 | private _useFuncFinished: ManualPromise<void> | undefined; |
| 35 | private _selfTeardownComplete: Promise<void> | undefined; |
| 36 | private _setupDescription: FixtureDescription; |
| 37 | private _teardownDescription: FixtureDescription; |
| 38 | private _stepInfo: { title: string, category: 'fixture', location?: Location, group?: string } | undefined; |
| 39 | _deps = new Set<Fixture>(); |
| 40 | _usages = new Set<Fixture>(); |
| 41 | |
| 42 | constructor(runner: FixtureRunner, registration: fixtures.FixtureRegistration) { |
| 43 | this.runner = runner; |
| 44 | this.registration = registration; |
| 45 | this.value = null; |
| 46 | const isUserFixture = this.registration.location && filterStackFile(this.registration.location.file); |
| 47 | const title = this.registration.customTitle || this.registration.name; |
| 48 | const location = isUserFixture ? this.registration.location : undefined; |
| 49 | this._stepInfo = { title: `Fixture ${escapeWithQuotes(title, '"')}`, category: 'fixture', location }; |
| 50 | if (this.registration.box === 'self') |
| 51 | this._stepInfo = undefined; |
| 52 | else if (this.registration.box) |
| 53 | this._stepInfo.group = isUserFixture ? 'configuration' : 'internal'; |
| 54 | this._setupDescription = { |
| 55 | title, |
| 56 | phase: 'setup', |
| 57 | location, |
| 58 | slot: this.registration.timeout !== undefined ? { |
| 59 | timeout: this.registration.timeout, |
| 60 | elapsed: 0, |
| 61 | } : this.registration.scope === 'worker' ? { |
| 62 | timeout: this.runner.workerFixtureTimeout, |
| 63 | elapsed: 0, |
| 64 | } : undefined, |
| 65 | }; |
| 66 | this._teardownDescription = { ...this._setupDescription, phase: 'teardown' }; |
| 67 | } |
| 68 | |
| 69 | async setup(testInfo: TestInfoImpl, runnable: RunnableDescription) { |
| 70 | this.runner.instanceForId.set(this.registration.id, this); |
| 71 | |
| 72 | if (typeof this.registration.fn !== 'function') { |
| 73 | this.value = this.registration.fn; |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | const run = () => testInfo._runWithTimeout({ ...runnable, fixture: this._setupDescription }, () => this._setupInternal(testInfo)); |
| 78 | if (this._stepInfo) |
| 79 | await testInfo._runAsStep(this._stepInfo, run); |
| 80 | else |
| 81 | await run(); |
| 82 | } |
| 83 | |
| 84 | private async _setupInternal(testInfo: TestInfoImpl) { |
| 85 | const params: { [key: string]: any } = {}; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…