go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/test_verdict/tools/utils/utils.ts (about) 1 // Copyright 2023 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import { ORDERED_VARIANT_DEF_KEYS } from '@/common/constants/test'; 16 17 /** 18 * Parses the test result name and get the individual components. 19 */ 20 export function parseTestResultName(name: string) { 21 const match = name.match( 22 /^invocations\/(.*?)\/tests\/(.*?)\/results\/(.*?)$/, 23 ); 24 if (!match) { 25 throw new Error(`invalid test result name: ${name}`); 26 } 27 28 const [, invocationId, testId, resultId] = match; 29 return { 30 invocationId, 31 testId: decodeURIComponent(testId), 32 resultId, 33 }; 34 } 35 36 export function getSortedTestVariantDef(def: { [key: string]: string }) { 37 const res: Array<[string, string]> = []; 38 const seen = new Set(); 39 for (const key of ORDERED_VARIANT_DEF_KEYS) { 40 if (Object.prototype.hasOwnProperty.call(def, key)) { 41 res.push([key, def[key]]); 42 seen.add(key); 43 } 44 } 45 for (const [key, value] of Object.entries(def)) { 46 if (!seen.has(key)) { 47 res.push([key, value]); 48 } 49 } 50 return res; 51 }