Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
import { BentleyCloudRpcManager } from "@bentley/imodeljs-common";
import { rpcInterfaces } from "../common/TestRpcInterface";
import { IModelJsExpressServer } from "@bentley/express-server";
import { registerBackendCallback } from "@bentley/certa/lib/utils/CallbackUtils";
import { BackendTestCallbacks } from "../common/SideChannels";
import "./CommonBackendSetup";
registerBackendCallback(BackendTestCallbacks.getEnvironment, () => "http");
async function init() {
const rpcConfig = BentleyCloudRpcManager.initializeImpl({ info: { title: "rpc-integration-test", version: "v1.0" } }, rpcInterfaces);
// create a basic express web server
const port = Number(process.env.CERTA_PORT || 3021) + 2000;
const server = new IModelJsExpressServer(rpcConfig.protocol);
await server.initialize(port);
// tslint:disable-next-line:no-console
console.log("Web backend for integration-tests listening on port " + port);
}
module.exports = init();
import { BackendTestCallbacks } from "../common/SideChannels";
import { TestRpcImpl2, resetOp8Initializer } from "./TestRpcImpl";
IModelJsConfig.init(true, true, Config.App);
RpcConfiguration.developmentMode = true;
// Start the backend
IModelHost.startup();
registerBackendCallback(BackendTestCallbacks.registerTestRpcImpl2Class, () => {
TestRpcImpl2.register();
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.replaceTestRpcImpl2Instance, () => {
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.unregisterTestRpcImpl2Class, () => {
TestRpcImpl2.unregister();
return true;
});
registerBackendCallback(BackendTestCallbacks.setIncompatibleInterfaceVersion, () => {
IModelReadRpcInterface.interfaceVersion = "0.0.0";
return true;
});
const compatibleVersion = IModelReadRpcInterface.interfaceVersion;
registerBackendCallback(BackendTestCallbacks.restoreIncompatibleInterfaceVersion, () => {
import { IModelHost } from "@bentley/imodeljs-backend";
import { RpcConfiguration, IModelReadRpcInterface } from "@bentley/imodeljs-common";
import { Logger, LogLevel } from "@bentley/bentleyjs-core";
import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig";
import { Config } from "@bentley/imodeljs-clients";
import { registerBackendCallback } from "@bentley/certa/lib/utils/CallbackUtils";
import { BackendTestCallbacks } from "../common/SideChannels";
import { TestRpcImpl2, resetOp8Initializer } from "./TestRpcImpl";
IModelJsConfig.init(true, true, Config.App);
RpcConfiguration.developmentMode = true;
// Start the backend
IModelHost.startup();
registerBackendCallback(BackendTestCallbacks.registerTestRpcImpl2Class, () => {
TestRpcImpl2.register();
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.replaceTestRpcImpl2Instance, () => {
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.unregisterTestRpcImpl2Class, () => {
TestRpcImpl2.unregister();
return true;
});
registerBackendCallback(BackendTestCallbacks.setIncompatibleInterfaceVersion, () => {
// Start the backend
IModelHost.startup();
registerBackendCallback(BackendTestCallbacks.registerTestRpcImpl2Class, () => {
TestRpcImpl2.register();
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.replaceTestRpcImpl2Instance, () => {
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.unregisterTestRpcImpl2Class, () => {
TestRpcImpl2.unregister();
return true;
});
registerBackendCallback(BackendTestCallbacks.setIncompatibleInterfaceVersion, () => {
IModelReadRpcInterface.interfaceVersion = "0.0.0";
return true;
});
const compatibleVersion = IModelReadRpcInterface.interfaceVersion;
registerBackendCallback(BackendTestCallbacks.restoreIncompatibleInterfaceVersion, () => {
IModelReadRpcInterface.interfaceVersion = compatibleVersion;
return true;
});
registerBackendCallback(BackendTestCallbacks.resetOp8Initializer, () => {
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.unregisterTestRpcImpl2Class, () => {
TestRpcImpl2.unregister();
return true;
});
registerBackendCallback(BackendTestCallbacks.setIncompatibleInterfaceVersion, () => {
IModelReadRpcInterface.interfaceVersion = "0.0.0";
return true;
});
const compatibleVersion = IModelReadRpcInterface.interfaceVersion;
registerBackendCallback(BackendTestCallbacks.restoreIncompatibleInterfaceVersion, () => {
IModelReadRpcInterface.interfaceVersion = compatibleVersion;
return true;
});
registerBackendCallback(BackendTestCallbacks.resetOp8Initializer, () => {
resetOp8Initializer();
return true;
});
Logger.initializeToConsole();
Logger.setLevel("imodeljs-backend.IModelReadRpcImpl", LogLevel.Error); // Change to trace to debug
Logger.setLevel("imodeljs-backend.IModelDb", LogLevel.Error); // Change to trace to debug
Logger.setLevel("Performance", LogLevel.Error); // Change to Info to capture
TestRpcImpl2.unregister();
return true;
});
registerBackendCallback(BackendTestCallbacks.setIncompatibleInterfaceVersion, () => {
IModelReadRpcInterface.interfaceVersion = "0.0.0";
return true;
});
const compatibleVersion = IModelReadRpcInterface.interfaceVersion;
registerBackendCallback(BackendTestCallbacks.restoreIncompatibleInterfaceVersion, () => {
IModelReadRpcInterface.interfaceVersion = compatibleVersion;
return true;
});
registerBackendCallback(BackendTestCallbacks.resetOp8Initializer, () => {
resetOp8Initializer();
return true;
});
Logger.initializeToConsole();
Logger.setLevel("imodeljs-backend.IModelReadRpcImpl", LogLevel.Error); // Change to trace to debug
Logger.setLevel("imodeljs-backend.IModelDb", LogLevel.Error); // Change to trace to debug
Logger.setLevel("Performance", LogLevel.Error); // Change to Info to capture
TestRpcImpl2.register();
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.replaceTestRpcImpl2Instance, () => {
TestRpcImpl2.instantiate();
return true;
});
registerBackendCallback(BackendTestCallbacks.unregisterTestRpcImpl2Class, () => {
TestRpcImpl2.unregister();
return true;
});
registerBackendCallback(BackendTestCallbacks.setIncompatibleInterfaceVersion, () => {
IModelReadRpcInterface.interfaceVersion = "0.0.0";
return true;
});
const compatibleVersion = IModelReadRpcInterface.interfaceVersion;
registerBackendCallback(BackendTestCallbacks.restoreIncompatibleInterfaceVersion, () => {
IModelReadRpcInterface.interfaceVersion = compatibleVersion;
return true;
});
registerBackendCallback(BackendTestCallbacks.resetOp8Initializer, () => {
resetOp8Initializer();
return true;
});
Logger.initializeToConsole();