MCPcopy Create free account
hub / github.com/TanStack/router / validateModeMetadata

Function validateModeMetadata

scripts/nx/playwright-plugin.ts:158–238  ·  view source on GitHub ↗
(
  modeMetadata: RawPlaywrightModeMetadata,
  index: number,
)

Source from the content-addressed store, hash-verified

156}
157
158function validateModeMetadata(
159 modeMetadata: RawPlaywrightModeMetadata,
160 index: number,
161): PlaywrightModeMetadata {
162 const targetName = `${modeMetadata.toolchain ?? '<missing toolchain>'}:${modeMetadata.mode ?? '<missing mode>'}`
163
164 if (!modeMetadata.toolchain || !modeMetadata.mode) {
165 throw new Error(
166 `[Playwright Sharding Plugin] Invalid playwrightModes[${index}] entry: ` +
167 `${JSON.stringify(modeMetadata)}. Both "toolchain" and "mode" are required.`,
168 )
169 }
170
171 if (
172 !PLAYWRIGHT_TOOLCHAINS.includes(
173 modeMetadata.toolchain as PlaywrightToolchain,
174 )
175 ) {
176 throw new Error(
177 `[Playwright Sharding Plugin] Invalid toolchain for playwrightModes[${index}]: ` +
178 `${modeMetadata.toolchain}. Supported toolchains: ${PLAYWRIGHT_TOOLCHAINS.join(', ')}.`,
179 )
180 }
181
182 if (!PLAYWRIGHT_MODES.includes(modeMetadata.mode as PlaywrightMode)) {
183 throw new Error(
184 `[Playwright Sharding Plugin] Invalid mode for playwrightModes[${index}]: ` +
185 `${modeMetadata.mode}. Supported modes: ${PLAYWRIGHT_MODES.join(', ')}.`,
186 )
187 }
188
189 if (modeMetadata.shards !== undefined) {
190 const shardCount = Number(modeMetadata.shards)
191
192 if (!Number.isInteger(shardCount) || shardCount < 1) {
193 throw new Error(
194 `[Playwright Sharding Plugin] Invalid shard count for ${targetName}: ${modeMetadata.shards}. ` +
195 `Expected a positive integer.`,
196 )
197 }
198 }
199
200 if (
201 modeMetadata.name !== undefined &&
202 !/^[a-z0-9][a-z0-9-]*$/.test(modeMetadata.name)
203 ) {
204 throw new Error(
205 `[Playwright Sharding Plugin] Invalid name for playwrightModes[${index}]: ` +
206 `${modeMetadata.name}. Expected lowercase letters, numbers, and dashes.`,
207 )
208 }
209
210 if (modeMetadata.env !== undefined) {
211 if (
212 typeof modeMetadata.env !== 'object' ||
213 Array.isArray(modeMetadata.env)
214 ) {
215 throw new Error(

Callers 1

buildModeTargetsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected