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;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const writeCaptures = (name, obj) => {
|
const writeResult = (name, obj) => {
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(comparePath, { recursive: true });
|
fs.mkdirSync(comparePath, { recursive: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code !== 'EEXIST') throw err;
|
if (err.code !== 'EEXIST') throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof obj === 'string') {
|
||||||
|
fs.writeFileSync(`${comparePath}/${name}.md`, obj, 'utf8');
|
||||||
|
} else {
|
||||||
fs.writeFileSync(`${comparePath}/${name}.json`, compactStringify(obj, { maxLength: 100 }), 'utf8');
|
fs.writeFileSync(`${comparePath}/${name}.json`, compactStringify(obj, { maxLength: 100 }), 'utf8');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const toMatchExtrinsics = {
|
const toMatchExtrinsics = {
|
||||||
|
@ -242,34 +247,37 @@ const comparisonReport = (capturesDev, capturesBuild, buildVersion, save) => {
|
||||||
|
|
||||||
const overlapChange = (totalOverlapDev / (totalOverlapBuild || 1)) - 1;
|
const overlapChange = (totalOverlapDev / (totalOverlapBuild || 1)) - 1;
|
||||||
|
|
||||||
if (save) {
|
const report = (breakEvery, format) => [
|
||||||
writeCaptures('examples-dev', devIntrinsicsChanged);
|
|
||||||
writeCaptures('examples-build', buildIntrinsicsChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
[`Output comparison of ${similarityEntries.length}`,
|
[`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(' '),
|
].join(' '),
|
||||||
`\n\n${color('Similarity', colors.White)}`,
|
`\n\n${format('Similarity', colors.White)}`,
|
||||||
`${color(toPercent(similarityAvg), similarityAvg === 1 ? colors.Green : colors.Yellow)}%`,
|
`${format(toPercent(similarityAvg), similarityAvg === 1 ? colors.Green : colors.Yellow)}%`,
|
||||||
`${color('Performance', colors.White)}`,
|
`${format('Performance', colors.White)}`,
|
||||||
`${color((perfChange >= 0 ? '+' : '') + toPercent(perfChange), perfChange >= 0 ? colors.Green : colors.Red)}%`,
|
`${format((perfChange >= 0 ? '+' : '') + toPercent(perfChange), perfChange >= 0 ? colors.Green : colors.Red)}%`,
|
||||||
`${color('Overlap', colors.White)}`,
|
`${format('Overlap', colors.White)}`,
|
||||||
`${color((overlapChange >= 0 ? '+' : '') + toPercent(overlapChange), overlapChange > 0 ? colors.Red : colors.Green)}%`,
|
`${format((overlapChange >= 0 ? '+' : '') + toPercent(overlapChange), overlapChange > 0 ? colors.Red : colors.Green)}%`,
|
||||||
capturePerformance.reduce((output, p, i) => {
|
capturePerformance.reduce((output, p, i) => {
|
||||||
output += `${p.name} `;
|
output += `${p.name} `;
|
||||||
output += `${similarityRatings(similaritys[p.name])} `;
|
output += `${similarityRatings(similaritys[p.name])} `;
|
||||||
output += `${changeRatings(capturesDev[p.name].changedIntrinsics)} `;
|
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';
|
output += '\n';
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}, '\n\n'),
|
}, '\n\n'),
|
||||||
`\nwhere · no change ● extrinsics changed ◆ intrinsics changed\n`,
|
`\nwhere · no change ● extrinsics changed ◆ intrinsics changed\n`,
|
||||||
similarityAvg < 1 ? `\n${color('▶', colors.White)} ${color(compareCommand + '=' + 120 + '#' + similarityEntries[0][0], colors.BrightCyan)}` : '',
|
similarityAvg < 1 ? `\n${format('▶', colors.White)} ${format(compareCommand + '=' + 120 + '#' + similarityEntries[0][0], colors.BrightCyan)}` : '',
|
||||||
intrinsicChangeCount > 0 ? `\n${color('▶', colors.White)} ${color((save ? diffCommand : diffSaveCommand), colors.BrightCyan)}` : ''
|
intrinsicChangeCount > 0 ? `\n${format('▶', colors.White)} ${format((save ? diffCommand : diffSaveCommand), colors.BrightCyan)}` : ''
|
||||||
].join(' ');
|
].join(' ');
|
||||||
|
|
||||||
|
if (save) {
|
||||||
|
writeResult('examples-dev', devIntrinsicsChanged);
|
||||||
|
writeResult('examples-build', buildIntrinsicsChanged);
|
||||||
|
writeResult('examples-report', report(5, s => s));
|
||||||
|
}
|
||||||
|
|
||||||
|
return report(5, color);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in a new issue