mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
chore(lint): no-explicit-any in workspace-git-service.test
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import path from "node:path";
|
||||
import type { FSWatcher } from "node:fs";
|
||||
import type pino from "pino";
|
||||
import type { GitHubService } from "../services/github-service.js";
|
||||
import type { CheckoutStatusGit, PullRequestStatusResult } from "../utils/checkout-git.js";
|
||||
import {
|
||||
@@ -7,6 +9,11 @@ import {
|
||||
type WorkspaceGitRuntimeSnapshot,
|
||||
} from "./workspace-git-service.js";
|
||||
|
||||
interface ServiceInternals {
|
||||
workingTreeWatchTargets: Map<string, { fallbackRefreshInterval: unknown; repoWatchPath: string }>;
|
||||
scheduleWorkspaceRefresh(cwd: string, options: { force: boolean; reason: string }): void;
|
||||
}
|
||||
|
||||
function createLogger() {
|
||||
const logger = {
|
||||
child: () => logger,
|
||||
@@ -112,11 +119,12 @@ function createPullRequestStatusResult(
|
||||
};
|
||||
}
|
||||
|
||||
function createWatcher() {
|
||||
return {
|
||||
function createWatcher(): FSWatcher & { close: ReturnType<typeof vi.fn> } {
|
||||
const watcher = {
|
||||
close: vi.fn(),
|
||||
on: vi.fn().mockReturnThis(),
|
||||
};
|
||||
return watcher as unknown as FSWatcher & { close: ReturnType<typeof vi.fn> };
|
||||
}
|
||||
|
||||
function createDirent(name: string, isDirectory: boolean) {
|
||||
@@ -183,7 +191,7 @@ interface CreateServiceTestOptions {
|
||||
|
||||
function buildDefaultTestServiceDeps() {
|
||||
return {
|
||||
watch: (() => createWatcher()) as unknown as any,
|
||||
watch: (() => createWatcher()) as unknown as typeof import("node:fs").watch,
|
||||
readdir: vi.fn(async () => []),
|
||||
getCheckoutStatus: vi.fn(async (cwd: string) => createCheckoutStatus(cwd)),
|
||||
getCheckoutShortstat: vi.fn(async () => ({
|
||||
@@ -208,7 +216,7 @@ function buildDefaultTestServiceDeps() {
|
||||
|
||||
function createService(options?: CreateServiceTestOptions) {
|
||||
return new WorkspaceGitServiceImpl({
|
||||
logger: createLogger() as any,
|
||||
logger: createLogger() as unknown as pino.Logger,
|
||||
paseoHome: "/tmp/paseo-test",
|
||||
deps: { ...buildDefaultTestServiceDeps(), ...(options ?? {}) },
|
||||
});
|
||||
@@ -593,7 +601,7 @@ describe("WorkspaceGitServiceImpl", () => {
|
||||
const watch = vi.fn((watchPath: string) => {
|
||||
const watcher = createWatcher();
|
||||
watchCalls.push({ path: watchPath, close: watcher.close });
|
||||
return watcher as any;
|
||||
return watcher;
|
||||
});
|
||||
const readdir = vi.fn(async (directory: string) => {
|
||||
if (directory === "/tmp/repo") {
|
||||
@@ -644,8 +652,8 @@ describe("WorkspaceGitServiceImpl", () => {
|
||||
const watchers = [createWatcher(), createWatcher()];
|
||||
const watch = vi
|
||||
.fn()
|
||||
.mockReturnValueOnce(watchers[0] as any)
|
||||
.mockReturnValueOnce(watchers[1] as any);
|
||||
.mockReturnValueOnce(watchers[0])
|
||||
.mockReturnValueOnce(watchers[1]);
|
||||
const service = createService({ watch });
|
||||
|
||||
const firstListener = vi.fn();
|
||||
@@ -683,13 +691,13 @@ describe("WorkspaceGitServiceImpl", () => {
|
||||
if (options.recursive) {
|
||||
throw recursiveUnsupported;
|
||||
}
|
||||
return createWatcher() as any;
|
||||
return createWatcher();
|
||||
})
|
||||
.mockImplementationOnce(() => createWatcher() as any);
|
||||
.mockImplementationOnce(() => createWatcher());
|
||||
|
||||
const service = createService({ watch });
|
||||
const subscription = await service.requestWorkingTreeWatch("/tmp/repo", vi.fn());
|
||||
const target = (service as any).workingTreeWatchTargets.get("/tmp/repo");
|
||||
const target = (service as unknown as ServiceInternals).workingTreeWatchTargets.get("/tmp/repo");
|
||||
|
||||
expect(target?.fallbackRefreshInterval).not.toBeNull();
|
||||
|
||||
@@ -698,7 +706,7 @@ describe("WorkspaceGitServiceImpl", () => {
|
||||
});
|
||||
|
||||
test("non-git directories fall back to watching cwd with polling", async () => {
|
||||
const watch = vi.fn(() => createWatcher() as any);
|
||||
const watch = vi.fn(() => createWatcher());
|
||||
const runGitCommand = vi.fn(async () => {
|
||||
throw new Error("not a git repository");
|
||||
});
|
||||
@@ -710,7 +718,7 @@ describe("WorkspaceGitServiceImpl", () => {
|
||||
});
|
||||
|
||||
const subscription = await service.requestWorkingTreeWatch("/tmp/plain", vi.fn());
|
||||
const target = (service as any).workingTreeWatchTargets.get("/tmp/plain");
|
||||
const target = (service as unknown as ServiceInternals).workingTreeWatchTargets.get("/tmp/plain");
|
||||
|
||||
expect(subscription.repoRoot).toBeNull();
|
||||
const expectedRecursive = process.platform !== "linux";
|
||||
@@ -731,11 +739,14 @@ describe("WorkspaceGitServiceImpl", () => {
|
||||
const watch = vi.fn(
|
||||
(_watchPath: string, _options: { recursive: boolean }, callback: () => void) => {
|
||||
watchCallbacks.push(callback);
|
||||
return createWatcher() as any;
|
||||
return createWatcher();
|
||||
},
|
||||
);
|
||||
const service = createService({ watch });
|
||||
const refreshSpy = vi.spyOn(service as any, "scheduleWorkspaceRefresh");
|
||||
const refreshSpy = vi.spyOn(
|
||||
service as unknown as ServiceInternals,
|
||||
"scheduleWorkspaceRefresh",
|
||||
);
|
||||
const listener = vi.fn();
|
||||
|
||||
const subscription = await service.requestWorkingTreeWatch("/tmp/repo", listener);
|
||||
@@ -758,7 +769,7 @@ describe("WorkspaceGitServiceImpl", () => {
|
||||
const watch = vi.fn(
|
||||
(watchPath: string, _options: { recursive: boolean }, callback: () => void) => {
|
||||
watchCallbacks.push({ path: watchPath, callback });
|
||||
return createWatcher() as any;
|
||||
return createWatcher();
|
||||
},
|
||||
);
|
||||
const getCheckoutShortstat = vi
|
||||
|
||||
Reference in New Issue
Block a user