From 2166708f162610ae84939060e3b80266d95fdb92 Mon Sep 17 00:00:00 2001 From: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:43:09 +1200 Subject: [PATCH] test: add a test that checks the health check endpoint --- package.json | 7 ++++--- pnpm-lock.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ tests/health.test.ts | 12 ++++++++++++ vitest.config.ts | 11 +++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 tests/health.test.ts create mode 100644 vitest.config.ts diff --git a/package.json b/package.json index 428ec4a..fc4e3de 100644 --- a/package.json +++ b/package.json @@ -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": [], @@ -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", @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f0f47e9..a1f0693 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -75,6 +75,9 @@ importers: typescript: specifier: ^5.5.2 version: 5.5.2 + vite-tsconfig-paths: + specifier: ^4.3.2 + version: 4.3.2(typescript@5.5.2)(vite@5.3.1(@types/node@20.14.8)) vitest: specifier: ^1.6.0 version: 1.6.0(@types/node@20.14.8) @@ -1986,6 +1989,9 @@ packages: resolution: {integrity: sha512-ollPHROa5mcxDEkwg6bPt3QbEf4pDQSNtd6JPL1YvOvAo/7/0VAm9TccUeoTmarjPw4pfUthSCqcyfNB1I3ZSg==} engines: {node: '>=6'} + globrex@0.1.2: + resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==} + gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} @@ -3323,6 +3329,16 @@ packages: ts-interface-checker@0.1.13: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} + tsconfck@3.1.0: + resolution: {integrity: sha512-CMjc5zMnyAjcS9sPLytrbFmj89st2g+JYtY/c02ug4Q+CZaAtCgbyviI0n1YvjZE/pzoc6FbNsINS13DOL1B9w==} + engines: {node: ^18 || >=20} + hasBin: true + peerDependencies: + typescript: ^5.0.0 + peerDependenciesMeta: + typescript: + optional: true + tscpaths@0.0.9: resolution: {integrity: sha512-tz4qimSJTCjYtHVsoY7pvxLcxhmhgmwzm7fyMEiL3/kPFFVyUuZOwuwcWwjkAsIrSUKJK22A7fNuJUwxzQ+H+w==} hasBin: true @@ -3429,6 +3445,14 @@ packages: engines: {node: ^18.0.0 || >=20.0.0} hasBin: true + vite-tsconfig-paths@4.3.2: + resolution: {integrity: sha512-0Vd/a6po6Q+86rPlntHye7F31zA2URZMbH8M3saAZ/xR9QoGN/L21bxEGfXdWmFdNkqPpRdxFT7nmNe12e9/uA==} + peerDependencies: + vite: '*' + peerDependenciesMeta: + vite: + optional: true + vite@5.3.1: resolution: {integrity: sha512-XBmSKRLXLxiaPYamLv3/hnP/KXDai1NDexN0FpkTaZXTfycHvkRHoenpgl/fvuK/kPbB6xAgoyiryAhQNxYmAQ==} engines: {node: ^18.0.0 || >=20.0.0} @@ -5753,6 +5777,8 @@ snapshots: transitivePeerDependencies: - supports-color + globrex@0.1.2: {} + gopd@1.0.1: dependencies: get-intrinsic: 1.2.4 @@ -7352,6 +7378,10 @@ snapshots: ts-interface-checker@0.1.13: {} + tsconfck@3.1.0(typescript@5.5.2): + optionalDependencies: + typescript: 5.5.2 + tscpaths@0.0.9: dependencies: commander: 2.20.3 @@ -7494,6 +7524,17 @@ snapshots: - supports-color - terser + vite-tsconfig-paths@4.3.2(typescript@5.5.2)(vite@5.3.1(@types/node@20.14.8)): + dependencies: + debug: 4.3.4 + globrex: 0.1.2 + tsconfck: 3.1.0(typescript@5.5.2) + optionalDependencies: + vite: 5.3.1(@types/node@20.14.8) + transitivePeerDependencies: + - supports-color + - typescript + vite@5.3.1(@types/node@20.14.8): dependencies: esbuild: 0.21.5 diff --git a/tests/health.test.ts b/tests/health.test.ts new file mode 100644 index 0000000..4ef5b96 --- /dev/null +++ b/tests/health.test.ts @@ -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); + }); +}); diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..3fb743f --- /dev/null +++ b/vitest.config.ts @@ -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, + }, + }, +});