Skip to content

Commit

Permalink
test: add a test that checks the health check endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Jun 24, 2024
1 parent 6033044 commit 2166708
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "simple-logging-server",
"license": "MIT",
"version": "2.3.0",
"version": "2.3.1",
"description": "This is a simple API for logging messages",
"author": "Sean Cassiere",
"keywords": [],
Expand All @@ -14,8 +14,8 @@
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
"start": "NODE_ENV=production node dist/index.js",
"dev": "NODE_ENV=development tsx --watch ./src/index.ts",
"test": "vitest --typecheck",
"test:ci": "vitest run --typecheck",
"test": "vitest",
"test:ci": "vitest run",
"build:kill-dist": "rimraf ./dist",
"build:code": "tsc && tscpaths -p tsconfig.json -s ./src -o ./dist",
"build": "pnpm run build:kill-dist && pnpm run build:code",
Expand All @@ -38,6 +38,7 @@
"tscpaths": "^0.0.9",
"tsx": "^4.15.7",
"typescript": "^5.5.2",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.6.0"
},
"dependencies": {
Expand Down
41 changes: 41 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/health.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, test } from "vitest";
import app from "../src/server";

describe("Health check", () => {
test("GET /health returns 200", async () => {
const response = await app.request("/health", { method: "GET" });
const jsonBody = await response.json();
expect(response.status).toBe(200);
expect(jsonBody.message).toBe("OK");
expect(jsonBody.uptime).toBeGreaterThanOrEqual(0);
});
});
11 changes: 11 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";

export default defineConfig({
plugins: [tsconfigPaths()],
test: {
alias: {
"@/": new URL("./src/", import.meta.url).pathname,
},
},
});

0 comments on commit 2166708

Please sign in to comment.