Skip to content

Commit

Permalink
Merge bac1f30 into 6277e34
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Dec 14, 2023
2 parents 6277e34 + bac1f30 commit 389eced
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
- name: Run tests with coverage
timeout-minutes: 60
env:
CONTEXT: syncLogLevel=warn,longTimeout=${{ env.LONG_TIMEOUT }}
# CONTEXT: syncLogLevel=warn,longTimeout=${{ env.LONG_TIMEOUT }},realmBaseUrl=${{ secrets.REALM_QA_BASE_URL }},mongodbClusterName=${{ secrets.ATLAS_QA_DAILY_CLUSTER_NAME }},privateKey=${{ secrets.ATLAS_QA_PRIVATE_API_KEY }},publicKey=${{ secrets.ATLAS_QA_PUBLIC_API_KEY }}
CONTEXT: longTimeout=${{ env.LONG_TIMEOUT }}
# CONTEXT: longTimeout=${{ env.LONG_TIMEOUT }},realmBaseUrl=${{ secrets.REALM_QA_BASE_URL }},mongodbClusterName=${{ secrets.ATLAS_QA_DAILY_CLUSTER_NAME }},privateKey=${{ secrets.ATLAS_QA_PRIVATE_API_KEY }},publicKey=${{ secrets.ATLAS_QA_PUBLIC_API_KEY }}
run: npm run ci:coverage --workspace @realm/integration-tests -- --reporter mocha-github-actions-reporter --timeout ${{ env.MOCHA_TIMEOUT }}

- name: Coveralls
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-realm-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ jobs:

- name: Create Mocha Remote Context
id: mocha-env
run: echo "context=syncLogLevel=warn,longTimeout=${{ env.LONG_TIMEOUT }},realmBaseUrl=${{ steps.baas-config.outputs.url }}" >> $GITHUB_OUTPUT
run: echo "context=printLogAfterTest=on-failure,longTimeout=${{ env.LONG_TIMEOUT }},realmBaseUrl=${{ steps.baas-config.outputs.url }}" >> $GITHUB_OUTPUT

- name: Wait for the server to start
run: npx wait-on ${{ steps.baas-config.outputs.url }}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ Examples of context variables used:
- `integration=false`: Skip the integration test (which performance tests are not considered a part of).
- `preserveAppAfterRun`: Skip deleting the Realm app after the test run
- `defaultLogLevel=all`: Set the default log level to help debugging realm core issues.
- `syncLogLevel=all`: Set the sync client log level to help debugging sync client issues.
- `reuseApp=true`: Instructs the app importer to reuse and reconfigure a single app. Defaults to `false`.
- `realmBaseUrl=https://localhost:9090`: Set the base URL used when connecting the the server.
- `mongodbClusterName=Cluster0`: Set the name of the cluster, used when setting up the "mongodb-atlas" service on imported apps.
- `mongodbServiceType`: Set the type of mongodb service, used when importing. Defaults to `mongodb` or `mongodb-atlas` if `mongodbClusterName` is set.
- `printLogAfterTest=on-failure`: Enable printing of the log after every test failure

As an example, to iterate on the performence tests, run the `./tests` (on Node.js) skipping tests that require a server as well as the integration tests and enable performance tests:

Expand Down
1 change: 1 addition & 0 deletions integration-tests/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"@thi.ng/bench": "^3.1.16",
"chai": "4.3.6",
"chai-as-promised": "^7.1.1",
"chalk": "^4.1.2",
"concurrently": "^6.0.2",
"jsrsasign": "^10.6.1"
},
Expand Down
22 changes: 6 additions & 16 deletions integration-tests/tests/src/hooks/import-app-before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
//
////////////////////////////////////////////////////////////////////////////

import Realm, { AppConfiguration } from "realm";
import Realm from "realm";

import { importApp } from "../utils/import-app";
import { AppConfig } from "@realm/app-importer";
import { mongodbServiceType } from "../utils/ExtendedAppConfigBuilder";

