UNPKG

@embeddable.com/sdk-core

Version:

Core Embeddable SDK module responsible for web-components bundling and publishing.

44 lines (37 loc) 1.18 kB
import { pathToFileURL } from "node:url"; import { existsSync } from "node:fs"; import { PathLike } from "node:fs"; import provideConfig from "./provideConfig"; import { vi } from "vitest"; // Mock fs module vi.mock("node:fs", () => ({ existsSync: vi.fn(), })); // Mock url module vi.mock("node:url", () => ({ pathToFileURL: vi.fn(), })); // Create a mock module factory const mockConfigModule = { default: "mocked-config", }; // Mock both possible config paths vi.mock(`${process.cwd()}/embeddable.config.js`, () => mockConfigModule); vi.mock(`${process.cwd()}/embeddable.config.ts`, () => mockConfigModule); describe("provideConfig", () => { beforeEach(() => { vi.resetModules(); // Mock that only the TS config exists vi.mocked(existsSync).mockImplementation((path: PathLike) => path.toString().endsWith("embeddable.config.ts"), ); // Mock URL creation vi.mocked(pathToFileURL).mockImplementation( (path) => new URL(`file://${path}`), ); }); it("should return the default config when the config file exists", async () => { const result = await provideConfig(); expect(result).toEqual("mocked-config"); }); });