Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

753 B
Raw Blame
import { afterEach, describe, expect, it, vi } from "vitest";
import { useTasks } from "./tasks";
import { stopBackgroundProcesses } from "./shellActions";

const task = (id: number, cancel?: () => void, done = false) => ({
  id,
  title: `Task ${id}`,
  message: null,
  fraction: null,
  done,
  startedAt: 0,
  cancel,
});

afterEach(() => useTasks.setState({ tasks: [] }));

describe("stopBackgroundProcesses", () => {
  it("stops the only running cancellable task", () => {
    const cancel = vi.fn();
    const finished = vi.fn();
    useTasks.setState({ tasks: [task(1, cancel), task(2), task(3, finished, true)] });
    stopBackgroundProcesses();
    expect(cancel).toHaveBeenCalledOnce();
    expect(finished).not.toHaveBeenCalled();
  });
});