From b979862b08d27e091545724095c3f4c027a2a91d Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Tue, 21 Nov 2023 18:27:39 +0100 Subject: [PATCH] Reuse log prefix colors if we run out Signed-off-by: Thomas Scholtes --- tests/support/logPrefix.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/support/logPrefix.ts b/tests/support/logPrefix.ts index 8de5b7a96..a517618f8 100644 --- a/tests/support/logPrefix.ts +++ b/tests/support/logPrefix.ts @@ -21,15 +21,14 @@ const availableColors: ColorName[] = [ "cyan", ]; +let nextColorIndex = 0; + const assignedColors: Record = {}; export function logPrefix(label: string): string { if (assignedColors[label] === undefined) { - const color = availableColors.pop(); - if (!color) { - throw new Error("We're out of colors. 🤷"); - } - + const color = availableColors[nextColorIndex]; + nextColorIndex = (nextColorIndex + 1) % availableColors.length; assignedColors[label] = color; }