Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Kusumgar committed Dec 5, 2024
1 parent e2e861d commit 5a0f06f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/server/tests/server/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("args", () => {
"--base-url", "http://example.com/wodin",
"--redis-url=redis:6379",
"--port=1234",
"--hot-reload=true",
"/testConfig"];
const args = processArgs(argv);
expect(args.path).toBe("/testConfig");
Expand All @@ -32,6 +33,7 @@ describe("args", () => {
redisUrl: "redis:6379",
port: 1234
});
expect(args.hotReload).toBe(true);
});

it("falls back on process.argv", () => {
Expand All @@ -47,4 +49,9 @@ describe("args", () => {
process.argv = ["node", "wodin", "--port=one", "somepath"];
expect(() => processArgs()).toThrow("Expected an integer for port");
});

it("requires that hot-reload is a boolean", () => {
process.argv = ["node", "wodin", "--hot-reload=T", "somepath"];
expect(() => processArgs()).toThrow("Expected a boolean for hot-reload");
});
});
1 change: 1 addition & 0 deletions app/server/tests/server/test-view.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ test }}
19 changes: 16 additions & 3 deletions app/server/tests/server/views.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { registerViews } from "../../src/server/views";
import * as path from "path";

const { mockRender } = vi.hoisted(() => ({ mockRender: vi.fn().mockReturnValue("mustache") }));
vi.mock("mustache", () => ({ render: mockRender }));

describe("views", () => {
it("register views sets app values and registers helper", () => {
it("register views sets app values and registers engine", () => {
const mockApp = {
set: vi.fn(),
engine: vi.fn()
} as any;
registerViews(mockApp, "/testRoot");
};
registerViews(mockApp as any, "/testRoot");

expect(mockApp.engine).toBeCalledTimes(1);
expect(mockApp.engine.mock.calls[0][0]).toBe("mustache");
const engineFn = mockApp.engine.mock.calls[0][1];
const mockCallback = vi.fn();

engineFn(path.resolve(__dirname, "./test-view.mustache"), {}, mockCallback);
expect(mockCallback.mock.calls[0][0]).toBe(null);
expect(mockCallback.mock.calls[0][1]).toBe("mustache");

engineFn(path.resolve(__dirname, "./wrong-file-path.mustache"), {}, mockCallback);
expect((mockCallback.mock.calls[1][0] as Error).message).toContain("no such file");

expect(mockApp.set).toBeCalledTimes(2);
expect(mockApp.set.mock.calls[0][0]).toBe("view engine");
Expand Down

0 comments on commit 5a0f06f

Please sign in to comment.