/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/internal/test_runner/reporter/rerun.js
81 строка
2 KB
atlowChemi
test_runner: fix --test-rerun-failures swallowing failures on retry
24 май 2026, 10:29
Не верифицирован
24 май 2026, 10:29
74ccf38
Код
Авторство
О чём код?
'use strict'; const { ArrayPrototypeMap, ArrayPrototypePush, JSONStringify, } = primordials; const { relative } = require('path'); const { writeFileSync } = require('fs'); function reportReruns(previousRuns, globalOptions) { return async function reporter(source) { const obj = { __proto__: null }; const disambiguator = { __proto__: null }; let currentSuite = null; const roots = []; function getTestId(data) { return `${relative(globalOptions.cwd, data.file)}:${data.line}:${data.column}`; } function startTest(data) { const originalSuite = currentSuite; currentSuite = { __proto__: null, data, parent: currentSuite, children: [] }; if (originalSuite?.children) { ArrayPrototypePush(originalSuite.children, currentSuite); } if (!currentSuite.parent) { ArrayPrototypePush(roots, currentSuite); } } for await (const { type, data } of source) { let currentTest; if (type === 'test:start') { startTest(data); } else if (type === 'test:fail' || type === 'test:pass') { if (!currentSuite) { startTest({ __proto__: null, name: 'root', nesting: 0 }); } if (currentSuite.data.name !== data.name || currentSuite.data.nesting !== data.nesting) { startTest(data); } currentTest = currentSuite; if (currentSuite?.data.nesting === data.nesting) { currentSuite = currentSuite.parent; } } if (type === 'test:pass' || type === 'test:fail') { const baseIdentifier = getTestId(data); let identifier = baseIdentifier; if (disambiguator[baseIdentifier] !== undefined) { identifier += `:(${disambiguator[baseIdentifier]})`; disambiguator[baseIdentifier] += 1; } else { disambiguator[baseIdentifier] = 1; } if (type === 'test:pass') { const children = ArrayPrototypeMap(currentTest.children, (child) => child.data); obj[identifier] = { __proto__: null, name: data.name, children, passed_on_attempt: data.details.passed_on_attempt ?? data.details.attempt, duration_ms: data.details.duration_ms, }; } } } ArrayPrototypePush(previousRuns, obj); writeFileSync(globalOptions.rerunFailuresFilePath, JSONStringify(previousRuns, null, 2), 'utf8'); }; }; module.exports = { __proto__: null, reportReruns, };