mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
added comparison output file option to test tools
This commit is contained in:
parent
69afb1175d
commit
45aae25681
1 changed files with 26 additions and 18 deletions
|
@ -145,13 +145,18 @@ const captureSimilarityExtrinsic = (currentCaptures, referenceCaptures) => {
|
|||
return result;
|
||||
};
|
||||
|
||||
const writeCaptures = (name, obj) => {
|
||||
const writeResult = (name, obj) => {
|
||||
try {
|
||||
fs.mkdirSync(comparePath, { recursive: true });
|
||||
} catch (err) {
|
||||
if (err.code !== 'EEXIST') throw err;
|
||||
}
|
||||
fs.writeFileSync(`${comparePath}/${name}.json`, compactStringify(obj, { maxLength: 100 }), 'utf8');
|
||||
|
||||
if (typeof obj === 'string') {
|
||||
fs.writeFileSync(`${comparePath}/${name}.md`, obj, 'utf8');
|
||||
} else {
|
||||
fs.writeFileSync(`${comparePath}/${name}.json`, compactStringify(obj, { maxLength: 100 }), 'utf8');
|
||||
}
|
||||
};
|
||||
|
||||
const toMatchExtrinsics = {
|
||||
|
@ -242,34 +247,37 @@ const comparisonReport = (capturesDev, capturesBuild, buildVersion, save) => {
|
|||
|
||||
const overlapChange = (totalOverlapDev / (totalOverlapBuild || 1)) - 1;
|
||||
|
||||
if (save) {
|
||||
writeCaptures('examples-dev', devIntrinsicsChanged);
|
||||
writeCaptures('examples-build', buildIntrinsicsChanged);
|
||||
}
|
||||
|
||||
return [
|
||||
const report = (breakEvery, format) => [
|
||||
[`Output comparison of ${similarityEntries.length}`,
|
||||
`examples against ${color('matter-js@' + buildVersion, colors.Yellow)} build on last run`
|
||||
`examples against ${format('matter-js@' + buildVersion, colors.Yellow)} build on last run`
|
||||
].join(' '),
|
||||
`\n\n${color('Similarity', colors.White)}`,
|
||||
`${color(toPercent(similarityAvg), similarityAvg === 1 ? colors.Green : colors.Yellow)}%`,
|
||||
`${color('Performance', colors.White)}`,
|
||||
`${color((perfChange >= 0 ? '+' : '') + toPercent(perfChange), perfChange >= 0 ? colors.Green : colors.Red)}%`,
|
||||
`${color('Overlap', colors.White)}`,
|
||||
`${color((overlapChange >= 0 ? '+' : '') + toPercent(overlapChange), overlapChange > 0 ? colors.Red : colors.Green)}%`,
|
||||
`\n\n${format('Similarity', colors.White)}`,
|
||||
`${format(toPercent(similarityAvg), similarityAvg === 1 ? colors.Green : colors.Yellow)}%`,
|
||||
`${format('Performance', colors.White)}`,
|
||||
`${format((perfChange >= 0 ? '+' : '') + toPercent(perfChange), perfChange >= 0 ? colors.Green : colors.Red)}%`,
|
||||
`${format('Overlap', colors.White)}`,
|
||||
`${format((overlapChange >= 0 ? '+' : '') + toPercent(overlapChange), overlapChange > 0 ? colors.Red : colors.Green)}%`,
|
||||
capturePerformance.reduce((output, p, i) => {
|
||||
output += `${p.name} `;
|
||||
output += `${similarityRatings(similaritys[p.name])} `;
|
||||
output += `${changeRatings(capturesDev[p.name].changedIntrinsics)} `;
|
||||
if (i > 0 && i < capturePerformance.length && i % 5 === 0) {
|
||||
if (i > 0 && i < capturePerformance.length && breakEvery > 0 && i % breakEvery === 0) {
|
||||
output += '\n';
|
||||
}
|
||||
return output;
|
||||
}, '\n\n'),
|
||||
`\nwhere · no change ● extrinsics changed ◆ intrinsics changed\n`,
|
||||
similarityAvg < 1 ? `\n${color('▶', colors.White)} ${color(compareCommand + '=' + 120 + '#' + similarityEntries[0][0], colors.BrightCyan)}` : '',
|
||||
intrinsicChangeCount > 0 ? `\n${color('▶', colors.White)} ${color((save ? diffCommand : diffSaveCommand), colors.BrightCyan)}` : ''
|
||||
similarityAvg < 1 ? `\n${format('▶', colors.White)} ${format(compareCommand + '=' + 120 + '#' + similarityEntries[0][0], colors.BrightCyan)}` : '',
|
||||
intrinsicChangeCount > 0 ? `\n${format('▶', colors.White)} ${format((save ? diffCommand : diffSaveCommand), colors.BrightCyan)}` : ''
|
||||
].join(' ');
|
||||
|
||||
if (save) {
|
||||
writeResult('examples-dev', devIntrinsicsChanged);
|
||||
writeResult('examples-build', buildIntrinsicsChanged);
|
||||
writeResult('examples-report', report(5, s => s));
|
||||
}
|
||||
|
||||
return report(5, color);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Reference in a new issue