fix: 💚 Run every test file separately instead of using the global bun test command

This commit is contained in:
Jesse Wierzbinski 2024-09-23 13:20:30 +02:00
parent de8b8e2cc0
commit c7ec678a3e
No known key found for this signature in database
6 changed files with 9 additions and 10 deletions

View file

@ -48,4 +48,4 @@ jobs:
- name: Run tests - name: Run tests
run: | run: |
bun test bun run test

View file

@ -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: To run the tests, run:
```sh ```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. 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 ## Code style

1
app.ts
View file

@ -220,7 +220,6 @@ export const appFactory = async () => {
}); });
app.onError((error, c) => { app.onError((error, c) => {
console.error(error);
serverLogger.error`${error}`; serverLogger.error`${error}`;
sentry?.captureException(error); sentry?.captureException(error);
return c.json( return c.json(

View file

@ -1,12 +1,9 @@
import cluster from "node:cluster"; import cluster from "node:cluster";
import { configureLoggers } from "@/loggers";
import { sentry } from "@/sentry"; import { sentry } from "@/sentry";
import { createServer } from "@/server"; import { createServer } from "@/server";
import { appFactory } from "~/app"; import { appFactory } from "~/app";
import { config } from "~/packages/config-manager/index"; import { config } from "~/packages/config-manager/index";
await configureLoggers();
if (cluster.isPrimary) { if (cluster.isPrimary) {
for (let i = 0; i < Number(process.env.NUM_CPUS ?? 1); i++) { for (let i = 0; i < Number(process.env.NUM_CPUS ?? 1); i++) {
cluster.fork(); cluster.fork();

View file

@ -5,7 +5,7 @@ import { config } from "~/packages/config-manager";
export const logger = createMiddleware(async (context, next) => { export const logger = createMiddleware(async (context, next) => {
if (config.logging.log_requests) { if (config.logging.log_requests) {
const logger = getLogger("server"); const serverLogger = getLogger("server");
const body = await context.req.raw.clone().text(); const body = await context.req.raw.clone().text();
const urlAndMethod = `${chalk.green(context.req.method)} ${chalk.blue(context.req.url)}`; 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)}`; const bodyLog = `${chalk.bold("Body")}: ${chalk.gray(body)}`;
if (config.logging.log_requests_verbose) { 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 { } else {
logger.debug`${urlAndMethod}`; serverLogger.debug`${urlAndMethod}`;
} }
} }

View file

@ -38,7 +38,8 @@
"cli": "bun run cli/index.ts", "cli": "bun run cli/index.ts",
"prune": "ts-prune | grep -v server/ | grep -v dist/ | grep -v '(used in module)'", "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", "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": [ "trustedDependencies": [
"@biomejs/biome", "@biomejs/biome",