Skip to content

Commit

Permalink
Merge branch 'main' into fp/core-logging
Browse files Browse the repository at this point in the history
* main:
  Added note in docs for change listeners (#5749)
  Update CHANGELOG entry (#5751)
  Use `SchemaParseError` for invalid schemas (#5722)
  Improving Electron tests (#5738)
  Support SSL Sync Configuration (#5507)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
papafe committed Apr 21, 2023
2 parents af0e164 + f8e0cc9 commit 0044a20
Show file tree
Hide file tree
Showing 28 changed files with 2,312 additions and 2,065 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/pr-realm-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,9 @@ jobs:
name: realm-js-prebuilds

- name: Install dependencies
# Ignoring scripts to prevent building if a prebuild is missing
run: npm ci --ignore-scripts

- name: Install prebuild
if: ${{ matrix.variant.environment == 'node' || matrix.variant.environment == 'electron' }}
run: npx --workspace realm prebuild-install --runtime napi --verbose
run: npm ci
env:
# Ensure we install the prebuild built in the previous job
npm_config_realm_local_prebuilds: ${{github.workspace}}/packages/realm/prebuilds

- name: Invoke the simulator (making subsequent "open -a Simulator" calls work)
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* None

### Enhancements
* Opening a Realm with invalid schemas will throw a `SchemaParseError` (or one of its subtypes `ObjectSchemaParseError` and `PropertySchemaParseError`) rather than an `AssertionError` or `Error`. ([#5198](https://github.com/realm/realm-js/issues/5198))
* Enable multiple processes to operate on an encrypted Realm simultaneously. ([realm/realm-core#1845](https://github.com/realm/realm-core/issues/1845))
* Added `Realm.setLogger`, that allows to setup a single static logger for the duration of the app lifetime. Differently from the now deprecated sync logger (that was setup with `Sync.setLogger`), this new one will emit messages coming also from the local database, and not only from sync. It is also possible to change the log level during the whole duration of the app lifetime with `Realm.setLogLevel`. ([#2546](https://github.com/realm/realm-js/issues/2546))
* Added support for a sync configuration option to provide an `SSLConfiguration` with a custom function for validating the server's SSL certificate. [#5485](https://github.com/realm/realm-js/issues/5485)

### Fixed
* Fix a stack overflow crash when using the query parser with long chains of AND/OR conditions. ([realm/realm-core#6428](https://github.com/realm/realm-core/pull/6428), since v10.11.0)
Expand Down
7 changes: 7 additions & 0 deletions integration-tests/environments/electron/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
// This file is pretty much a copy of https://github.com/electron/electron-quick-start/blob/master/main.js
const electron = require("electron");
const { app, BrowserWindow } = electron;
// Needed to forward console logs
const remote = require("@electron/remote/main");
remote.initialize();

// Increasing memory
// app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096');
Expand All @@ -39,11 +42,15 @@ app.on("ready", () => {
mainWindow = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
preload,
},
});

remote.enable(mainWindow.webContents);

mainWindow.loadFile(path.join(__dirname, "index.html"));
} else {
console.error("Expected a process runtime argument");
Expand Down
7 changes: 6 additions & 1 deletion integration-tests/environments/electron/app/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const processType = process.type === "browser" ? "main" : process.type;

console.log("Required Mocha client");

return new Client({
const client = new Client({
id: processType,
title: `Electron v${process.versions.electron} ${processType} process on ${platform()}`,
tests(context) {
Expand All @@ -40,3 +40,8 @@ return new Client({
require("@realm/integration-tests");
},
});

client.on("error", (err) => {
console.error("Failure from Mocha Remote Client:", err);
process.exitCode = 1;
});
2 changes: 1 addition & 1 deletion integration-tests/environments/electron/app/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// Disables security warnings which spams the console
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;

const remote = require("electron").remote;
const remote = require("@electron/remote");

// Use the main process console when logging
global.console = remote.getGlobal("console");
Expand Down
22 changes: 11 additions & 11 deletions integration-tests/environments/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"test": "wireit",
"test:main": "wireit",
"test:renderer": "wireit",
"test:ci:main": "mocha-remote --reporter @realm/mocha-reporter --id main node runner.js main",
"test:ci:renderer": "mocha-remote --reporter @realm/mocha-reporter --id main node runner.js renderer",
"test:ci:main": "mocha-remote --reporter mocha-github-actions-reporter --id main tsx runner.ts main",
"test:ci:renderer": "mocha-remote --reporter mocha-github-actions-reporter --id renderer tsx runner.ts renderer",
"lint": "eslint .",
"package": "electron-builder --dir"
},
Expand All @@ -23,7 +23,7 @@
"command": "npm run test:main && npm run test:renderer"
},
"test:main": {
"command": "mocha-remote --reporter @realm/mocha-reporter --id main node runner.js main",
"command": "mocha-remote --reporter @realm/mocha-reporter --id main tsx runner.ts main",
"dependencies": [
"../../../packages/realm:bundle",
"../../../packages/realm:build:node",
Expand All @@ -33,7 +33,7 @@
]
},
"test:renderer": {
"command": "mocha-remote --reporter @realm/mocha-reporter --id main node runner.js renderer",
"command": "mocha-remote --reporter @realm/mocha-reporter --id renderer tsx runner.ts renderer",
"dependencies": [
"../../../packages/realm:bundle",
"../../../packages/realm:build:node",
Expand All @@ -45,16 +45,16 @@
},
"devDependencies": {
"@realm/mocha-reporter": "*",
"cmake-js": "^6.1.0",
"command-line-args": "^5.1.1",
"concurrently": "^6.0.2",
"electron": "^12.2.1",
"electron-builder": "^22.10.5",
"mocha-github-actions-reporter": "^0.2.3",
"mocha-junit-reporter": "^2.0.0",
"command-line-args": "^5.2.1",
"concurrently": "^8.0.1",
"electron": "^24.1.2",
"electron-builder": "^23.6.0",
"mocha-github-actions-reporter": "^0.3.0",
"mocha-junit-reporter": "^2.2.0",
"mocha-remote-cli": "^1.6.1"
},
"dependencies": {
"@electron/remote": "^2.0.9",
"@realm/integration-tests": "*",
"fs-extra": "^9.1.0",
"mocha-remote-client": "^1.6.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,32 @@
//
////////////////////////////////////////////////////////////////////////////

const { spawn } = require("child_process");
const fs = require("fs");
const path = require("path");
import { spawn } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import module from "node:module"
import { rollup } from "rollup";

const require = module.createRequire(import.meta.url);

// Adjust this as the expected execution time increases
const TIMEOUT_MS = 1000 * 30; // 30 seconds

const appPaths = {
type ProcessType = "main" | "renderer";

const appPaths: Partial<Record<NodeJS.Platform, string>> = {
darwin: "dist/mac/realm-electron-tests.app/Contents/MacOS/realm-electron-tests",
linux: "dist/linux-unpacked/realm-electron-tests",
win32: "dist/win-unpacked/realm-electron-tests.exe",
};

function determineSpawnParameters(processType) {
function determineSpawnParameters(processType: ProcessType) {
const platform = process.platform;
const appPath = path.resolve(appPaths[platform]);
const relativeAppPath = appPaths[platform];
if (!relativeAppPath) {
throw new Error(`Unsupported platform: ${platform}`);
}
const appPath = path.resolve(relativeAppPath);
if (fs.existsSync(appPath)) {
if (platform === "darwin") {
return {
Expand All @@ -50,7 +60,7 @@ function determineSpawnParameters(processType) {
}
}

function runElectron(processType) {
function runElectron(processType: ProcessType) {
const { command, args } = determineSpawnParameters(processType);
// Spawn the Electron app
const env = Object.create(process.env);
Expand All @@ -74,7 +84,7 @@ async function run() {
console.log(`Started the Electron app (pid = ${appProcess.pid})`);
}

function timeout(ms) {
function timeout(ms: number) {
return new Promise((_, reject) => {
setTimeout(() => {
const err = new Error(`Timed out after ${ms}ms`);
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/environments/electron/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"esModuleInterop": true,
"moduleResolution": "node",
"useDefineForClassFields": false
}
}
4 changes: 1 addition & 3 deletions integration-tests/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
"name": "@realm/integration-tests",
"version": "0.1.0",
"description": "A set of tests that can run in different environments",
"type": "module",
"main": "src/index.ts",
"exports": {
".": "./src/index.ts",
"./node": "./src/node/index.ts",
"./electron": "./dist/index.js"
"./node": "./src/node/index.ts"
},
"private": true,
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/tests/src/utils/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
////////////////////////////////////////////////////////////////////////////

import { benchmark, BenchmarkOpts } from "@thi.ng/bench";
import type { BenchmarkOpts } from "@thi.ng/bench";

import { openRealmBefore } from "../hooks";

Expand All @@ -28,6 +28,7 @@ const DEFAULT_OPTIONS: Partial<BenchmarkOpts> = { output: false, iter: 1000, siz

export function itPerforms(title: string, fn: () => void, options?: Partial<BenchmarkOpts>): void {
it(title, async function (this: Partial<BenchmarkContext> & Mocha.Context) {
const { benchmark } = await import("@thi.ng/bench");
this.timeout("1m").slow("1m");
const result = benchmark(fn.bind(this), { ...DEFAULT_OPTIONS, ...options });
const hz = (result.iter * result.size) / (result.total / 1000);
Expand Down
Loading

0 comments on commit 0044a20

Please sign in to comment.