* Extract the multi-line block for a field under `fields:`. * Returns all lines belonging to that field definition (from the field name * line up to the next sibling field or end of fields section).
(yaml: string, fieldName: string)
| 35 | * line up to the next sibling field or end of fields section). |
| 36 | */ |
| 37 | function getFieldBlock(yaml: string, fieldName: string): string | undefined { |
| 38 | const lines = yaml.split("\n"); |
| 39 | // Find the field line at exactly 2-space indent under fields: |
| 40 | const fieldRe = new RegExp(`^ ${fieldName}:`); |
| 41 | const startIdx = lines.findIndex((l) => fieldRe.test(l)); |
| 42 | if (startIdx === -1) return undefined; |
| 43 | |
| 44 | const result: string[] = [lines[startIdx]]; |
| 45 | for (let i = startIdx + 1; i < lines.length; i++) { |
| 46 | const line = lines[i]; |
| 47 | // Stop at next sibling field (2-space indent, non-empty) or section boundary |
| 48 | if (line.match(/^ \S/) || line.match(/^[a-z]/)) break; |
| 49 | // Include deeper-indented lines and blank lines within the block |
| 50 | if (line.match(/^\s{4,}/) || line === "") { |
| 51 | result.push(line); |
| 52 | } else { |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | return result.join("\n"); |
| 57 | } |
| 58 | |
| 59 | function createMockPlugin(overrides: Record<string, any> = {}): any { |
| 60 | const settings = { |
no outgoing calls
no test coverage detected