(spec?: string)
| 82 | * typoed bench env var would be worse than running with system time. |
| 83 | */ |
| 84 | export function resolveClockSources(spec?: string): ClockSources { |
| 85 | if (spec === undefined || spec === '' || spec === 'system') { |
| 86 | return SYSTEM_CLOCKS; |
| 87 | } |
| 88 | |
| 89 | if (spec.startsWith('file:')) { |
| 90 | const filePath = spec.slice('file:'.length); |
| 91 | if (filePath === '') { |
| 92 | debugInvalidSpec(spec, 'empty file path'); |
| 93 | return SYSTEM_CLOCKS; |
| 94 | } |
| 95 | return { |
| 96 | wallNow: () => readFileWall(filePath), |
| 97 | monoNowMs: systemMonoNowMs, |
| 98 | }; |
| 99 | } |
| 100 | |
| 101 | debugInvalidSpec(spec, 'unrecognised scheme'); |
| 102 | return SYSTEM_CLOCKS; |
| 103 | } |
| 104 | |
| 105 | // Epoch-ms is always under 20 characters in practice; 64 bytes leaves |
| 106 | // slack for a leading newline / `\r` and prevents OOM on a hostile or |
no test coverage detected