const REALM_LOG_LEVELS = ["all", "trace", "debug", "detail", "info", "warn", "error", "fatal", "off"];

const { syncLogLevel = "warn" } = environment;

export type AppConfigurationRelaxed = {
id?: string;
baseUrl?: string;
Expand Down Expand Up @@ -65,20 +61,14 @@ export function importAppBefore(config: AppConfig | { config: AppConfig }, sdkCo
} else if (databaseNames.length > 1) {
throw new Error("Expected at most 1 database name in the config");
}

Realm.App.Sync.setLogLevel(this.app, syncLogLevel);
// Set a default logger as Android does not forward stdout
Realm.App.Sync.setLogger(this.app, (level, message) => {
const time = new Date().toISOString().split("T")[1].replace("Z", "");
const magentaTime = `\x1b[35m${time}`;
const greenLogLevel = `\x1b[32m${REALM_LOG_LEVELS[level].toUpperCase()}`;
const whiteMessage = `\x1b[37m${message}}`;

console.log(`${magentaTime}: ${greenLogLevel}:\t${whiteMessage}`);
});
}
});

after("muteAppLog", function (this: AppContext & Mocha.Context) {
// Mute the log to avoid lifetime issues when reading out strings from the logger
Realm.App.Sync.setLogLevel(this.app, "off");
});

after("removeUsersAfter", async function (this: Partial<AppContext> & Mocha.Context) {
const { app } = this;
if (app) {
Expand Down
41 changes: 40 additions & 1 deletion integration-tests/tests/src/setup-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,46 @@ describe("Test Harness", function (this: Mocha.Suite) {
import Realm from "realm";

// Disable the logger to avoid console flooding
const { defaultLogLevel = "off" } = environment;
const { printLogAfterTest = false, defaultLogLevel = printLogAfterTest ? "all" : "off" } = environment;
Realm.setLogLevel(defaultLogLevel);

import chalk from "chalk";

/**
* Contains the Realm log since the test started.
*/
let log: { level: ValidRealmLogLevel; message: string }[] = [];

if (printLogAfterTest) {
Realm.setLogger((level: Realm.App.Sync.LogLevel, message: string) => {
if (level !== "off" && level !== "all") {
log.push({ level, message });
}
});
}

// Reset the log before each test
beforeEach(() => {
log = [];
});

const logColors: Record<ValidRealmLogLevel, chalk.Chalk> = {
trace: chalk.dim,
debug: chalk.dim,
detail: chalk.dim,
info: chalk.blue,
warn: chalk.yellow,
error: chalk.red,
fatal: chalk.red,
};

afterEach(function (this: Mocha.Context) {
if (printLogAfterTest === true || (printLogAfterTest === "on-failure" && this.currentTest?.isFailed())) {
for (const { level, message } of log) {
const color = logColors[level];
console.log(`[${color(level)}] ${message}`);
}
}
});

Realm.flags.THROW_ON_GLOBAL_REALM = true;
6 changes: 4 additions & 2 deletions integration-tests/tests/src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type KnownEnvironment = {
reuseApp?: true;
/** Set the default log level to help debugging realm core issues */
defaultLogLevel?: Realm.App.Sync.LogLevel;
/** Set the sync client log level to help debugging sync client issues */
syncLogLevel?: Realm.App.Sync.LogLevel;
/** Enable printing of the log after every test */
printLogAfterTest?: boolean | "on-failure";

// BaaS server and Realm App Importer specific variables below

Expand Down Expand Up @@ -159,6 +159,8 @@ declare namespace Mocha {
type AppContext = { app: Realm.App; databaseName: string } & Mocha.Context;
type UserContext = { user: Realm.User } & Mocha.Context;
type CloseRealmOptions = { deleteFile: boolean; clearTestState: boolean; reopen: boolean };

type ValidRealmLogLevel = Exclude<Realm.App.Sync.LogLevel, "off" | "all">;
type RealmContext = {
realm: Realm;
/**
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 389eced

Please sign in to comment.