diff --git a/app/__test__/App.spec.ts b/app/__test__/App.spec.ts index 57b5eeb..7213216 100644 --- a/app/__test__/App.spec.ts +++ b/app/__test__/App.spec.ts @@ -1,12 +1,15 @@ -import { afterEach, describe, test, expect } from "bun:test"; +import { afterEach, describe, test, expect, beforeAll, afterAll } from "bun:test"; import { App, createApp } from "core/test/utils"; import { getDummyConnection } from "./helper"; import { Hono } from "hono"; import * as proto from "../src/data/prototype"; import { pick } from "lodash-es"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); const { dummyConnection, afterAllCleanup } = getDummyConnection(); -afterEach(afterAllCleanup); +afterEach(async () => (await afterAllCleanup()) && enableConsoleLog()); describe("App tests", async () => { test("boots and pongs", async () => { diff --git a/app/__test__/api/Api.spec.ts b/app/__test__/api/Api.spec.ts index dee1e14..c1041d9 100644 --- a/app/__test__/api/Api.spec.ts +++ b/app/__test__/api/Api.spec.ts @@ -42,7 +42,6 @@ describe("Api", async () => { expect(api.isAuthVerified()).toBe(false); const params = api.getParams(); - console.log(params); expect(params.token).toBe(token); expect(params.token_transport).toBe("cookie"); expect(params.host).toBe("http://example.com"); diff --git a/app/__test__/app/App.spec.ts b/app/__test__/app/App.spec.ts index fab85b8..5bbee56 100644 --- a/app/__test__/app/App.spec.ts +++ b/app/__test__/app/App.spec.ts @@ -1,8 +1,12 @@ -import { describe, expect, mock, test } from "bun:test"; +import { afterAll, beforeAll, describe, expect, mock, test } from "bun:test"; import type { ModuleBuildContext } from "../../src"; import { App, createApp } from "core/test/utils"; import * as proto from "data/prototype"; import { DbModuleManager } from "modules/db/DbModuleManager"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(disableConsoleLog); +afterAll(enableConsoleLog); describe("App", () => { test("use db mode by default", async () => { diff --git a/app/__test__/app/mcp/mcp.base.test.ts b/app/__test__/app/mcp/mcp.base.test.ts index e861595..40b77c4 100644 --- a/app/__test__/app/mcp/mcp.base.test.ts +++ b/app/__test__/app/mcp/mcp.base.test.ts @@ -1,7 +1,11 @@ -import { describe, it, expect } from "bun:test"; +import { describe, it, expect, beforeAll, afterAll } from "bun:test"; import { createApp } from "core/test/utils"; import { registries } from "index"; import { StorageLocalAdapter } from "adapter/node/storage/StorageLocalAdapter"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(enableConsoleLog); describe("mcp", () => { it("should have tools", async () => { diff --git a/app/__test__/app/mcp/mcp.server.test.ts b/app/__test__/app/mcp/mcp.server.test.ts index f9eb729..1b64edb 100644 --- a/app/__test__/app/mcp/mcp.server.test.ts +++ b/app/__test__/app/mcp/mcp.server.test.ts @@ -1,6 +1,10 @@ -import { describe, test, expect, beforeAll, mock, beforeEach, afterAll } from "bun:test"; +import { describe, test, expect, beforeAll, afterAll } from "bun:test"; import { type App, createApp, createMcpToolCaller } from "core/test/utils"; import type { McpServer } from "bknd/utils"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(enableConsoleLog); /** * - [x] config_server_get diff --git a/app/__test__/app/plugins/sync-config.test.ts b/app/__test__/app/plugins/sync-config.test.ts index 69c4dc3..ba299c9 100644 --- a/app/__test__/app/plugins/sync-config.test.ts +++ b/app/__test__/app/plugins/sync-config.test.ts @@ -1,6 +1,10 @@ -import { describe, it, expect, mock } from "bun:test"; +import { describe, it, expect, mock, beforeAll, afterAll } from "bun:test"; import { createApp } from "core/test/utils"; import { syncConfig } from "plugins/dev/sync-config.plugin"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(enableConsoleLog); describe("syncConfig", () => { it("should only sync if enabled", async () => { diff --git a/app/__test__/app/repro.spec.ts b/app/__test__/app/repro.spec.ts index b18497f..54ff7e2 100644 --- a/app/__test__/app/repro.spec.ts +++ b/app/__test__/app/repro.spec.ts @@ -1,8 +1,12 @@ -import { describe, expect, test } from "bun:test"; +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { registries } from "../../src"; import { createApp } from "core/test/utils"; import * as proto from "../../src/data/prototype"; import { StorageLocalAdapter } from "adapter/node/storage/StorageLocalAdapter"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(enableConsoleLog); describe("repros", async () => { /** diff --git a/app/__test__/core/EventManager.spec.ts b/app/__test__/core/EventManager.spec.ts index 3d8b981..65d4433 100644 --- a/app/__test__/core/EventManager.spec.ts +++ b/app/__test__/core/EventManager.spec.ts @@ -1,6 +1,6 @@ import { afterAll, beforeAll, describe, expect, mock, test } from "bun:test"; import { Event, EventManager, InvalidEventReturn, NoParamEvent } from "../../src/core/events"; -import { disableConsoleLog, enableConsoleLog } from "../helper"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; beforeAll(disableConsoleLog); afterAll(enableConsoleLog); diff --git a/app/__test__/core/utils.spec.ts b/app/__test__/core/utils.spec.ts index 15428bf..36b4969 100644 --- a/app/__test__/core/utils.spec.ts +++ b/app/__test__/core/utils.spec.ts @@ -248,7 +248,7 @@ describe("Core Utils", async () => { expect(utils.getContentName(request)).toBe(name); }); - test.only("detectImageDimensions", async () => { + test("detectImageDimensions", async () => { // wrong // @ts-expect-error expect(utils.detectImageDimensions(new ArrayBuffer(), "text/plain")).rejects.toThrow(); @@ -267,12 +267,12 @@ describe("Core Utils", async () => { }); describe("dates", () => { - test.only("formats local time", () => { + test("formats local time", () => { expect(utils.datetimeStringUTC("2025-02-21T16:48:25.841Z")).toBe("2025-02-21 16:48:25"); - console.log(utils.datetimeStringUTC(new Date())); + /*console.log(utils.datetimeStringUTC(new Date())); console.log(utils.datetimeStringUTC()); console.log(new Date()); - console.log("timezone", Intl.DateTimeFormat().resolvedOptions().timeZone); + console.log("timezone", Intl.DateTimeFormat().resolvedOptions().timeZone); */ }); }); }); diff --git a/app/__test__/data/DataController.spec.ts b/app/__test__/data/DataController.spec.ts index ca4905d..9ca90d8 100644 --- a/app/__test__/data/DataController.spec.ts +++ b/app/__test__/data/DataController.spec.ts @@ -5,7 +5,8 @@ import { parse } from "core/utils/schema"; import { DataController } from "../../src/data/api/DataController"; import { dataConfigSchema } from "../../src/data/data-schema"; -import { disableConsoleLog, enableConsoleLog, getDummyConnection } from "../helper"; +import { getDummyConnection } from "../helper"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; import type { RepositoryResultJSON } from "data/entities/query/RepositoryResult"; import type { MutatorResultJSON } from "data/entities/mutation/MutatorResult"; import { Entity, EntityManager, type EntityData } from "data/entities"; @@ -13,7 +14,7 @@ import { TextField } from "data/fields"; import { ManyToOneRelation } from "data/relations"; const { dummyConnection, afterAllCleanup } = getDummyConnection(); -beforeAll(() => disableConsoleLog(["log", "warn"])); +beforeAll(() => disableConsoleLog()); afterAll(async () => (await afterAllCleanup()) && enableConsoleLog()); const dataConfig = parse(dataConfigSchema, {}); diff --git a/app/__test__/data/specs/JoinBuilder.spec.ts b/app/__test__/data/specs/JoinBuilder.spec.ts index 16f8d30..4ed1255 100644 --- a/app/__test__/data/specs/JoinBuilder.spec.ts +++ b/app/__test__/data/specs/JoinBuilder.spec.ts @@ -1,12 +1,15 @@ -import { afterAll, describe, expect, test } from "bun:test"; +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { Entity, EntityManager } from "data/entities"; import { ManyToOneRelation } from "data/relations"; import { TextField } from "data/fields"; import { JoinBuilder } from "data/entities/query/JoinBuilder"; import { getDummyConnection } from "../helper"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); const { dummyConnection, afterAllCleanup } = getDummyConnection(); -afterAll(afterAllCleanup); +afterAll(async () => (await afterAllCleanup()) && enableConsoleLog()); describe("[data] JoinBuilder", async () => { test("missing relation", async () => { diff --git a/app/__test__/data/specs/Mutator.spec.ts b/app/__test__/data/specs/Mutator.spec.ts index 45bbb28..c4014c8 100644 --- a/app/__test__/data/specs/Mutator.spec.ts +++ b/app/__test__/data/specs/Mutator.spec.ts @@ -9,13 +9,14 @@ import { } from "data/relations"; import { NumberField, TextField } from "data/fields"; import * as proto from "data/prototype"; -import { getDummyConnection, disableConsoleLog, enableConsoleLog } from "../../helper"; +import { getDummyConnection } from "../../helper"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; import { MutatorEvents } from "data/events"; const { dummyConnection, afterAllCleanup } = getDummyConnection(); afterAll(afterAllCleanup); -beforeAll(() => disableConsoleLog(["log", "warn"])); +beforeAll(() => disableConsoleLog()); afterAll(async () => (await afterAllCleanup()) && enableConsoleLog()); describe("[data] Mutator (base)", async () => { diff --git a/app/__test__/data/specs/Repository.spec.ts b/app/__test__/data/specs/Repository.spec.ts index 35c4ec5..d9b2dc2 100644 --- a/app/__test__/data/specs/Repository.spec.ts +++ b/app/__test__/data/specs/Repository.spec.ts @@ -1,4 +1,4 @@ -import { afterAll, describe, expect, test } from "bun:test"; +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import type { Kysely, Transaction } from "kysely"; import { TextField } from "data/fields"; import { em as $em, entity as $entity, text as $text } from "data/prototype"; @@ -6,11 +6,13 @@ import { Entity, EntityManager } from "data/entities"; import { ManyToOneRelation } from "data/relations"; import { RepositoryEvents } from "data/events"; import { getDummyConnection } from "../helper"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; type E = Kysely | Transaction; const { dummyConnection, afterAllCleanup } = getDummyConnection(); -afterAll(afterAllCleanup); +beforeAll(() => disableConsoleLog()); +afterAll(async () => (await afterAllCleanup()) && enableConsoleLog()); async function sleep(ms: number) { return new Promise((resolve) => { diff --git a/app/__test__/data/specs/WithBuilder.spec.ts b/app/__test__/data/specs/WithBuilder.spec.ts index 31cfd96..b778b0a 100644 --- a/app/__test__/data/specs/WithBuilder.spec.ts +++ b/app/__test__/data/specs/WithBuilder.spec.ts @@ -1,4 +1,4 @@ -import { describe, expect, test } from "bun:test"; +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { Entity, EntityManager } from "data/entities"; import { ManyToManyRelation, ManyToOneRelation, PolymorphicRelation } from "data/relations"; import { TextField } from "data/fields"; @@ -6,6 +6,10 @@ import * as proto from "data/prototype"; import { WithBuilder } from "data/entities/query/WithBuilder"; import { schemaToEm } from "../../helper"; import { getDummyConnection } from "../helper"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(enableConsoleLog); const { dummyConnection } = getDummyConnection(); diff --git a/app/__test__/helper.ts b/app/__test__/helper.ts index 2579a88..aaf88d2 100644 --- a/app/__test__/helper.ts +++ b/app/__test__/helper.ts @@ -39,26 +39,6 @@ export function getLocalLibsqlConnection() { return { url: "http://127.0.0.1:8080" }; } -type ConsoleSeverity = "debug" | "log" | "warn" | "error"; -const _oldConsoles = { - debug: console.debug, - log: console.log, - warn: console.warn, - error: console.error, -}; - -export function disableConsoleLog(severities: ConsoleSeverity[] = ["debug", "log", "warn"]) { - severities.forEach((severity) => { - console[severity] = () => null; - }); -} - -export function enableConsoleLog() { - Object.entries(_oldConsoles).forEach(([severity, fn]) => { - console[severity as ConsoleSeverity] = fn; - }); -} - export function compileQb(qb: SelectQueryBuilder) { const { sql, parameters } = qb.compile(); return { sql, parameters }; @@ -66,7 +46,7 @@ export function compileQb(qb: SelectQueryBuilder) { export function prettyPrintQb(qb: SelectQueryBuilder) { const { sql, parameters } = qb.compile(); - console.log("$", sqlFormat(sql), "\n[params]", parameters); + console.info("$", sqlFormat(sql), "\n[params]", parameters); } export function schemaToEm(s: ReturnType, conn?: Connection): EntityManager { diff --git a/app/__test__/integration/auth.integration.test.ts b/app/__test__/integration/auth.integration.test.ts index cf71f05..340ccaf 100644 --- a/app/__test__/integration/auth.integration.test.ts +++ b/app/__test__/integration/auth.integration.test.ts @@ -1,8 +1,9 @@ -import { afterAll, afterEach, beforeAll, describe, expect, it } from "bun:test"; +import { afterAll, beforeAll, describe, expect, it } from "bun:test"; import { App, createApp, type AuthResponse } from "../../src"; import { auth } from "../../src/auth/middlewares"; import { randomString, secureRandomString, withDisabledConsole } from "../../src/core/utils"; -import { disableConsoleLog, enableConsoleLog, getDummyConnection } from "../helper"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; +import { getDummyConnection } from "../helper"; beforeAll(disableConsoleLog); afterAll(enableConsoleLog); @@ -148,8 +149,8 @@ describe("integration auth", () => { const { data: users } = await app.em.repository("users").findMany(); expect(users.length).toBe(2); - expect(users[0].email).toBe(configs.users.normal.email); - expect(users[1].email).toBe(configs.users.admin.email); + expect(users[0]?.email).toBe(configs.users.normal.email); + expect(users[1]?.email).toBe(configs.users.admin.email); }); it("should log you in with API", async () => { @@ -220,7 +221,7 @@ describe("integration auth", () => { app.server.get("/get", auth(), async (c) => { return c.json({ - user: c.get("auth").user ?? null, + user: c.get("auth")?.user ?? null, }); }); app.server.get("/wait", auth(), async (c) => { @@ -239,7 +240,7 @@ describe("integration auth", () => { { await new Promise((r) => setTimeout(r, 10)); const res = await app.server.request("/get"); - const data = await res.json(); + const data = (await res.json()) as any; expect(data.user).toBe(null); expect(await $fns.me()).toEqual({ user: null as any }); } diff --git a/app/__test__/integration/config.integration.test.ts b/app/__test__/integration/config.integration.test.ts index 52c7df2..8e8ba4e 100644 --- a/app/__test__/integration/config.integration.test.ts +++ b/app/__test__/integration/config.integration.test.ts @@ -1,6 +1,10 @@ -import { describe, expect, it } from "bun:test"; +import { afterAll, beforeAll, describe, expect, it } from "bun:test"; import { createApp } from "core/test/utils"; import { Api } from "../../src/Api"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(disableConsoleLog); +afterAll(enableConsoleLog); describe("integration config", () => { it("should create an entity", async () => { diff --git a/app/__test__/media/MediaController.spec.ts b/app/__test__/media/MediaController.spec.ts index f3aeebd..8ce6a0b 100644 --- a/app/__test__/media/MediaController.spec.ts +++ b/app/__test__/media/MediaController.spec.ts @@ -6,11 +6,14 @@ import { createApp } from "core/test/utils"; import { mergeObject, randomString } from "../../src/core/utils"; import type { TAppMediaConfig } from "../../src/media/media-schema"; import { StorageLocalAdapter } from "adapter/node/storage/StorageLocalAdapter"; -import { assetsPath, assetsTmpPath, disableConsoleLog, enableConsoleLog } from "../helper"; +import { assetsPath, assetsTmpPath } from "../helper"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; beforeAll(() => { + disableConsoleLog(); registries.media.register("local", StorageLocalAdapter); }); +afterAll(enableConsoleLog); const path = `${assetsPath}/image.png`; @@ -40,9 +43,6 @@ function makeName(ext: string) { return randomString(10) + "." + ext; } -beforeAll(disableConsoleLog); -afterAll(enableConsoleLog); - describe("MediaController", () => { test("accepts direct", async () => { const app = await makeApp(); diff --git a/app/__test__/modules/AppAuth.spec.ts b/app/__test__/modules/AppAuth.spec.ts index 5ea58ac..89872de 100644 --- a/app/__test__/modules/AppAuth.spec.ts +++ b/app/__test__/modules/AppAuth.spec.ts @@ -3,11 +3,14 @@ import { createApp } from "core/test/utils"; import { AuthController } from "../../src/auth/api/AuthController"; import { em, entity, make, text } from "data/prototype"; import { AppAuth, type ModuleBuildContext } from "modules"; -import { disableConsoleLog, enableConsoleLog } from "../helper"; import { makeCtx, moduleTestSuite } from "./module-test-suite"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(disableConsoleLog); +afterAll(enableConsoleLog); describe("AppAuth", () => { - test.only("...", () => { + test.skip("...", () => { const auth = new AppAuth({}); console.log(auth.toJSON()); console.log(auth.config); diff --git a/app/__test__/modules/AppMedia.spec.ts b/app/__test__/modules/AppMedia.spec.ts index ff86c86..fb5464a 100644 --- a/app/__test__/modules/AppMedia.spec.ts +++ b/app/__test__/modules/AppMedia.spec.ts @@ -7,7 +7,7 @@ import { AppMedia } from "../../src/media/AppMedia"; import { moduleTestSuite } from "./module-test-suite"; describe("AppMedia", () => { - test.only("...", () => { + test.skip("...", () => { const media = new AppMedia(); console.log(media.toJSON()); }); diff --git a/app/__test__/modules/ModuleManager.spec.ts b/app/__test__/modules/ModuleManager.spec.ts index 66f2380..de5c889 100644 --- a/app/__test__/modules/ModuleManager.spec.ts +++ b/app/__test__/modules/ModuleManager.spec.ts @@ -1,5 +1,5 @@ -import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test"; -import { disableConsoleLog, enableConsoleLog } from "core/utils"; +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, mock, test } from "bun:test"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; import { Module } from "modules/Module"; import { getDefaultConfig } from "modules/ModuleManager"; @@ -11,6 +11,9 @@ import { s, stripMark } from "core/utils/schema"; import { Connection } from "data/connection/Connection"; import { entity, text } from "data/prototype"; +beforeAll(disableConsoleLog); +afterAll(enableConsoleLog); + describe("ModuleManager", async () => { test("s1: no config, no build", async () => { const { dummyConnection } = getDummyConnection(); @@ -135,7 +138,7 @@ describe("ModuleManager", async () => { const db = c2.dummyConnection.kysely; const mm2 = new ModuleManager(c2.dummyConnection, { - initial: { version: version - 1, ...json }, + initial: { version: version - 1, ...json } as any, }); await mm2.syncConfigTable(); await db diff --git a/app/__test__/modules/migrations/migrations.spec.ts b/app/__test__/modules/migrations/migrations.spec.ts index 4bd83ab..2113305 100644 --- a/app/__test__/modules/migrations/migrations.spec.ts +++ b/app/__test__/modules/migrations/migrations.spec.ts @@ -1,4 +1,4 @@ -import { describe, expect, test } from "bun:test"; +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { type InitialModuleConfigs, createApp } from "../../../src"; import { type Kysely, sql } from "kysely"; @@ -6,6 +6,10 @@ import { getDummyConnection } from "../../helper"; import v7 from "./samples/v7.json"; import v8 from "./samples/v8.json"; import v8_2 from "./samples/v8-2.json"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(enableConsoleLog); // app expects migratable config to be present in database async function createVersionedApp(config: InitialModuleConfigs | any) { diff --git a/app/package.json b/app/package.json index f72b09e..4c6b2ac 100644 --- a/app/package.json +++ b/app/package.json @@ -3,7 +3,7 @@ "type": "module", "sideEffects": false, "bin": "./dist/cli/index.js", - "version": "0.18.0-rc.3", + "version": "0.18.0-rc.4", "description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.", "homepage": "https://bknd.io", "repository": { @@ -30,7 +30,7 @@ "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly && tsc-alias", "updater": "bun x npm-check-updates -ui", "cli": "LOCAL=1 bun src/cli/index.ts", - "prepublishOnly": "bun run types && bun run test && bun run test:node && VITE_DB_URL=:memory: bun run test:e2e && bun run build:all && cp ../README.md ./", + "prepublishOnly": "bun run types && bun run test && bun run test:node && NODE_NO_WARNINGS=1 VITE_DB_URL=:memory: bun run test:e2e && bun run build:all && cp ../README.md ./", "postpublish": "rm -f README.md", "test": "ALL_TESTS=1 bun test --bail", "test:all": "bun run test && bun run test:node", diff --git a/app/src/adapter/adapter-test-suite.ts b/app/src/adapter/adapter-test-suite.ts index f65e3da..0a224eb 100644 --- a/app/src/adapter/adapter-test-suite.ts +++ b/app/src/adapter/adapter-test-suite.ts @@ -1,6 +1,7 @@ import type { TestRunner } from "core/test"; import type { BkndConfig, DefaultArgs } from "./index"; import type { App } from "App"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; export function adapterTestSuite< Config extends BkndConfig = BkndConfig, @@ -21,7 +22,9 @@ export function adapterTestSuite< }; }, ) { - const { test, expect, mock } = testRunner; + const { test, expect, mock, beforeAll, afterAll } = testRunner; + beforeAll(() => disableConsoleLog()); + afterAll(() => enableConsoleLog()); test(`creates ${label}`, async () => { const beforeBuild = mock(async () => null) as any; diff --git a/app/src/adapter/bun/test.ts b/app/src/adapter/bun/test.ts index 4d453d7..b185776 100644 --- a/app/src/adapter/bun/test.ts +++ b/app/src/adapter/bun/test.ts @@ -1,4 +1,4 @@ -import { expect, test, mock, describe, beforeEach, afterEach, afterAll } from "bun:test"; +import { expect, test, mock, describe, beforeEach, afterEach, afterAll, beforeAll } from "bun:test"; export const bunTestRunner = { describe, @@ -8,4 +8,5 @@ export const bunTestRunner = { beforeEach, afterEach, afterAll, + beforeAll, }; diff --git a/app/src/adapter/cloudflare/connection/DoConnection.vitest.ts b/app/src/adapter/cloudflare/connection/DoConnection.vitest.ts index 695046e..cb209e8 100644 --- a/app/src/adapter/cloudflare/connection/DoConnection.vitest.ts +++ b/app/src/adapter/cloudflare/connection/DoConnection.vitest.ts @@ -1,11 +1,12 @@ /// -import { describe, test, expect } from "vitest"; +import { describe, beforeAll, afterAll } from "vitest"; import { viTestRunner } from "adapter/node/vitest"; import { connectionTestSuite } from "data/connection/connection-test-suite"; import { Miniflare } from "miniflare"; import { doSqlite } from "./DoConnection"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; const script = ` import { DurableObject } from "cloudflare:workers"; @@ -40,6 +41,9 @@ export default { } `; +beforeAll(() => disableConsoleLog()); +afterAll(() => enableConsoleLog()); + describe("doSqlite", async () => { connectionTestSuite(viTestRunner, { makeConnection: async () => { diff --git a/app/src/adapter/cloudflare/drivers/cache.vitest.ts b/app/src/adapter/cloudflare/drivers/cache.vitest.ts index d9a856d..65c6608 100644 --- a/app/src/adapter/cloudflare/drivers/cache.vitest.ts +++ b/app/src/adapter/cloudflare/drivers/cache.vitest.ts @@ -3,6 +3,10 @@ import { cacheWorkersKV } from "./cache"; import { viTestRunner } from "adapter/node/vitest"; import { cacheDriverTestSuite } from "core/drivers/cache/cache-driver-test-suite"; import { Miniflare } from "miniflare"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(() => enableConsoleLog()); describe("cacheWorkersKV", async () => { beforeAll(() => { diff --git a/app/src/adapter/cloudflare/storage/StorageR2Adapter.vitest.ts b/app/src/adapter/cloudflare/storage/StorageR2Adapter.vitest.ts index 437ec9b..8ad1d90 100644 --- a/app/src/adapter/cloudflare/storage/StorageR2Adapter.vitest.ts +++ b/app/src/adapter/cloudflare/storage/StorageR2Adapter.vitest.ts @@ -3,8 +3,12 @@ import { Miniflare } from "miniflare"; import { StorageR2Adapter } from "./StorageR2Adapter"; import { adapterTestSuite } from "media/storage/adapters/adapter-test-suite"; import path from "node:path"; -import { describe, afterAll, test, expect } from "vitest"; +import { describe, afterAll, test, expect, beforeAll } from "vitest"; import { viTestRunner } from "adapter/node/vitest"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(() => enableConsoleLog()); let mf: Miniflare | undefined; describe("StorageR2Adapter", async () => { diff --git a/app/src/adapter/node/connection/NodeSqliteConnection.vi-test.ts b/app/src/adapter/node/connection/NodeSqliteConnection.vi-test.ts index 2cb9149..205f166 100644 --- a/app/src/adapter/node/connection/NodeSqliteConnection.vi-test.ts +++ b/app/src/adapter/node/connection/NodeSqliteConnection.vi-test.ts @@ -1,8 +1,12 @@ import { nodeSqlite } from "./NodeSqliteConnection"; import { DatabaseSync } from "node:sqlite"; import { connectionTestSuite } from "data/connection/connection-test-suite"; -import { describe } from "vitest"; +import { describe, beforeAll, afterAll } from "vitest"; import { viTestRunner } from "../vitest"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(() => enableConsoleLog()); describe("NodeSqliteConnection", () => { connectionTestSuite(viTestRunner, { diff --git a/app/src/adapter/node/node.adapter.vi-test.ts b/app/src/adapter/node/node.adapter.vi-test.ts index 31cdb31..11bb0f7 100644 --- a/app/src/adapter/node/node.adapter.vi-test.ts +++ b/app/src/adapter/node/node.adapter.vi-test.ts @@ -2,10 +2,6 @@ import { describe, beforeAll, afterAll } from "vitest"; import * as node from "./node.adapter"; import { adapterTestSuite } from "adapter/adapter-test-suite"; import { viTestRunner } from "adapter/node/vitest"; -import { disableConsoleLog, enableConsoleLog } from "core/utils"; - -beforeAll(() => disableConsoleLog()); -afterAll(enableConsoleLog); describe("node adapter", () => { adapterTestSuite(viTestRunner, { diff --git a/app/src/adapter/node/storage/StorageLocalAdapter.vitest.ts b/app/src/adapter/node/storage/StorageLocalAdapter.vitest.ts index 3d13bd5..8b3acf1 100644 --- a/app/src/adapter/node/storage/StorageLocalAdapter.vitest.ts +++ b/app/src/adapter/node/storage/StorageLocalAdapter.vitest.ts @@ -1,9 +1,13 @@ -import { describe } from "vitest"; +import { describe, beforeAll, afterAll } from "vitest"; import { viTestRunner } from "adapter/node/vitest"; import { StorageLocalAdapter } from "adapter/node"; import { adapterTestSuite } from "media/storage/adapters/adapter-test-suite"; import { readFileSync } from "node:fs"; import path from "node:path"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; + +beforeAll(() => disableConsoleLog()); +afterAll(() => enableConsoleLog()); describe("StorageLocalAdapter (node)", async () => { const basePath = path.resolve(import.meta.dirname, "../../../../__test__/_assets"); diff --git a/app/src/adapter/node/test.ts b/app/src/adapter/node/test.ts index 3c78f25..bd1d8a5 100644 --- a/app/src/adapter/node/test.ts +++ b/app/src/adapter/node/test.ts @@ -1,5 +1,5 @@ import nodeAssert from "node:assert/strict"; -import { test, describe, beforeEach, afterEach } from "node:test"; +import { test, describe, beforeEach, afterEach, after, before } from "node:test"; import type { Matcher, Test, TestFn, TestRunner } from "core/test"; // Track mock function calls @@ -99,5 +99,6 @@ export const nodeTestRunner: TestRunner = { }), beforeEach: beforeEach, afterEach: afterEach, - afterAll: () => {}, + afterAll: after, + beforeAll: before, }; diff --git a/app/src/adapter/node/vitest.ts b/app/src/adapter/node/vitest.ts index 8f6988e..ad9afcf 100644 --- a/app/src/adapter/node/vitest.ts +++ b/app/src/adapter/node/vitest.ts @@ -1,5 +1,5 @@ import type { TestFn, TestRunner, Test } from "core/test"; -import { describe, test, expect, vi, beforeEach, afterEach, afterAll } from "vitest"; +import { describe, test, expect, vi, beforeEach, afterEach, afterAll, beforeAll } from "vitest"; function vitestTest(label: string, fn: TestFn, options?: any) { return test(label, fn as any); @@ -50,4 +50,5 @@ export const viTestRunner: TestRunner = { beforeEach: beforeEach, afterEach: afterEach, afterAll: afterAll, + beforeAll: beforeAll, }; diff --git a/app/src/core/test/index.ts b/app/src/core/test/index.ts index 4e9bfef..0afecb2 100644 --- a/app/src/core/test/index.ts +++ b/app/src/core/test/index.ts @@ -31,6 +31,7 @@ export type TestRunner = { beforeEach: (fn: () => MaybePromise) => void; afterEach: (fn: () => MaybePromise) => void; afterAll: (fn: () => MaybePromise) => void; + beforeAll: (fn: () => MaybePromise) => void; }; export async function retry( diff --git a/app/src/core/utils/test.ts b/app/src/core/utils/test.ts index 44d38d9..5107c4b 100644 --- a/app/src/core/utils/test.ts +++ b/app/src/core/utils/test.ts @@ -6,6 +6,8 @@ const _oldConsoles = { warn: console.warn, error: console.error, }; +let _oldStderr: any; +let _oldStdout: any; export async function withDisabledConsole( fn: () => Promise, @@ -36,10 +38,17 @@ export function disableConsoleLog(severities: ConsoleSeverity[] = ["log", "warn" severities.forEach((severity) => { console[severity] = () => null; }); + // Disable stderr + _oldStderr = process.stderr.write; + _oldStdout = process.stdout.write; + process.stderr.write = () => true; + process.stdout.write = () => true; $console?.setLevel("critical"); } export function enableConsoleLog() { + process.stderr.write = _oldStderr; + process.stdout.write = _oldStdout; Object.entries(_oldConsoles).forEach(([severity, fn]) => { console[severity as ConsoleSeverity] = fn; }); diff --git a/app/src/data/connection/connection-test-suite.ts b/app/src/data/connection/connection-test-suite.ts index 894f143..270ccb0 100644 --- a/app/src/data/connection/connection-test-suite.ts +++ b/app/src/data/connection/connection-test-suite.ts @@ -4,6 +4,7 @@ import { getPath } from "bknd/utils"; import * as proto from "data/prototype"; import { createApp } from "App"; import type { MaybePromise } from "core/types"; +import { disableConsoleLog, enableConsoleLog } from "core/utils/test"; // @todo: add various datatypes: string, number, boolean, object, array, null, undefined, date, etc. // @todo: add toDriver/fromDriver tests on all types and fields @@ -21,7 +22,9 @@ export function connectionTestSuite( rawDialectDetails: string[]; }, ) { - const { test, expect, describe, beforeEach, afterEach, afterAll } = testRunner; + const { test, expect, describe, beforeEach, afterEach, afterAll, beforeAll } = testRunner; + beforeAll(() => disableConsoleLog()); + afterAll(() => enableConsoleLog()); describe("base", () => { let ctx: Awaited>; diff --git a/app/src/modules/db/DbModuleManager.ts b/app/src/modules/db/DbModuleManager.ts index 45f597c..6b9da06 100644 --- a/app/src/modules/db/DbModuleManager.ts +++ b/app/src/modules/db/DbModuleManager.ts @@ -571,7 +571,7 @@ export class DbModuleManager extends ModuleManager { return result; } catch (e) { - $console.error(`[Safe Mutate] failed "${name}":`, e); + $console.error(`[Safe Mutate] failed "${name}":`, String(e)); // revert to previous config & rebuild using original listener this.revertModules(); diff --git a/app/src/ui/elements/media/helper.spec.ts b/app/src/ui/elements/media/helper.spec.ts index 1ef8e96..fb9280b 100644 --- a/app/src/ui/elements/media/helper.spec.ts +++ b/app/src/ui/elements/media/helper.spec.ts @@ -51,13 +51,5 @@ describe("media helper", () => { added: 1, }), ).toEqual({ reject: false, to_drop: 1 }); - console.log( - checkMaxReached({ - maxItems: 6, - current: 0, - overwrite: true, - added: 1, - }), - ); }); });