|
1 | 1 | import axios from 'axios';
|
2 | 2 | import { readJson } from 'fs-extra';
|
3 |
| -import { DefaultBenchCase, getCommitLink, getMetricsPath } from './shared'; |
| 3 | +import { |
| 4 | + DefaultBenchCase, |
| 5 | + ValidMetricsForCase, |
| 6 | + getCommitLink, |
| 7 | + getMetricsPath, |
| 8 | +} from './shared'; |
4 | 9 |
|
5 | 10 | const productName = process.argv[2] || 'MODERNJS_FRAMEWORK';
|
6 | 11 |
|
@@ -30,6 +35,7 @@ function formatValue(value: number, property: string) {
|
30 | 35 | function generateTable(
|
31 | 36 | base: Record<string, number>,
|
32 | 37 | current: Record<string, number>,
|
| 38 | + caseName: string, |
33 | 39 | ) {
|
34 | 40 | const overThresholdTags: string[] = [];
|
35 | 41 | const properties = Object.keys(base);
|
@@ -58,55 +64,65 @@ function generateTable(
|
58 | 64 | ).padEnd(10)} | ${formatValue(current[property], property).padEnd(
|
59 | 65 | 10,
|
60 | 66 | )} | ${formattedPercent.padEnd(10)} |`;
|
61 |
| - table.push(row); |
62 | 67 |
|
63 |
| - if (percent > 5 && !property.includes('InstallTime')) { |
64 |
| - overThresholdTags.push(property); |
| 68 | + if ( |
| 69 | + ValidMetricsForCase[ |
| 70 | + caseName as keyof typeof ValidMetricsForCase |
| 71 | + ]?.includes(property) || |
| 72 | + !ValidMetricsForCase[caseName as keyof typeof ValidMetricsForCase] |
| 73 | + ) { |
| 74 | + table.push(row); |
| 75 | + if (percent > 5 && !property.includes('InstallTime')) { |
| 76 | + overThresholdTags.push(property); |
| 77 | + } |
65 | 78 | }
|
66 | 79 | });
|
67 | 80 |
|
68 | 81 | console.log('');
|
69 | 82 | console.log(table.join('\n'));
|
| 83 | + console.log(''); |
70 | 84 |
|
71 | 85 | return overThresholdTags;
|
72 | 86 | }
|
73 | 87 |
|
74 | 88 | export async function compare(productName: string) {
|
75 |
| - const caseName = |
76 |
| - process.argv[3] || |
77 |
| - DefaultBenchCase[productName as keyof typeof DefaultBenchCase]; |
78 |
| - const { jsonPath, remoteURL } = await getMetricsPath(productName, caseName); |
79 |
| - |
80 |
| - const allMetrics = |
81 |
| - process.env.MONITOR === '1' |
82 |
| - ? (await axios.get(remoteURL)).data |
83 |
| - : await readJson(jsonPath); |
84 |
| - |
85 |
| - let arr = Object.keys(allMetrics).map(key => { |
86 |
| - return { key: key, value: allMetrics[key] }; |
87 |
| - }); |
88 |
| - |
89 |
| - arr.sort((a, b) => a.value.time - b.value.time); |
90 |
| - |
91 |
| - const currentKey = arr[arr.length - 1].key; |
92 |
| - const baseKey = arr[arr.length - 2].key; |
93 |
| - const current = allMetrics[currentKey as any]; |
94 |
| - const base = allMetrics[baseKey as any]; |
95 |
| - const baseCommitLink = getCommitLink(productName, baseKey); |
96 |
| - const currentCommitLink = getCommitLink(productName, currentKey); |
97 |
| - |
98 |
| - console.log(`case: ${caseName}`); |
99 |
| - console.log('base: ', baseCommitLink); |
100 |
| - console.log('current: ', currentCommitLink); |
101 |
| - |
102 |
| - const overThresholdTags = generateTable(base, current); |
103 |
| - |
104 |
| - if (overThresholdTags.length > 0) { |
105 |
| - console.log(''); |
106 |
| - console.log( |
107 |
| - `Threshold exceeded in ${caseName}: `, |
108 |
| - JSON.stringify(overThresholdTags), |
109 |
| - ); |
| 89 | + const cases = DefaultBenchCase[productName as keyof typeof DefaultBenchCase]; |
| 90 | + |
| 91 | + for (const caseName of cases) { |
| 92 | + const { jsonPath, remoteURL } = await getMetricsPath(productName, caseName); |
| 93 | + |
| 94 | + const allMetrics = |
| 95 | + process.env.MONITOR === '1' |
| 96 | + ? (await axios.get(remoteURL)).data |
| 97 | + : await readJson(jsonPath); |
| 98 | + |
| 99 | + let arr = Object.keys(allMetrics).map(key => { |
| 100 | + return { key: key, value: allMetrics[key] }; |
| 101 | + }); |
| 102 | + |
| 103 | + arr.sort((a, b) => a.value.time - b.value.time); |
| 104 | + |
| 105 | + const currentKey = arr[arr.length - 1].key; |
| 106 | + const baseKey = arr[arr.length - 2].key; |
| 107 | + const current = allMetrics[currentKey as any]; |
| 108 | + const base = allMetrics[baseKey as any]; |
| 109 | + const baseCommitLink = getCommitLink(productName, baseKey); |
| 110 | + const currentCommitLink = getCommitLink(productName, currentKey); |
| 111 | + |
| 112 | + console.log(`case: ${caseName}`); |
| 113 | + console.log('base: ', baseCommitLink); |
| 114 | + console.log('current: ', currentCommitLink); |
| 115 | + |
| 116 | + const overThresholdTags = generateTable(base, current, caseName); |
| 117 | + |
| 118 | + if (overThresholdTags.length > 0) { |
| 119 | + console.log(''); |
| 120 | + console.log( |
| 121 | + `Threshold exceeded in ${caseName}: `, |
| 122 | + JSON.stringify(overThresholdTags), |
| 123 | + ); |
| 124 | + console.log(''); |
| 125 | + } |
110 | 126 | }
|
111 | 127 | }
|
112 | 128 |
|
|
0 commit comments