(contents)
| 244 | } |
| 245 | |
| 246 | function extractTestInstructions(contents) { |
| 247 | if (!contents) { |
| 248 | return ''; |
| 249 | } |
| 250 | |
| 251 | let tree = unified().use(remarkParse).parse(contents); |
| 252 | |
| 253 | let collecting = false; |
| 254 | let headingDepth = null; |
| 255 | let collected = []; |
| 256 | |
| 257 | for (let node of tree.children) { |
| 258 | if (node.type === 'heading') { |
| 259 | let text = getHeadingText(node).toLowerCase(); |
| 260 | |
| 261 | if (/test(?:ing)? instructions?/.test(text)) { |
| 262 | collecting = true; |
| 263 | headingDepth = node.depth; |
| 264 | continue; |
| 265 | } |
| 266 | |
| 267 | // Stop when we reach another heading of same or higher level |
| 268 | if (collecting && node.depth <= headingDepth) { |
| 269 | break; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if (collecting) { |
| 274 | collected.push(node); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | return collected |
| 279 | .map(node => toString(node)) |
| 280 | .join(' ') |
| 281 | .replace(/\r\n/g, '\n') |
| 282 | .replace(/\s+/g, ' ') |
| 283 | .trim(); |
| 284 | } |
| 285 | |
| 286 | function escapeCSV(value) { |
| 287 | if (!value) { |
no test coverage detected