Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support accessing task from test context without accessing fixtures #4419

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
})
})