mirror of
https://github.com/home-assistant/frontend.git
synced 2026-10-01 01:08:50 +01:00
* Update vitest monorepo to v5 * Add required Vite peer dependency for Vitest 5 * Migrate benchmarks to the Vitest 5 context API * Stub read-only jsdom globals in Vitest tests * Revise benchmark reporting instructions in README Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Aidan Timson <aidan@timmo.dev> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { afterEach, assert, describe, it, vi } from "vitest";
|
|
import { createHassioSession } from "../../src/data/hassio/ingress";
|
|
import type { HomeAssistant } from "../../src/types";
|
|
|
|
describe("Create hassio session", () => {
|
|
const hass = {
|
|
callWS: async () => ({
|
|
session: "fhdsu73rh3io4h8f3irhjel8ousafehf8f3yh",
|
|
}),
|
|
} as unknown as Pick<HomeAssistant, "callWS">;
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("Test create session without HTTPS", async () => {
|
|
vi.stubGlobal("document", {});
|
|
vi.stubGlobal("location", { protocol: "http:" });
|
|
await createHassioSession(hass);
|
|
assert.strictEqual(
|
|
global.document.cookie,
|
|
"ingress_session=fhdsu73rh3io4h8f3irhjel8ousafehf8f3yh;path=/api/hassio_ingress/;SameSite=Strict"
|
|
);
|
|
});
|
|
it("Test create session with HTTPS", async () => {
|
|
vi.stubGlobal("document", {});
|
|
vi.stubGlobal("location", { protocol: "https:" });
|
|
await createHassioSession(hass);
|
|
assert.strictEqual(
|
|
global.document.cookie,
|
|
"ingress_session=fhdsu73rh3io4h8f3irhjel8ousafehf8f3yh;path=/api/hassio_ingress/;SameSite=Strict;Secure"
|
|
);
|
|
});
|
|
it("Test fail to create", async () => {
|
|
const createSessionPromise = createHassioSession({
|
|
callWS: async () => {
|
|
throw new Error("Failed to create session");
|
|
},
|
|
}).then(
|
|
() => true,
|
|
() => false
|
|
);
|
|
assert.strictEqual(await createSessionPromise, false);
|
|
});
|
|
});
|