(script: string)
| 68 | |
| 69 | // fallow-ignore-next-line complexity |
| 70 | export function readReplayScriptMetadata(script: string): ReplayScriptMetadata { |
| 71 | const lines = script.split(/\r?\n/); |
| 72 | const metadata: ReplayScriptMetadata = {}; |
| 73 | for (const [index, line] of lines.entries()) { |
| 74 | const trimmed = line.trim(); |
| 75 | if (trimmed.length === 0 || trimmed.startsWith('#')) continue; |
| 76 | if (isReplayEnvLine(trimmed)) { |
| 77 | ingestEnvLine(metadata, trimmed, index + 1); |
| 78 | continue; |
| 79 | } |
| 80 | if (!trimmed.startsWith('context ')) break; |
| 81 | const platformMatch = trimmed.match(/(?:^|\s)platform=([^\s]+)/); |
| 82 | if (platformMatch) { |
| 83 | const platform = platformMatch[1] as ReplayScriptPlatform | undefined; |
| 84 | if (platform && REPLAY_METADATA_PLATFORMS.has(platform)) { |
| 85 | assignReplayMetadataValue(metadata, 'platform', platform); |
| 86 | } |
| 87 | } |
| 88 | const targetMatch = trimmed.match(/(?:^|\s)target=([^\s]+)/); |
| 89 | if (targetMatch) { |
| 90 | const target = targetMatch[1] as DeviceTarget | undefined; |
| 91 | if (target && REPLAY_METADATA_TARGETS.has(target)) { |
| 92 | assignReplayMetadataValue(metadata, 'target', target); |
| 93 | } |
| 94 | } |
| 95 | const timeoutMatch = trimmed.match(/(?:^|\s)timeout=(\d+)/); |
| 96 | if (timeoutMatch) { |
| 97 | const timeoutMs = Number(timeoutMatch[1]); |
| 98 | if (Number.isFinite(timeoutMs) && timeoutMs >= 1) { |
| 99 | assignReplayMetadataValue(metadata, 'timeoutMs', Math.floor(timeoutMs)); |
| 100 | } |
| 101 | } |
| 102 | const retriesMatch = trimmed.match(/(?:^|\s)retries=(\d+)/); |
| 103 | if (retriesMatch) { |
| 104 | const retries = Number(retriesMatch[1]); |
| 105 | if (Number.isFinite(retries) && retries >= 0) { |
| 106 | assignReplayMetadataValue(metadata, 'retries', Math.floor(retries)); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | return metadata; |
| 111 | } |
| 112 | |
| 113 | function isReplayEnvLine(trimmed: string): boolean { |
| 114 | return trimmed === 'env' || trimmed.startsWith('env ') || trimmed.startsWith('env\t'); |
no test coverage detected