node/lib/internal/test_runner/reporter/rerun.js
Moshe Atlow 64355ae97e
test_runner: add option to rerun only failed tests
PR-URL: https://github.com/nodejs/node/pull/59443
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2025-08-19 07:42:00 +00:00

41 lines
1.1 KiB
JavaScript

'use strict';
const {
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 };
for await (const { type, data } of source) {
if (type === 'test:pass') {
let identifier = `${relative(globalOptions.cwd, data.file)}:${data.line}:${data.column}`;
if (disambiguator[identifier] !== undefined) {
identifier += `:(${disambiguator[identifier]})`;
disambiguator[identifier] += 1;
} else {
disambiguator[identifier] = 1;
}
obj[identifier] = {
__proto__: null,
name: data.name,
passed_on_attempt: data.details.passed_on_attempt ?? data.details.attempt,
};
}
}
ArrayPrototypePush(previousRuns, obj);
writeFileSync(globalOptions.rerunFailuresFilePath, JSONStringify(previousRuns, null, 2), 'utf8');
};
};
module.exports = {
__proto__: null,
reportReruns,
};