From 254b02c66e93394baff5019592bdb45ffd55a2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Thu, 29 Feb 2024 19:30:50 +0100 Subject: [PATCH] Incorporated feedback on #6494 (#6521) --- .../tests/src/hooks/import-app-before.ts | 41 ++++++------------- .../tests/src/tests/sync/logging.ts | 2 +- .../tests/src/utils/print-warning-box.ts | 28 +++++++++++++ 3 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 integration-tests/tests/src/utils/print-warning-box.ts diff --git a/integration-tests/tests/src/hooks/import-app-before.ts b/integration-tests/tests/src/hooks/import-app-before.ts index 94621b886c..c3bad5017c 100644 --- a/integration-tests/tests/src/hooks/import-app-before.ts +++ b/integration-tests/tests/src/hooks/import-app-before.ts @@ -20,6 +20,7 @@ import Realm from "realm"; import { AppConfig, AppImporter, Credentials } from "@realm/app-importer"; import { mongodbServiceType } from "../utils/ExtendedAppConfigBuilder"; +import { printWarningBox } from "../utils/print-warning-box"; const REALM_LOG_LEVELS = ["all", "trace", "debug", "detail", "info", "warn", "error", "fatal", "off"]; @@ -46,23 +47,18 @@ export type AppConfigurationRelaxed = { baseFilePath?: string; }; -function getCredentials(): Credentials { - if (typeof publicKey === "string" && typeof privateKey === "string") { - return { - kind: "api-key", - publicKey, - privateKey, - }; - } else { - return { - kind: "username-password", - username, - password, - }; - } -} - -const credentials = getCredentials(); +const credentials: Credentials = + typeof publicKey === "string" && typeof privateKey === "string" + ? { + kind: "api-key", + publicKey, + privateKey, + } + : { + kind: "username-password", + username, + password, + }; const importer = new AppImporter({ baseUrl, @@ -79,17 +75,6 @@ function isConnectionRefused(err: unknown) { ); } -function printWarningBox(...lines: string[]) { - const contentWidth = Math.max(...lines.map((line) => line.length)); - const bar = "━".repeat(contentWidth + 2); - console.warn(`┏${bar}┓`); - for (const line of lines) { - const padding = " ".repeat(contentWidth - line.length); - console.warn(`┃ ${line}${padding} ┃`); - } - console.warn(`┗${bar}┛`); -} - /** Ensure we'll only ever install a single after hook with this warning */ let skippedAppImportAfterHookInstalled = false; function ensureSkippedAppImportAfterHook() { diff --git a/integration-tests/tests/src/tests/sync/logging.ts b/integration-tests/tests/src/tests/sync/logging.ts index cf11a5cffa..196aa0bca9 100644 --- a/integration-tests/tests/src/tests/sync/logging.ts +++ b/integration-tests/tests/src/tests/sync/logging.ts @@ -23,7 +23,7 @@ import { buildAppConfig } from "../../utils/build-app-config"; describe("Logging", () => { importAppBefore(buildAppConfig("with-pbs").anonAuth().flexibleSync()); afterEach(() => Realm.clearTestState()); - // Skipped because reusing a single app across tests break this + it("can set custom logging function", async function (this: AppContext) { const credentials = Realm.Credentials.anonymous(); diff --git a/integration-tests/tests/src/utils/print-warning-box.ts b/integration-tests/tests/src/utils/print-warning-box.ts new file mode 100644 index 0000000000..2af0f2cb65 --- /dev/null +++ b/integration-tests/tests/src/utils/print-warning-box.ts @@ -0,0 +1,28 @@ +//////////////////////////////////////////////////////////////////////////// +// +// Copyright 2024 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////// + +export function printWarningBox(...lines: string[]) { + const contentWidth = Math.max(...lines.map((line) => line.length)); + const bar = "━".repeat(contentWidth + 2); + console.warn(`┏${bar}┓`); + for (const line of lines) { + const padding = " ".repeat(contentWidth - line.length); + console.warn(`┃ ${line}${padding} ┃`); + } + console.warn(`┗${bar}┛`); +}