RunTestsButton

tcmts.studio.RunTestsButton · #ypllzu5g · term · runs in the browser

uses useState

Run tests (startTests, as tcm test <names>): all of them, without names. The page then shows the run as it goes.

import { refresh } from "#codebase/tcmts/react";
import { toasts } from "#codebase/tcmts/share";
import { startTests } from "#codebase/tcmts/studio";
import { useState } from "react";
import { Button } from "react-aria-components";

export function RunTestsButton({
  names,
  label,
  primary,
}: {
  names: string[];
  label: string;
  primary?: boolean;
}) {
  const [busy, setBusy] = useState(false);
  return (
    <Button
      className={primary ? "btn primary" : "btn small"}
      isPending={busy}
      onPress={async () => {
        setBusy(true);
        try {
          await startTests(names);
          refresh();
        } catch (e) {
          toasts.add(
            { title: "Couldn't run them", description: (e as Error).message, tone: "bad" },
            { timeout: 8000 },
          );
        }
        setBusy(false);
      }}
    >
      {label}
    </Button>
  );
}

uses

used by