Implement solve(op, ...args):
| Op | Args | Description |
|---|---|---|
'instrument' | (sourceLines) | Takes an array of source code lines. Returns an instrumented version: a string where each line is prefixed with __cov[lineIndex] = true;. |
'run' | (instrumentedSrc) | Executes the instrumented source. Returns a __cov object mapping line index → true (only for executed lines). |
'report' | (sourceLines, cov) | Returns { total, covered, percent, uncovered } where uncovered is an array of 0-based line indices that were NOT covered. |
const lines = [
'function add(a, b) {',
' return a + b',
'}',
]
const src = solve('instrument', lines)
const cov = solve('run', src + '\nadd(1, 2)')
solve('report', lines, cov)
// { total: 3, covered: 3, percent: 100, uncovered: [] }Blank lines and lines containing only } or { still count toward total.
Sample tests