(
runner: VitestRunner,
userFixtures: UserFixtures,
supportNonTest: boolean,
registrations = new Map<string, TestFixtureItem>(this._registrations),
)
| 116 | } |
| 117 | |
| 118 | private parseUserFixtures( |
| 119 | runner: VitestRunner, |
| 120 | userFixtures: UserFixtures, |
| 121 | supportNonTest: boolean, |
| 122 | registrations = new Map<string, TestFixtureItem>(this._registrations), |
| 123 | ) { |
| 124 | const errors: Error[] = [] |
| 125 | |
| 126 | Object.entries(userFixtures).forEach(([name, fn]) => { |
| 127 | let options: FixtureOptions | undefined |
| 128 | let value: unknown | undefined |
| 129 | let _options: FixtureOptions | undefined |
| 130 | |
| 131 | if ( |
| 132 | Array.isArray(fn) |
| 133 | && fn.length >= 2 |
| 134 | && TestFixtures.isFixtureOptions(fn[1]) |
| 135 | ) { |
| 136 | _options = fn[1] as FixtureOptions |
| 137 | options = { |
| 138 | auto: _options.auto ?? false, |
| 139 | scope: _options.scope ?? 'test', |
| 140 | injected: _options.injected ?? false, |
| 141 | } |
| 142 | value = options.injected |
| 143 | ? (runner.injectValue?.(name) ?? fn[0]) |
| 144 | : fn[0] |
| 145 | } |
| 146 | else { |
| 147 | value = fn |
| 148 | } |
| 149 | |
| 150 | const parent = registrations.get(name) |
| 151 | if (parent && options) { |
| 152 | if (parent.scope !== options.scope) { |
| 153 | errors.push(new FixtureDependencyError(`The "${name}" fixture was already registered with a "${options.scope}" scope.`)) |
| 154 | } |
| 155 | if (parent.auto !== options.auto) { |
| 156 | errors.push(new FixtureDependencyError(`The "${name}" fixture was already registered as { auto: ${options.auto} }.`)) |
| 157 | } |
| 158 | } |
| 159 | else if (parent) { |
| 160 | options = { |
| 161 | auto: parent.auto, |
| 162 | scope: parent.scope, |
| 163 | injected: parent.injected, |
| 164 | } |
| 165 | } |
| 166 | else if (!options) { |
| 167 | options = { |
| 168 | auto: false, |
| 169 | injected: false, |
| 170 | scope: 'test', |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | if (options.scope && !TestFixtures._fixtureScopes.includes(options.scope)) { |
| 175 | errors.push(new FixtureDependencyError(`The "${name}" fixture has unknown scope "${options.scope}".`)) |
no test coverage detected