Skip to content

Commit 3397fdc

Browse files
authored
fix: support accessing task from test context without accessing fixtures (#4419)
1 parent 1ecbe74 commit 3397fdc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/runner/src/fixture.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export function withFixtures(fn: Function, testContext?: TestContext) {
7474

7575
const usedFixtures = fixtures.filter(({ prop }) => usedProps.includes(prop))
7676
const pendingFixtures = resolveDeps(usedFixtures)
77+
78+
if (!pendingFixtures.length)
79+
return fn(context)
80+
7781
let cursor = 0
7882

7983
return new Promise((resolve, reject) => {

test/core/test/fixture-initialization.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Use } from '@vitest/runner'
2-
import { describe, expect, expectTypeOf, test, vi } from 'vitest'
2+
import { beforeEach, describe, expect, expectTypeOf, test, vi } from 'vitest'
33

44
interface Fixtures {
55
a: number
@@ -179,4 +179,16 @@ describe('fixture initialization', () => {
179179
expect(archive.length).toBe(1)
180180
})
181181
})
182+
183+
describe('accessing non-fixture context', () => {
184+
const myTest = test.extend({ a: 1 })
185+
186+
beforeEach(async ({ task }) => {
187+
expect(task).toBeTruthy()
188+
})
189+
190+
myTest('non-fixture context can be accessed without accessing fixtures', ({ task }) => {
191+
expect(task).toBeTruthy()
192+
})
193+
})
182194
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy