MCPcopy
hub / github.com/Doorman11991/smallcode / parseMocha

Function parseMocha

src/tools/run_tests.js:228–246  ·  view source on GitHub ↗
(output)

Source from the content-addressed store, hash-verified

226}
227
228function parseMocha(output) {
229 const result = { passed: 0, failed: 0, errors: 0, skipped: 0, failures: [] };
230
231 const passingLine = output.match(/(\d+) passing/); if (passingLine) result.passed = parseInt(passingLine[1], 10);
232 const failingLine = output.match(/(\d+) failing/); if (failingLine) result.failed = parseInt(failingLine[1], 10);
233 const pendingLine = output.match(/(\d+) pending/); if (pendingLine) result.skipped = parseInt(pendingLine[1], 10);
234
235 // " N) test suite title:"
236 const failHeaderRe = /^\s+\d+\)\s+(.+):?\s*$/mg;
237 let m;
238 while ((m = failHeaderRe.exec(output)) !== null) {
239 // Next non-empty line is usually the error message
240 const rest = output.slice(m.index + m[0].length);
241 const msgLine = rest.split('\n').find(l => l.trim().length > 0);
242 result.failures.push({ name: m[1].trim(), message: (msgLine || '').trim().slice(0, 200) });
243 }
244
245 return result;
246}
247
248function parseNodeTest(output) {
249 // TAP-like output from node:test

Callers 2

run_tests.test.jsFile · 0.85
parseOutputFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected