Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Use more descriptive name for making log prefixes
Thomas Scholtes committed 2 years ago
commit de64d7c151a42932b7b0b794a3895f7cfc35f02a
parent 5d4511e3a74fa80bed2b49e60f3ef064a424af96
4 files changed +47 -47
modified tests/support/fixtures.ts
@@ -9,7 +9,7 @@ import { test as base, expect, type ViewportSize } from "@playwright/test";

import * as Process from "./process.js";
import * as issue from "@tests/support/cobs/issue.js";
-
import * as logLabel from "@tests/support/logLabel.js";
+
import * as logLabel from "@tests/support/logPrefix.js";
import * as patch from "@tests/support/cobs/patch.js";
import { createOptions, supportDir, tmpDir } from "@tests/support/support.js";
import { createPeerManager } from "@tests/support/peerManager.js";
@@ -52,7 +52,7 @@ export const test = base.extend<{

  forAllTests: [
    async ({ customAppConfig, outputLog, page }, use) => {
-
      const browserLabel = logLabel.make("browser");
+
      const browserLabel = logLabel.logPrefix("browser");
      page.on("console", msg => {
        // Ignore common console logs that we don't care about.
        if (
@@ -111,7 +111,7 @@ export const test = base.extend<{
        });
      }

-
      const playwrightLabel = logLabel.make("playwright");
+
      const playwrightLabel = logLabel.logPrefix("playwright");

      function isLocalhost(url: URL) {
        return url.hostname === "localhost" || url.hostname === "127.0.0.1";
deleted tests/support/logLabel.ts
@@ -1,42 +0,0 @@
-
import type { ColorName } from "chalk";
-

-
import chalk from "chalk";
-

-
const PADDING_WIDTH = 12;
-

-
// The order here is important, we want successive prefixes to have
-
// high contrast.
-
const availableColors: ColorName[] = [
-
  "blue",
-
  "yellowBright",
-
  "greenBright",
-
  "gray",
-
  "green",
-
  "blueBright",
-
  "redBright",
-
  "white",
-
  "yellow",
-
  "red",
-
  "magenta",
-
  "cyan",
-
];
-

-
const assignedColors: Record<string, ColorName> = {};
-

-
export function make(label: string): string {
-
  if (assignedColors[label] === undefined) {
-
    const color = availableColors.pop();
-
    if (!color) {
-
      throw new Error("We're out of colors. 🤷");
-
    }
-

-
    assignedColors[label] = color;
-
  }
-

-
  // We reset colors at the beginning of each line to avoid styles from previous
-
  // lines messing up prefix colors. This is noticable in rust stack traces
-
  // where the `in` and `with` keywords have a white background color.
-
  return chalk.reset[assignedColors[label]](
-
    `${label.padEnd(PADDING_WIDTH)} | `,
-
  );
-
}
added tests/support/logPrefix.ts
@@ -0,0 +1,42 @@
+
import type { ColorName } from "chalk";
+

+
import chalk from "chalk";
+

+
const PADDING_WIDTH = 12;
+

+
// The order here is important, we want successive prefixes to have
+
// high contrast.
+
const availableColors: ColorName[] = [
+
  "blue",
+
  "yellowBright",
+
  "greenBright",
+
  "gray",
+
  "green",
+
  "blueBright",
+
  "redBright",
+
  "white",
+
  "yellow",
+
  "red",
+
  "magenta",
+
  "cyan",
+
];
+

+
const assignedColors: Record<string, ColorName> = {};
+

+
export function logPrefix(label: string): string {
+
  if (assignedColors[label] === undefined) {
+
    const color = availableColors.pop();
+
    if (!color) {
+
      throw new Error("We're out of colors. 🤷");
+
    }
+

+
    assignedColors[label] = color;
+
  }
+

+
  // We reset colors at the beginning of each line to avoid styles from previous
+
  // lines messing up prefix colors. This is noticable in rust stack traces
+
  // where the `in` and `with` keywords have a white background color.
+
  return chalk.reset[assignedColors[label]](
+
    `${label.padEnd(PADDING_WIDTH)} | `,
+
  );
+
}
modified tests/support/process.ts
@@ -5,7 +5,7 @@ import onExit from "exit-hook";
import { StringDecoder } from "string_decoder";
import { execa } from "execa";

-
import { make } from "./logLabel.js";
+
import { logPrefix } from "./logPrefix.js";

// Processes that should be SIGKILLed when the Node process shutsdown.
// We add all proxy and node instances that we spawn to this list.
@@ -42,7 +42,7 @@ export function prefixOutput(
  label: string,
  output: Stream.Writable,
): ExecaChildProcess {
-
  const pref = make(label);
+
  const pref = logPrefix(label);
  if (childProcess.stdout) {
    const stdoutPrefix = new LinePrefix(pref);
    childProcess.stdout.pipe(stdoutPrefix).pipe(output, { end: false });