Skip to content

Commit 535ca1f

Browse files
committed
Sort tests by name when creating servo score report
Signed-off-by: Nico Burns <[email protected]>
1 parent db2b77e commit 535ca1f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,41 @@ async function process_chunks (path) {
5959
delete scored_chunk.run_info
6060
result = merge_nonoverlap(result, scored_chunk)
6161
}
62+
63+
sort_test_results(result)
64+
6265
return result
6366
}
6467

68+
// Sorts the keys of the test_scores object alphabetically
69+
function sort_test_results (result) {
70+
result.test_scores = sort_object(result.test_scores)
71+
}
72+
73+
// Sorts the keys of an objects
74+
//
75+
// JS objects serialize keys in insertion order, so to control the order of JSON serialized output
76+
// we can:
77+
//
78+
// - Convert the object into an array
79+
// - Sort the array by test object key
80+
// - Reinsert the results into a new object in order
81+
function sort_object (obj) {
82+
const arr = Object.entries(obj).map(([key, value]) => ({ key, value }))
83+
arr.sort((a, b) => {
84+
if (a.key < b.key) return -1
85+
if (a.key > b.key) return 1
86+
return 0
87+
})
88+
89+
const obj2 = {}
90+
for (const entry of arr) {
91+
obj2[entry.key] = entry.value
92+
}
93+
94+
return obj2
95+
}
96+
6597
async function add_run (runs_dir, chunks_dir, date) {
6698
const new_run = await process_chunks(chunks_dir)
6799
await write_compressed(`./${runs_dir}/${date}.xz`, new_run)

0 commit comments

Comments
 (0)