Skip to content

Commit

Permalink
fix: support accessing task from test context without accessing fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyddall committed Nov 1, 2023
1 parent 9021e8b commit f184ad2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/runner/src/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export function withFixtures(fn: Function, testContext?: TestContext) {

const usedFixtures = fixtures.filter(({ prop }) => usedProps.includes(prop))
const pendingFixtures = resolveDeps(usedFixtures)

if (!pendingFixtures.length)
return fn(context)

let cursor = 0

return new Promise((resolve, reject) => {
Expand Down
14 changes: 13 additions & 1 deletion test/core/test/fixture-initialization.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Use } from '@vitest/runner'
import { describe, expect, expectTypeOf, test, vi } from 'vitest'
import { beforeEach, describe, expect, expectTypeOf, test, vi } from 'vitest'

interface Fixtures {
a: number
Expand Down Expand Up @@ -179,4 +179,16 @@ describe('fixture initialization', () => {
expect(archive.length).toBe(1)
})
})

describe('accessing non-fixture context', () => {
const myTest = test.extend({ a: 1 })

beforeEach(async ({ task }) => {
expect(task).toBeTruthy()
})

myTest('non-fixture context can be accessed without accessing fixtures', ({ task }) => {
expect(task).toBeTruthy()
})
})
})

0 comments on commit f184ad2

Please sign in to comment.