Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/JAVA/Openclaw/src/infra/   (Openclaw AI Version 22©)  Datei vom 26.3.2026 mit Größe 1 kB image not shown  

Quelle  clipboard.test.ts

  Sprache: JAVA
 

import { beforeEach, describe, expect, it, vi } from "vitest";

const runCommandWithTimeoutMock = vi.hoisted(() => vi.fn());

vi.mock("../process/exec.js", () => ({
  runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args),
}));

const { copyToClipboard } = await import("./clipboard.js");

describe("copyToClipboard", () => {
  beforeEach(() => {
    runCommandWithTimeoutMock.mockReset();
  });

  it("returns true on the first successful clipboard command", async () => {
    runCommandWithTimeoutMock.mockResolvedValueOnce({ code: 0, killed: false });

    await expect(copyToClipboard("hello")).resolves.toBe(true);
    expect(runCommandWithTimeoutMock).toHaveBeenCalledWith(["pbcopy"], {
      timeoutMs: 3000,
      input: "hello",
    });
    expect(runCommandWithTimeoutMock).toHaveBeenCalledTimes(1);
  });

  it("falls through failed attempts until a later command succeeds", async () => {
    runCommandWithTimeoutMock
      .mockRejectedValueOnce(new Error("missing pbcopy"))
      .mockResolvedValueOnce({ code: 1, killed: false })
      .mockResolvedValueOnce({ code: 0, killed: false });

    await expect(copyToClipboard("hello")).resolves.toBe(true);
    expect(runCommandWithTimeoutMock.mock.calls.map((call) => call[0])).toEqual([
      ["pbcopy"],
      ["xclip""-selection""clipboard"],
      ["wl-copy"],
    ]);
  });

  it("returns false when every clipboard backend fails or is killed", async () => {
    runCommandWithTimeoutMock
      .mockResolvedValueOnce({ code: 0, killed: true })
      .mockRejectedValueOnce(new Error("missing xclip"))
      .mockResolvedValueOnce({ code: 1, killed: false })
      .mockRejectedValueOnce(new Error("missing clip.exe"))
      .mockResolvedValueOnce({ code: 2, killed: false });

    await expect(copyToClipboard("hello")).resolves.toBe(false);
    expect(runCommandWithTimeoutMock).toHaveBeenCalledTimes(5);
  });
});

Messung V0.5 in Prozent
C=100 H=100 G=100

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-09) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.