From c7ec678a3e52cb4f7cb9f658ff92ae6dd9a292c2 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Mon, 23 Sep 2024 13:20:30 +0200 Subject: [PATCH] fix: :green_heart: Run every test file separately instead of using the global bun test command --- .github/workflows/tests.yml | 2 +- CONTRIBUTING.md | 4 +++- app.ts | 1 - index.ts | 3 --- middlewares/logger.ts | 6 +++--- package.json | 3 ++- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cba3e86f..f9c98d30 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -48,4 +48,4 @@ jobs: - name: Run tests run: | - bun test + bun run test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fe9ef0c8..f353ac0f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -83,9 +83,11 @@ If your port number is lower than 1024, you may need to run the command as root. To run the tests, run: ```sh -bun test +bun run test ``` +The `bun test` command will cause errors due to Bun bugs ([oven-sh/bun#7823](https://github.com/oven-sh/bun/issues/7823)). Use the `test` script instead. + The tests are located all around the codebase (filename `*.test.ts`) and follow a Jest-like syntax. The server should be shut down before running the tests. ## Code style diff --git a/app.ts b/app.ts index 6f6a04b5..c037aeee 100644 --- a/app.ts +++ b/app.ts @@ -220,7 +220,6 @@ export const appFactory = async () => { }); app.onError((error, c) => { - console.error(error); serverLogger.error`${error}`; sentry?.captureException(error); return c.json( diff --git a/index.ts b/index.ts index de6892ec..11f887e5 100644 --- a/index.ts +++ b/index.ts @@ -1,12 +1,9 @@ import cluster from "node:cluster"; -import { configureLoggers } from "@/loggers"; import { sentry } from "@/sentry"; import { createServer } from "@/server"; import { appFactory } from "~/app"; import { config } from "~/packages/config-manager/index"; -await configureLoggers(); - if (cluster.isPrimary) { for (let i = 0; i < Number(process.env.NUM_CPUS ?? 1); i++) { cluster.fork(); diff --git a/middlewares/logger.ts b/middlewares/logger.ts index cb7b37e1..c7dc1a54 100644 --- a/middlewares/logger.ts +++ b/middlewares/logger.ts @@ -5,7 +5,7 @@ import { config } from "~/packages/config-manager"; export const logger = createMiddleware(async (context, next) => { if (config.logging.log_requests) { - const logger = getLogger("server"); + const serverLogger = getLogger("server"); const body = await context.req.raw.clone().text(); const urlAndMethod = `${chalk.green(context.req.method)} ${chalk.blue(context.req.url)}`; @@ -26,9 +26,9 @@ export const logger = createMiddleware(async (context, next) => { const bodyLog = `${chalk.bold("Body")}: ${chalk.gray(body)}`; if (config.logging.log_requests_verbose) { - logger.debug`${urlAndMethod}\n${hash}\n${headers}\n${bodyLog}`; + serverLogger.debug`${urlAndMethod}\n${hash}\n${headers}\n${bodyLog}`; } else { - logger.debug`${urlAndMethod}`; + serverLogger.debug`${urlAndMethod}`; } } diff --git a/package.json b/package.json index f8ee3abb..751d2ea3 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "cli": "bun run cli/index.ts", "prune": "ts-prune | grep -v server/ | grep -v dist/ | grep -v '(used in module)'", "schema:generate": "bun run packages/config-manager/json-schema.ts > config/config.schema.json && bun run packages/plugin-kit/json-schema.ts > packages/plugin-kit/manifest.schema.json", - "check": "bunx tsc -p ." + "check": "bunx tsc -p .", + "test": "find . -name \"*.test.ts\" -not -path \"./node_modules/*\" | xargs -I {} sh -c 'bun test {} || exit 255'" }, "trustedDependencies": [ "@biomejs/biome",