[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

refactor: add `isFixtureOptions` (#9819)

authored by

Vladimir and committed by
GitHub
(Mar 19, 2026, 11:18 AM +0100) 9ae316e1 321e7ccc

+6 -19
+5 -2
packages/runner/src/fixture.ts
··· 50 50 return TestFixtures._definitions.map(f => f.getFileContext(file)) 51 51 } 52 52 53 + static isFixtureOptions(obj: unknown): boolean { 54 + return isObject(obj) && Object.keys(obj as any).some(key => TestFixtures._fixtureOptionKeys.includes(key)) 55 + } 56 + 53 57 constructor(registrations?: FixtureRegistrations) { 54 58 this._registrations = registrations ?? new Map() 55 59 this._suiteContexts = new WeakMap() ··· 127 131 if ( 128 132 Array.isArray(fn) 129 133 && fn.length >= 2 130 - && isObject(fn[1]) 131 - && Object.keys(fn[1]).some(key => TestFixtures._fixtureOptionKeys.includes(key)) 134 + && TestFixtures.isFixtureOptions(fn[1]) 132 135 ) { 133 136 _options = fn[1] as FixtureOptions 134 137 options = {
+1 -1
packages/runner/src/suite.ts
··· 867 867 optionsOrFn !== null 868 868 && typeof optionsOrFn === 'object' 869 869 && !Array.isArray(optionsOrFn) 870 - && ('scope' in optionsOrFn || 'auto' in optionsOrFn) 870 + && TestFixtures.isFixtureOptions(optionsOrFn) 871 871 ) { 872 872 // (name, options) with no value - treat as empty object fixture 873 873 fixtureOptions = optionsOrFn as object
-16
test/cli/test/scoped-fixtures.test.ts
··· 1812 1812 expect(tests).toMatchInlineSnapshot(`" ✓ basic.test.ts > non-function values work <time>"`) 1813 1813 }) 1814 1814 1815 - test('object with injected is treated as an object', async () => { 1816 - const { stderr, tests } = await runFixtureTests(({}) => { 1817 - return it 1818 - .extend('object', { injected: true }) 1819 - }, { 1820 - 'basic.test.ts': ({ extendedTest, expect, expectTypeOf }) => { 1821 - extendedTest('object with injected is treated as an object', ({ object }) => { 1822 - expectTypeOf(object).toEqualTypeOf<{ injected: boolean }>() 1823 - expect(object).toEqual({ injected: true }) 1824 - }) 1825 - }, 1826 - }) 1827 - expect(stderr).toBe('') 1828 - expect(tests).toMatchInlineSnapshot(`" ✓ basic.test.ts > object with injected is treated as an object <time>"`) 1829 - }) 1830 - 1831 1815 test('non-function values with injected option work', async () => { 1832 1816 const { stderr, tests } = await runFixtureTests(({ expectTypeOf }) => { 1833 1817 return it