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