Skip to content

Build your personal knowledge base with Trilium Notes

1.2 KB
Raw Blame
import { afterEach, describe, expect, it } from "vitest";

import path from "path";

import { getClientBuildDir, getClientDir, getPdfjsAssetDir, getShareThemeAssetDir } from "./assets.js";

// The test runner sets NODE_ENV=development, which exercises the dev branch of
// these path helpers. Toggle to production to cover the resource-dir branch too.
describe("assets path helpers", () => {
    const original = process.env.NODE_ENV;
    afterEach(() => { process.env.NODE_ENV = original; });

    it("resolves dev paths under development", () => {
        process.env.NODE_ENV = "development";
        expect(getShareThemeAssetDir()).toBe(path.join(getClientBuildDir(), "src"));
        expect(getPdfjsAssetDir()).toContain("pdfjs-viewer");
        expect(getClientDir()).toContain("client");
        expect(getClientBuildDir()).toBe(path.join(getClientDir(), "..", "dist"));
    });

    it("resolves resource-dir paths under production", () => {
        process.env.NODE_ENV = "production";
        expect(getShareThemeAssetDir()).toBe(path.join(getClientBuildDir(), "src"));
        expect(getPdfjsAssetDir()).toContain("pdfjs-viewer");
        expect(typeof getClientDir()).toBe("string");
        expect(getClientBuildDir()).toBe(getClientDir());
    });
});