Skip to content

Commit ce2a06b

Browse files
committed
Revert "feat: draft implementation"
This reverts commit 86010b3.
1 parent 86010b3 commit ce2a06b

File tree

5 files changed

+11
-106
lines changed

5 files changed

+11
-106
lines changed

packages/runner/src/collect.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import type { FixtureItem } from './fixture'
21
import type { FileSpecification, VitestRunner } from './types/runner'
3-
import type { File, SuiteHooks, Task } from './types/tasks'
2+
import type { File, SuiteHooks } from './types/tasks'
43
import { toArray } from '@vitest/utils'
54
import { processError } from '@vitest/utils/error'
65
import { collectorContext } from './context'
7-
import { getHooks, getTestFixture, setHooks, setTestFixture } from './map'
6+
import { getHooks, setHooks } from './map'
87
import { runSetupFiles } from './setup'
98
import {
109
clearCollectorContext,
@@ -105,36 +104,11 @@ export async function collectTests(
105104
}
106105

107106
files.push(file)
108-
109-
// TODO: any
110-
setTestFixture(file.context as any, getFileFixtires(file))
111107
}
112108

113109
return files
114110
}
115111

116-
function getFileFixtires(file: File): FixtureItem[] {
117-
const fixtures = new Set<FixtureItem>()
118-
function traverse(children: Task[]) {
119-
for (const child of children) {
120-
if (child.type === 'test') {
121-
const childFixtures = getTestFixture(child.context) || []
122-
for (const fixture of childFixtures) {
123-
// TODO: what if overriden?
124-
if (fixture.scope === 'file' && !fixtures.has(fixture)) {
125-
fixtures.add(fixture)
126-
}
127-
}
128-
}
129-
else {
130-
traverse(child.tasks)
131-
}
132-
}
133-
}
134-
traverse(file.tasks)
135-
return Array.from(fixtures)
136-
}
137-
138112
function mergeHooks(baseHooks: SuiteHooks, hooks: SuiteHooks): SuiteHooks {
139113
for (const _key in hooks) {
140114
const key = _key as keyof SuiteHooks

packages/runner/src/fixture.ts

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function mergeContextFixtures<T extends { fixtures?: FixtureItem[] }>(
4545
context: T,
4646
inject: (key: string) => unknown,
4747
): T {
48-
const fixtureOptionKeys = ['auto', 'injected', 'scope']
48+
const fixtureOptionKeys = ['auto', 'injected']
4949
const fixtureArray: FixtureItem[] = Object.entries(fixtures).map(
5050
([prop, value]) => {
5151
const fixtureItem = { value } as FixtureItem
@@ -94,11 +94,11 @@ export function mergeContextFixtures<T extends { fixtures?: FixtureItem[] }>(
9494

9595
const fixtureValueMaps = new Map<TestContext, Map<FixtureItem, any>>()
9696
const cleanupFnArrayMap = new Map<
97-
object,
97+
TestContext,
9898
Array<() => void | Promise<void>>
9999
>()
100100

101-
export async function callFixtureCleanup(context: object): Promise<void> {
101+
export async function callFixtureCleanup(context: TestContext): Promise<void> {
102102
const cleanupFnArray = cleanupFnArrayMap.get(context) ?? []
103103
for (const cleanup of cleanupFnArray.reverse()) {
104104
await cleanup()
@@ -153,75 +153,21 @@ export function withFixtures(fn: Function, testContext?: TestContext) {
153153
continue
154154
}
155155

156-
const resolvedValue = await resolveFixtureValue(
157-
fixture,
158-
context!,
159-
cleanupFnArray,
160-
)
156+
const resolvedValue = fixture.isFn
157+
? await resolveFixtureFunction(fixture.value, context, cleanupFnArray)
158+
: fixture.value
161159
context![fixture.prop] = resolvedValue
162160
fixtureValueMap.set(fixture, resolvedValue)
163-
164-
if (!fixture.scope || fixture.scope === 'test') {
165-
cleanupFnArray.unshift(() => {
166-
fixtureValueMap.delete(fixture)
167-
})
168-
}
161+
cleanupFnArray.unshift(() => {
162+
fixtureValueMap.delete(fixture)
163+
})
169164
}
170165
}
171166

172167
return resolveFixtures().then(() => fn(context))
173168
}
174169
}
175170

176-
const fileFixturePromise = new WeakMap<FixtureItem, Promise<unknown>>()
177-
178-
function resolveFixtureValue(
179-
fixture: FixtureItem,
180-
context: TestContext & { [key: string]: any },
181-
cleanupFnArray: (() => void | Promise<void>)[],
182-
) {
183-
if (!fixture.isFn) {
184-
return fixture.value
185-
}
186-
187-
if (!fixture.scope || fixture.scope === 'test') {
188-
return resolveFixtureFunction(
189-
fixture.value,
190-
context,
191-
cleanupFnArray,
192-
)
193-
}
194-
195-
const fileContext = context.task.file.context
196-
197-
if (fixture.prop in fileContext) {
198-
return fileContext[fixture.prop]
199-
}
200-
201-
// in case the test runs in parallel
202-
if (fileFixturePromise.has(fixture)) {
203-
return fileFixturePromise.get(fixture)!
204-
}
205-
206-
if (!cleanupFnArrayMap.has(fileContext)) {
207-
cleanupFnArrayMap.set(fileContext, [])
208-
}
209-
const cleanupFnFileArray = cleanupFnArrayMap.get(fileContext)!
210-
211-
const promise = resolveFixtureFunction(
212-
fixture.value,
213-
fileContext,
214-
cleanupFnFileArray,
215-
).then((value) => {
216-
fileContext[fixture.prop] = value
217-
fileFixturePromise.delete(fixture)
218-
return value
219-
})
220-
221-
fileFixturePromise.set(fixture, promise)
222-
return promise
223-
}
224-
225171
async function resolveFixtureFunction(
226172
fixtureFn: (
227173
context: unknown,

packages/runner/src/run.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,6 @@ export async function runSuite(suite: Suite, runner: VitestRunner): Promise<void
526526
try {
527527
await callSuiteHook(suite, suite, 'afterAll', runner, [suite])
528528
await callCleanupHooks(runner, beforeAllCleanups)
529-
if (suite.file === suite) {
530-
await callFixtureCleanup((suite as File).context)
531-
}
532529
}
533530
catch (e) {
534531
failTask(suite.result, e, runner.config.diffOptions)

packages/runner/src/types/tasks.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ export interface File extends Suite {
239239
* @internal
240240
*/
241241
local?: boolean
242-
/** @internal */
243-
context: Record<string, unknown>
244242
}
245243

246244
export interface Test<ExtraContext = object> extends TaskPopulated {
@@ -481,21 +479,12 @@ export type { TestAPI as CustomAPI }
481479
export interface FixtureOptions {
482480
/**
483481
* Whether to automatically set up current fixture, even though it's not being used in tests.
484-
* @default false
485482
*/
486483
auto?: boolean
487484
/**
488485
* Indicated if the injected value from the config should be preferred over the fixture value
489486
*/
490487
injected?: boolean
491-
/**
492-
* When should the fixture be set up.
493-
* - **test**: fixture will be set up before ever test
494-
* - **worker**: fixture will be set up once per worker
495-
* - **file**: fixture will be set up once per file
496-
* @default 'test'
497-
*/
498-
scope?: 'test' | 'worker' | 'file'
499488
}
500489

501490
export type Use<T> = (value: T) => Promise<void>

packages/runner/src/utils/collect.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ export function createFileTask(
192192
projectName,
193193
file: undefined!,
194194
pool,
195-
context: Object.create(null),
196195
}
197196
file.file = file
198197
return file

0 commit comments

Comments
 (0)