mirror of
https://github.com/gethomepage/homepage.git
synced 2026-02-08 00:40:52 +08:00
test: move pages tests out of Next.js routes
This commit is contained in:
@@ -21,7 +21,7 @@ vi.mock("utils/contexts/tab", () => ({
|
||||
TabProvider: ({ children }) => <>{children}</>,
|
||||
}));
|
||||
|
||||
import App from "./_app.jsx";
|
||||
import App from "pages/_app.jsx";
|
||||
|
||||
describe("pages/_app", () => {
|
||||
it("renders the active page component with pageProps", () => {
|
||||
@@ -8,7 +8,7 @@ vi.mock("next/document", () => ({
|
||||
NextScript: () => <script data-testid="nextscript" />,
|
||||
}));
|
||||
|
||||
import Document from "./_document.jsx";
|
||||
import Document from "pages/_document.jsx";
|
||||
|
||||
describe("pages/_document", () => {
|
||||
it("renders the PWA meta + custom css links", () => {
|
||||
@@ -10,7 +10,7 @@ vi.mock("utils/config/api-response", () => ({
|
||||
bookmarksResponse,
|
||||
}));
|
||||
|
||||
import handler from "./bookmarks";
|
||||
import handler from "pages/api/bookmarks";
|
||||
|
||||
describe("pages/api/bookmarks", () => {
|
||||
beforeEach(() => {
|
||||
@@ -26,7 +26,7 @@ vi.mock("utils/logger", () => ({
|
||||
default: () => logger,
|
||||
}));
|
||||
|
||||
import handler from "./[path]";
|
||||
import handler from "pages/api/config/[path]";
|
||||
|
||||
describe("pages/api/config/[path]", () => {
|
||||
beforeEach(() => {
|
||||
@@ -39,7 +39,7 @@ vi.mock("dockerode", () => ({ default: Docker }));
|
||||
vi.mock("utils/config/docker", () => ({ default: getDockerArguments }));
|
||||
vi.mock("utils/logger", () => ({ default: () => logger }));
|
||||
|
||||
import handler from "./[...service]";
|
||||
import handler from "pages/api/docker/stats/[...service]";
|
||||
|
||||
describe("pages/api/docker/stats/[...service]", () => {
|
||||
beforeEach(() => {
|
||||
@@ -39,7 +39,7 @@ vi.mock("dockerode", () => ({ default: Docker }));
|
||||
vi.mock("utils/config/docker", () => ({ default: getDockerArguments }));
|
||||
vi.mock("utils/logger", () => ({ default: () => logger }));
|
||||
|
||||
import handler from "./[...service]";
|
||||
import handler from "pages/api/docker/status/[...service]";
|
||||
|
||||
describe("pages/api/docker/status/[...service]", () => {
|
||||
beforeEach(() => {
|
||||
@@ -22,7 +22,7 @@ vi.mock("utils/config/config", () => ({
|
||||
CONF_DIR,
|
||||
}));
|
||||
|
||||
import handler from "./hash";
|
||||
import handler from "pages/api/hash";
|
||||
|
||||
describe("pages/api/hash", () => {
|
||||
const originalBuildTime = process.env.HOMEPAGE_BUILDTIME;
|
||||
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import createMockRes from "test-utils/create-mock-res";
|
||||
|
||||
import handler from "./healthcheck";
|
||||
import handler from "pages/api/healthcheck";
|
||||
|
||||
describe("pages/api/healthcheck", () => {
|
||||
it("returns 'up'", () => {
|
||||
@@ -24,20 +24,20 @@ vi.mock("@kubernetes/client-node", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../../../../utils/config/kubernetes", () => ({
|
||||
vi.mock("utils/config/kubernetes", () => ({
|
||||
getKubeConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../../../../utils/kubernetes/utils", () => ({
|
||||
vi.mock("utils/kubernetes/utils", () => ({
|
||||
parseCpu,
|
||||
parseMemory,
|
||||
}));
|
||||
|
||||
vi.mock("../../../../utils/logger", () => ({
|
||||
vi.mock("utils/logger", () => ({
|
||||
default: () => logger,
|
||||
}));
|
||||
|
||||
import handler from "./[...service]";
|
||||
import handler from "pages/api/kubernetes/stats/[...service]";
|
||||
|
||||
describe("pages/api/kubernetes/stats/[...service]", () => {
|
||||
beforeEach(() => {
|
||||
@@ -15,15 +15,15 @@ vi.mock("@kubernetes/client-node", () => ({
|
||||
CoreV1Api: class CoreV1Api {},
|
||||
}));
|
||||
|
||||
vi.mock("../../../../utils/config/kubernetes", () => ({
|
||||
vi.mock("utils/config/kubernetes", () => ({
|
||||
getKubeConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../../../../utils/logger", () => ({
|
||||
vi.mock("utils/logger", () => ({
|
||||
default: () => logger,
|
||||
}));
|
||||
|
||||
import handler from "./[...service]";
|
||||
import handler from "pages/api/kubernetes/status/[...service]";
|
||||
|
||||
describe("pages/api/kubernetes/status/[...service]", () => {
|
||||
beforeEach(() => {
|
||||
@@ -20,7 +20,7 @@ vi.mock("ping", () => ({
|
||||
promise: ping,
|
||||
}));
|
||||
|
||||
import handler from "./ping";
|
||||
import handler from "pages/api/ping";
|
||||
|
||||
describe("pages/api/ping", () => {
|
||||
beforeEach(() => {
|
||||
@@ -20,7 +20,7 @@ vi.mock("utils/logger", () => ({
|
||||
default: () => logger,
|
||||
}));
|
||||
|
||||
import handler from "./[...service]";
|
||||
import handler from "pages/api/proxmox/stats/[...service]";
|
||||
|
||||
describe("pages/api/proxmox/stats/[...service]", () => {
|
||||
beforeEach(() => {
|
||||
@@ -15,7 +15,7 @@ vi.mock("utils/proxy/http", () => ({
|
||||
cachedRequest,
|
||||
}));
|
||||
|
||||
import handler from "./releases";
|
||||
import handler from "pages/api/releases";
|
||||
|
||||
describe("pages/api/releases", () => {
|
||||
beforeEach(() => {
|
||||
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import createMockRes from "test-utils/create-mock-res";
|
||||
|
||||
import handler from "./revalidate";
|
||||
import handler from "pages/api/revalidate";
|
||||
|
||||
describe("pages/api/revalidate", () => {
|
||||
it("revalidates and returns {revalidated:true}", async () => {
|
||||
@@ -33,7 +33,7 @@ vi.mock("utils/proxy/http", () => ({
|
||||
cachedRequest,
|
||||
}));
|
||||
|
||||
import handler from "./searchSuggestion";
|
||||
import handler from "pages/api/search/searchSuggestion";
|
||||
|
||||
describe("pages/api/search/searchSuggestion", () => {
|
||||
beforeEach(() => {
|
||||
@@ -10,7 +10,7 @@ vi.mock("utils/config/api-response", () => ({
|
||||
servicesResponse,
|
||||
}));
|
||||
|
||||
import handler from "./index";
|
||||
import handler from "pages/api/services/index";
|
||||
|
||||
describe("pages/api/services/index", () => {
|
||||
beforeEach(() => {
|
||||
@@ -26,7 +26,7 @@ vi.mock("widgets/widgets", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
import servicesProxy from "./proxy";
|
||||
import servicesProxy from "pages/api/services/proxy";
|
||||
|
||||
function createMockRes() {
|
||||
const res = {
|
||||
@@ -25,7 +25,7 @@ vi.mock("utils/logger", () => ({
|
||||
default: () => logger,
|
||||
}));
|
||||
|
||||
import handler from "./siteMonitor";
|
||||
import handler from "pages/api/siteMonitor";
|
||||
|
||||
describe("pages/api/siteMonitor", () => {
|
||||
beforeEach(() => {
|
||||
@@ -12,7 +12,7 @@ vi.mock("utils/config/config", () => ({
|
||||
getSettings,
|
||||
}));
|
||||
|
||||
import handler from "./theme";
|
||||
import handler from "pages/api/theme";
|
||||
|
||||
describe("pages/api/theme", () => {
|
||||
beforeEach(() => {
|
||||
@@ -10,7 +10,7 @@ vi.mock("utils/config/config", () => ({
|
||||
default: checkAndCopyConfig,
|
||||
}));
|
||||
|
||||
import handler from "./validate";
|
||||
import handler from "pages/api/validate";
|
||||
|
||||
describe("pages/api/validate", () => {
|
||||
beforeEach(() => {
|
||||
@@ -20,7 +20,7 @@ vi.mock("utils/logger", () => ({
|
||||
default: () => logger,
|
||||
}));
|
||||
|
||||
import handler from "./glances";
|
||||
import handler from "pages/api/widgets/glances";
|
||||
|
||||
describe("pages/api/widgets/glances", () => {
|
||||
beforeEach(() => {
|
||||
@@ -10,7 +10,7 @@ vi.mock("utils/config/api-response", () => ({
|
||||
widgetsResponse,
|
||||
}));
|
||||
|
||||
import handler from "./index";
|
||||
import handler from "pages/api/widgets/index";
|
||||
|
||||
describe("pages/api/widgets/index", () => {
|
||||
beforeEach(() => {
|
||||
@@ -30,20 +30,20 @@ vi.mock("@kubernetes/client-node", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../../../utils/config/kubernetes", () => ({
|
||||
vi.mock("utils/config/kubernetes", () => ({
|
||||
getKubeConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../../../utils/kubernetes/utils", () => ({
|
||||
vi.mock("utils/kubernetes/utils", () => ({
|
||||
parseCpu,
|
||||
parseMemory,
|
||||
}));
|
||||
|
||||
vi.mock("../../../utils/logger", () => ({
|
||||
vi.mock("utils/logger", () => ({
|
||||
default: () => logger,
|
||||
}));
|
||||
|
||||
import handler from "./kubernetes";
|
||||
import handler from "pages/api/widgets/kubernetes";
|
||||
|
||||
describe("pages/api/widgets/kubernetes", () => {
|
||||
beforeEach(() => {
|
||||
@@ -8,19 +8,19 @@ const { getSettings, httpProxy, logger } = vi.hoisted(() => ({
|
||||
logger: { error: vi.fn() },
|
||||
}));
|
||||
|
||||
vi.mock("../../../utils/config/config", () => ({
|
||||
vi.mock("utils/config/config", () => ({
|
||||
getSettings,
|
||||
}));
|
||||
|
||||
vi.mock("../../../utils/proxy/http", () => ({
|
||||
vi.mock("utils/proxy/http", () => ({
|
||||
httpProxy,
|
||||
}));
|
||||
|
||||
vi.mock("../../../utils/logger", () => ({
|
||||
vi.mock("utils/logger", () => ({
|
||||
default: () => logger,
|
||||
}));
|
||||
|
||||
import handler from "./longhorn";
|
||||
import handler from "pages/api/widgets/longhorn";
|
||||
|
||||
describe("pages/api/widgets/longhorn", () => {
|
||||
beforeEach(() => {
|
||||
@@ -10,7 +10,7 @@ vi.mock("utils/proxy/http", () => ({
|
||||
cachedRequest,
|
||||
}));
|
||||
|
||||
import handler from "./openmeteo";
|
||||
import handler from "pages/api/widgets/openmeteo";
|
||||
|
||||
describe("pages/api/widgets/openmeteo", () => {
|
||||
beforeEach(() => {
|
||||
@@ -20,7 +20,7 @@ vi.mock("utils/proxy/http", () => ({
|
||||
cachedRequest,
|
||||
}));
|
||||
|
||||
import handler from "./openweathermap";
|
||||
import handler from "pages/api/widgets/openweathermap";
|
||||
|
||||
describe("pages/api/widgets/openweathermap", () => {
|
||||
beforeEach(() => {
|
||||
@@ -24,7 +24,7 @@ vi.mock("utils/logger", () => ({
|
||||
|
||||
vi.mock("systeminformation", () => ({ default: si }));
|
||||
|
||||
import handler from "./resources";
|
||||
import handler from "pages/api/widgets/resources";
|
||||
|
||||
describe("pages/api/widgets/resources", () => {
|
||||
beforeEach(() => {
|
||||
@@ -20,7 +20,7 @@ vi.mock("utils/logger", () => ({
|
||||
default: () => logger,
|
||||
}));
|
||||
|
||||
import handler from "./stocks";
|
||||
import handler from "pages/api/widgets/stocks";
|
||||
|
||||
describe("pages/api/widgets/stocks", () => {
|
||||
beforeEach(() => {
|
||||
@@ -20,7 +20,7 @@ vi.mock("utils/proxy/http", () => ({
|
||||
cachedRequest,
|
||||
}));
|
||||
|
||||
import handler from "./weather";
|
||||
import handler from "pages/api/widgets/weather";
|
||||
|
||||
describe("pages/api/widgets/weatherapi", () => {
|
||||
beforeEach(() => {
|
||||
@@ -10,7 +10,7 @@ vi.mock("utils/config/config", () => ({
|
||||
getSettings,
|
||||
}));
|
||||
|
||||
import { getServerSideProps } from "./browserconfig.xml.jsx";
|
||||
import { getServerSideProps } from "pages/browserconfig.xml.jsx";
|
||||
|
||||
function createMockRes() {
|
||||
return {
|
||||
@@ -65,7 +65,7 @@ describe("pages/index getStaticProps", () => {
|
||||
it("returns initial settings and api fallbacks for swr", async () => {
|
||||
getSettings.mockReturnValueOnce({ providers: { x: 1 }, language: "en", title: "Homepage" });
|
||||
|
||||
const { getStaticProps } = await import("./index.jsx");
|
||||
const { getStaticProps } = await import("pages/index.jsx");
|
||||
const result = await getStaticProps();
|
||||
|
||||
expect(result.props.initialSettings).toEqual({ language: "en", title: "Homepage" });
|
||||
@@ -79,7 +79,7 @@ describe("pages/index getStaticProps", () => {
|
||||
it("normalizes legacy language codes before requesting translations", async () => {
|
||||
getSettings.mockReturnValueOnce({ providers: {}, language: "zh-CN" });
|
||||
|
||||
const { getStaticProps } = await import("./index.jsx");
|
||||
const { getStaticProps } = await import("pages/index.jsx");
|
||||
await getStaticProps();
|
||||
|
||||
expect(serverSideTranslations).toHaveBeenCalledWith("zh-Hans");
|
||||
@@ -89,7 +89,7 @@ describe("pages/index getStaticProps", () => {
|
||||
getSettings.mockReturnValueOnce({ providers: {}, language: "de" });
|
||||
state.throwIn = "services";
|
||||
|
||||
const { getStaticProps } = await import("./index.jsx");
|
||||
const { getStaticProps } = await import("pages/index.jsx");
|
||||
const result = await getStaticProps();
|
||||
|
||||
expect(result.props.initialSettings).toEqual({});
|
||||
@@ -8,7 +8,7 @@ vi.mock("utils/config/config", () => ({
|
||||
getSettings,
|
||||
}));
|
||||
|
||||
import { getServerSideProps } from "./robots.txt.js";
|
||||
import { getServerSideProps } from "pages/robots.txt.js";
|
||||
|
||||
function createMockRes() {
|
||||
return {
|
||||
@@ -12,7 +12,7 @@ vi.mock("utils/config/config", () => ({
|
||||
getSettings,
|
||||
}));
|
||||
|
||||
import { getServerSideProps } from "./site.webmanifest.jsx";
|
||||
import { getServerSideProps } from "pages/site.webmanifest.jsx";
|
||||
|
||||
function createMockRes() {
|
||||
return {
|
||||
Reference in New Issue
Block a user