Skip to content

Commit

Permalink
Incorporated feedback on #6494
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Feb 29, 2024
1 parent 6e60915 commit 95e458c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
41 changes: 13 additions & 28 deletions integration-tests/tests/src/hooks/import-app-before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand All @@ -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,
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/src/tests/sync/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
28 changes: 28 additions & 0 deletions integration-tests/tests/src/utils/print-warning-box.ts
Original file line number Diff line number Diff line change
@@ -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}┛`);
}

0 comments on commit 95e458c

Please sign in to comment.