fix: address CodeRabbit review — typed mocks, robust benchmark script

- Replace `as any` casts in integration-test-connection.spec.ts with
  Pick<Integration, "testConnectionAsync"> + mockResolvedValue
- build-compare.sh: split local declarations (SC2318), clean .next
  between builds with --force, add EXIT trap for safe stash/cleanup
This commit is contained in:
Thomas Camlong committed 2026-08-08 13:00:42 +02:00
1 parent b1713a9820
commit abec79abe8
2 files changed
+33 -34

No files matched your search

@@ -1,10 +1,15 @@
import { describe, expect, test, vi } from "vitest";
import * as homarrDefinitions from "@homarr/definitions";
import type { Integration } from "@homarr/integrations";
import * as homarrIntegrations from "@homarr/integrations";
import { testConnectionAsync } from "../../integration/integration-test-connection";
const mockIntegration = (): Pick<Integration, "testConnectionAsync"> => ({
testConnectionAsync: async () => ({ success: true }),
});
vi.mock("@homarr/common/server", async (importActual) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
const actual = await importActual<typeof import("@homarr/common/server")>();
@@ -20,12 +25,7 @@ describe("testConnectionAsync should run test connection of integration", () =>
// Arrange
const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync");
const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions");
factorySpy.mockReturnValue(
Promise.resolve({
testConnectionAsync: async () => await Promise.resolve({ success: true }),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any),
);
factorySpy.mockResolvedValue(mockIntegration() as Awaited<ReturnType<typeof homarrIntegrations.createIntegrationAsync>>);
optionsSpy.mockReturnValue([["apiKey"]]);
const integration = {
@@ -64,12 +64,7 @@ describe("testConnectionAsync should run test connection of integration", () =>
// Arrange
const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync");
const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions");
factorySpy.mockReturnValue(
Promise.resolve({
testConnectionAsync: async () => await Promise.resolve({ success: true }),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any),
);
factorySpy.mockResolvedValue(mockIntegration() as Awaited<ReturnType<typeof homarrIntegrations.createIntegrationAsync>>);
optionsSpy.mockReturnValue([["apiKey"]]);
const integration = {
@@ -115,12 +110,7 @@ describe("testConnectionAsync should run test connection of integration", () =>
// Arrange
const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync");
const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions");
factorySpy.mockReturnValue(
Promise.resolve({
testConnectionAsync: async () => await Promise.resolve({ success: true }),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any),
);
factorySpy.mockResolvedValue(mockIntegration() as Awaited<ReturnType<typeof homarrIntegrations.createIntegrationAsync>>);
optionsSpy.mockReturnValue([["apiKey"]]);
const integration = {
@@ -166,12 +156,7 @@ describe("testConnectionAsync should run test connection of integration", () =>
// Arrange
const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync");
const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions");
factorySpy.mockReturnValue(
Promise.resolve({
testConnectionAsync: async () => await Promise.resolve({ success: true }),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any),
);
factorySpy.mockResolvedValue(mockIntegration() as Awaited<ReturnType<typeof homarrIntegrations.createIntegrationAsync>>);
optionsSpy.mockReturnValue([["username", "password"], ["apiKey"]]);
const integration = {
@@ -221,12 +206,7 @@ describe("testConnectionAsync should run test connection of integration", () =>
// Arrange
const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync");
const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions");
factorySpy.mockReturnValue(
Promise.resolve({
testConnectionAsync: async () => await Promise.resolve({ success: true }),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any),
);
factorySpy.mockResolvedValue(mockIntegration() as Awaited<ReturnType<typeof homarrIntegrations.createIntegrationAsync>>);
optionsSpy.mockReturnValue([["username", "password"], ["apiKey"]]);
const integration = {
+23 -4
View File
@@ -7,18 +7,30 @@ REPO_ROOT="$(git rev-parse --show-toplevel)"
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
NEXT_DIR="$REPO_ROOT/apps/nextjs"
OUT_DIR="$REPO_ROOT/.bench"
STASH_CREATED=false
mkdir -p "$OUT_DIR"
cleanup() {
git checkout "$CURRENT_BRANCH" -q 2>/dev/null || true
if $STASH_CREATED; then
git stash pop -q 2>/dev/null || true
fi
}
trap cleanup EXIT
capture_metrics() {
local label="$1" out="$OUT_DIR/$label"
local label="$1"
local out="$OUT_DIR/$label"
mkdir -p "$out"
echo "=== Building $label ==="
cd "$REPO_ROOT"
rm -rf "$NEXT_DIR/.next"
local start_ns
start_ns=$(date +%s)
pnpm turbo build --filter=@homarr/nextjs 2>&1 | tee "$out/build.log"
pnpm turbo build --force --filter=@homarr/nextjs 2>&1 | tee "$out/build.log"
local end_ns
end_ns=$(date +%s)
echo $((end_ns - start_ns)) > "$out/build_time_s"
@@ -47,7 +59,11 @@ capture_metrics() {
}
echo "Stashing uncommitted changes..."
git stash --include-untracked -q 2>/dev/null || true
if git stash --include-untracked -q 2>/dev/null; then
if [ "$(git stash list | wc -l)" -gt 0 ]; then
STASH_CREATED=true
fi
fi
echo ""
echo "=== Phase 1: Build origin/dev ==="
@@ -57,7 +73,10 @@ capture_metrics "dev"
echo ""
echo "=== Phase 2: Build $CURRENT_BRANCH ==="
git checkout "$CURRENT_BRANCH" -q
git stash pop -q 2>/dev/null || true
if $STASH_CREATED; then
git stash pop -q 2>/dev/null || true
STASH_CREATED=false
fi
capture_metrics "branch"
echo ""