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