11import { randomUUID } from 'node:crypto' ;
2- import { TEST_RUNTIMES , defaultRuntime } from './constants' ;
2+ import {
3+ TEST_RUNTIMES ,
4+ defaultRuntime ,
5+ TEST_ARCHITECTURES ,
6+ defaultArchitecture ,
7+ } from './constants' ;
38
49const isValidRuntimeKey = (
510 runtime : string
@@ -15,6 +20,21 @@ const getRuntimeKey = (): keyof typeof TEST_RUNTIMES => {
1520 return runtime ;
1621} ;
1722
23+ const isValidArchitectureKey = (
24+ architecture : string
25+ ) : architecture is keyof typeof TEST_ARCHITECTURES =>
26+ architecture in TEST_ARCHITECTURES ;
27+
28+ const getArchitectureKey = ( ) : keyof typeof TEST_ARCHITECTURES => {
29+ const architecture : string = process . env . ARCH || defaultArchitecture ;
30+
31+ if ( ! isValidArchitectureKey ( architecture ) ) {
32+ throw new Error ( `Invalid architecture key value: ${ architecture } ` ) ;
33+ }
34+
35+ return architecture ;
36+ } ;
37+
1838/**
1939 * Generate a unique name for a test.
2040 *
@@ -23,10 +43,11 @@ const getRuntimeKey = (): keyof typeof TEST_RUNTIMES => {
2343 * @example
2444 * ```ts
2545 * process.env.RUNTIME = 'nodejs18x';
26- * const testPrefix = 'E2E-TRACER';
46+ * process.env.ARCH = 'x86_64';
47+ * const testPrefix = 'TRACER';
2748 * const testName = 'someFeature';
2849 * const uniqueName = generateTestUniqueName({ testPrefix, testName });
29- * // uniqueName = 'E2E- TRACER-node18 -12345-someFeature'
50+ * // uniqueName = 'TRACER-18-x86 -12345-someFeature'
3051 * ```
3152 */
3253const generateTestUniqueName = ( {
@@ -38,7 +59,8 @@ const generateTestUniqueName = ({
3859} ) : string =>
3960 [
4061 testPrefix ,
41- getRuntimeKey ( ) . replace ( / [ j s x ] / g, '' ) ,
62+ getRuntimeKey ( ) . replace ( / [ n o d e j s x ] / g, '' ) ,
63+ getArchitectureKey ( ) . replace ( / _ 6 4 / g, '' ) ,
4264 randomUUID ( ) . toString ( ) . substring ( 0 , 5 ) ,
4365 testName ,
4466 ]
@@ -81,4 +103,5 @@ export {
81103 generateTestUniqueName ,
82104 concatenateResourceName ,
83105 findAndGetStackOutputValue ,
106+ getArchitectureKey ,
84107} ;
0 commit comments