@itwin/presentation-testing 4.0.1 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  # Change Log - @itwin/presentation-testing
2
2
 
3
- This log was last generated on Thu, 15 Jun 2023 07:31:15 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 09 Aug 2023 11:46:49 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 4.0.2
8
+
9
+ Wed, 09 Aug 2023 11:46:49 GMT
10
+
11
+ ### Patches
12
+
13
+ - Update package dependencies ([commit](https://github.com/iTwin/presentation/commit/3f36136778e2444c1224a5b68b0a21f707b5685f))
14
+
7
15
  ## 4.0.1
8
16
 
9
- Thu, 15 Jun 2023 07:31:15 GMT
17
+ Thu, 15 Jun 2023 07:31:33 GMT
10
18
 
11
19
  ### Patches
12
20
 
@@ -2,6 +2,7 @@
2
2
  * @module Helpers
3
3
  */
4
4
  import { IModelHostOptions } from "@itwin/core-backend";
5
+ import { RpcInterfaceDefinition } from "@itwin/core-common";
5
6
  import { IModelApp, IModelAppOptions } from "@itwin/core-frontend";
6
7
  import { HierarchyCacheMode, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from "@itwin/presentation-backend";
7
8
  import { PresentationProps as PresentationFrontendProps } from "@itwin/presentation-frontend";
@@ -10,6 +11,12 @@ export declare const getTestOutputDir: () => string;
10
11
  export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
11
12
  /** @public */
12
13
  export interface PresentationTestingInitProps {
14
+ /**
15
+ * RPC interfaces to enable. Defaults to `[SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]`.
16
+ *
17
+ * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.
18
+ */
19
+ rpcs?: RpcInterfaceDefinition[];
13
20
  /** Properties for backend initialization */
14
21
  backendProps?: PresentationBackendProps;
15
22
  /** Properties for `IModelHost` */
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAOH,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAElB,wBAAwB,IAAI,wBAAwB,EACpD,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AA0BpI,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,QAAO,MAEnC,CAAC;AAGF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,CAAC;AAEjF,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,6CAA6C;IAC7C,aAAa,CAAC,EAAE,yBAAyB,CAAC;IAC1C,+BAA+B;IAC/B,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IACtE,0BAA0B;IAC1B,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IACtC,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,WAAkB,4BAA4B,kBAoCpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDA0BrB,CAAC"}
1
+ {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAOH,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAqE,sBAAsB,EAA8B,MAAM,oBAAoB,CAAC;AAC3J,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAElB,wBAAwB,IAAI,wBAAwB,EACpD,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AA0BpI,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,QAAO,MAEnC,CAAC;AAGF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,CAAC;AAEjF,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,IAAI,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAChC,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,6CAA6C;IAC7C,aAAa,CAAC,EAAE,yBAAyB,CAAC;IAC1C,+BAA+B;IAC/B,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IACtE,0BAA0B;IAC1B,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IACtC,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,WAAkB,4BAA4B,kBAoCpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDA0BrB,CAAC"}
@@ -92,7 +92,7 @@ const initialize = async (props) => {
92
92
  props = {};
93
93
  }
94
94
  // set up rpc interfaces
95
- initializeRpcInterfaces([core_common_1.SnapshotIModelRpcInterface, core_common_1.IModelReadRpcInterface, presentation_common_1.PresentationRpcInterface]);
95
+ initializeRpcInterfaces(props.rpcs ?? [core_common_1.SnapshotIModelRpcInterface, core_common_1.IModelReadRpcInterface, presentation_common_1.PresentationRpcInterface]);
96
96
  // init backend
97
97
  // make sure backend gets assigned an id which puts its resources into a unique directory
98
98
  props.backendProps = props.backendProps ?? {};
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,0BAA0B,CAAC,uGAAuG;AAElI,2BAA4B;AAC5B,+BAA4B;AAC5B,+CAAiC;AACjC,sDAAoE;AACpE,sDAA2C;AAC3C,oDAA2J;AAC3J,wDAAgF;AAChF,sEAKqC;AAkC5B,mGAtCP,yCAAkB,OAsCO;AAAE,wGAnC3B,8CAAuB,OAmC2B;AAjCpD,oEAAsE;AACtE,wEAAoI;AAEpI,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,MAAM,GAAG,KAAM,SAAQ,qCAAuB;QAArC;;YACG;;;;uBAAkB,GAAG,EAAE,CAAC,UAAU;eAAC;QACrD,CAAC;KAAA,CAAC;IAEF,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE;QACnC,8BAAgB,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,yCAAyC;KAC7F;IAED,MAAM,QAAQ,GAAG,8BAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,yCAAyC;IAE3F,IAAI;QACF,8BAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,yCAAyC;KAC3F;IAAC,MAAM;QACN,kFAAkF;QAClF,yDAAyD;KAC1D;AACH,CAAC;AAED,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,MAAM,oBAAoB,GAAG,IAAA,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AAC,CAAC,CAAC;SAC1D;KACF,CAAC;IACF,MAAM,oCAAoB,CAAC,UAAU,CAAC,EAAE,GAAG,oBAAoB,EAAE,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAC3F,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;IAEpC,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC,CAAC;AApCW,QAAA,UAAU,cAoCrB;AAEF;;;;;;;GAOG;AACI,MAAM,SAAS,GAAG,KAAK,EAAE,WAAW,GAAG,yBAAS,EAAE,EAAE;IACzD,IAAI,CAAC,aAAa,EAAE;QAClB,OAAO;KACR;IAED,8CAA8C;IAC9C,IAAI,yBAA6C,CAAC;IAClD,MAAM,sBAAsB,GAAG,mCAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC;IACnF,IAAI,sBAAsB,EAAE,IAAI,KAAK,yCAAkB,CAAC,IAAI,EAAE;QAC5D,yBAAyB,GAAG,sBAAsB,EAAE,SAAS,CAAC;KAC/D;SAAM,IAAI,sBAAsB,EAAE,IAAI,KAAK,yCAAkB,CAAC,MAAM,EAAE;QACrE,yBAAyB,GAAG,sBAAsB,EAAE,IAAI,EAAE,SAAS,CAAC;KACrE;IAED,oBAAoB;IACpB,mCAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,yBAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB,EAAE;QAC7B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;KACxC;IAED,qBAAqB;IACrB,oCAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC;AA1BW,QAAA,SAAS,aA0BpB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Helpers\n */\n\n/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.\n\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid } from \"@itwin/core-bentley\";\nimport { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface } from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport {\n HierarchyCacheMode,\n Presentation as PresentationBackend,\n PresentationManagerProps as PresentationBackendProps,\n PresentationManagerMode,\n} from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\n\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\n const config = class extends RpcDefaultConfiguration {\n public override interfaces: any = () => interfaces;\n };\n\n for (const definition of interfaces) {\n RpcConfiguration.assign(definition, () => config); // eslint-disable-line @itwin/no-internal\n }\n\n const instance = RpcConfiguration.obtain(config); // eslint-disable-line @itwin/no-internal\n\n try {\n RpcConfiguration.initializeInterfaces(instance); // eslint-disable-line @itwin/no-internal\n } catch {\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\n // multiple different tests want to set up rpc interfaces\n }\n}\n\nlet isInitialized = false;\n\nconst defaultTestOutputDir = tmpdir();\nlet testOutputDir: string | undefined;\n\n/** @internal */\nexport const getTestOutputDir = (): string => {\n return testOutputDir ?? defaultTestOutputDir;\n};\n\n// eslint-disable-next-line deprecation/deprecation\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\n /** Properties for `IModelHost` */\n backendHostProps?: IModelHostOptions;\n /** Properties for frontend initialization */\n frontendProps?: PresentationFrontendProps;\n /** IModelApp implementation */\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\n /** `IModelApp` options */\n frontendAppOptions?: IModelAppOptions;\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\n testOutputDir?: string;\n}\n\n/**\n * Initialize the framework for presentation testing. The function sets up backend,\n * frontend and RPC communication between them.\n *\n * @see `terminate`\n *\n * @public\n */\nexport const initialize = async (props?: PresentationTestingInitProps) => {\n if (isInitialized) {\n return;\n }\n\n if (!props) {\n props = {};\n }\n\n // set up rpc interfaces\n initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init backend\n // make sure backend gets assigned an id which puts its resources into a unique directory\n props.backendProps = props.backendProps ?? {};\n // eslint-disable-next-line @itwin/no-internal\n if (!props.backendProps.id) {\n props.backendProps.id = `test-${Guid.createValue()}`; // eslint-disable-line @itwin/no-internal\n }\n await IModelHost.startup({ cacheDir: join(__dirname, \".cache\"), ...props.backendHostProps });\n PresentationBackend.initialize(props.backendProps);\n\n // init frontend\n if (!props.frontendApp) {\n props.frontendApp = NoRenderApp;\n }\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.getLanguageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\n testOutputDir = props.testOutputDir;\n\n isInitialized = true;\n};\n\n/**\n * Undoes the setup made by `initialize`.\n * @param frontendApp IModelApp implementation\n *\n * @see `initialize`\n *\n * @public\n */\nexport const terminate = async (frontendApp = IModelApp) => {\n if (!isInitialized) {\n return;\n }\n\n // store directory that needs to be cleaned-up\n let hierarchiesCacheDirectory: string | undefined;\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\n } else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\n }\n\n // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory) {\n rimraf.sync(hierarchiesCacheDirectory);\n }\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
1
+ {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,0BAA0B,CAAC,uGAAuG;AAElI,2BAA4B;AAC5B,+BAA4B;AAC5B,+CAAiC;AACjC,sDAAoE;AACpE,sDAA2C;AAC3C,oDAA2J;AAC3J,wDAAgF;AAChF,sEAKqC;AAkC5B,mGAtCP,yCAAkB,OAsCO;AAAE,wGAnC3B,8CAAuB,OAmC2B;AAjCpD,oEAAsE;AACtE,wEAAoI;AAEpI,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,MAAM,GAAG,KAAM,SAAQ,qCAAuB;QAArC;;YACG;;;;uBAAkB,GAAG,EAAE,CAAC,UAAU;eAAC;QACrD,CAAC;KAAA,CAAC;IAEF,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE;QACnC,8BAAgB,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,yCAAyC;KAC7F;IAED,MAAM,QAAQ,GAAG,8BAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,yCAAyC;IAE3F,IAAI;QACF,8BAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,yCAAyC;KAC3F;IAAC,MAAM;QACN,kFAAkF;QAClF,yDAAyD;KAC1D;AACH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------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Helpers\n */\n\n/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.\n\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid } from \"@itwin/core-bentley\";\nimport { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface } from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport {\n HierarchyCacheMode,\n Presentation as PresentationBackend,\n PresentationManagerProps as PresentationBackendProps,\n PresentationManagerMode,\n} from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\n\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\n const config = class extends RpcDefaultConfiguration {\n public override interfaces: any = () => interfaces;\n };\n\n for (const definition of interfaces) {\n RpcConfiguration.assign(definition, () => config); // eslint-disable-line @itwin/no-internal\n }\n\n const instance = RpcConfiguration.obtain(config); // eslint-disable-line @itwin/no-internal\n\n try {\n RpcConfiguration.initializeInterfaces(instance); // eslint-disable-line @itwin/no-internal\n } catch {\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\n // multiple different tests want to set up rpc interfaces\n }\n}\n\nlet isInitialized = false;\n\nconst defaultTestOutputDir = tmpdir();\nlet testOutputDir: string | undefined;\n\n/** @internal */\nexport const getTestOutputDir = (): string => {\n return testOutputDir ?? defaultTestOutputDir;\n};\n\n// eslint-disable-next-line deprecation/deprecation\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /**\n * RPC interfaces to enable. Defaults to `[SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]`.\n *\n * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.\n */\n rpcs?: RpcInterfaceDefinition[];\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\n /** Properties for `IModelHost` */\n backendHostProps?: IModelHostOptions;\n /** Properties for frontend initialization */\n frontendProps?: PresentationFrontendProps;\n /** IModelApp implementation */\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\n /** `IModelApp` options */\n frontendAppOptions?: IModelAppOptions;\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\n testOutputDir?: string;\n}\n\n/**\n * Initialize the framework for presentation testing. The function sets up backend,\n * frontend and RPC communication between them.\n *\n * @see `terminate`\n *\n * @public\n */\nexport const initialize = async (props?: PresentationTestingInitProps) => {\n if (isInitialized) {\n return;\n }\n\n if (!props) {\n props = {};\n }\n\n // set up rpc interfaces\n initializeRpcInterfaces(props.rpcs ?? [SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init backend\n // make sure backend gets assigned an id which puts its resources into a unique directory\n props.backendProps = props.backendProps ?? {};\n // eslint-disable-next-line @itwin/no-internal\n if (!props.backendProps.id) {\n props.backendProps.id = `test-${Guid.createValue()}`; // eslint-disable-line @itwin/no-internal\n }\n await IModelHost.startup({ cacheDir: join(__dirname, \".cache\"), ...props.backendHostProps });\n PresentationBackend.initialize(props.backendProps);\n\n // init frontend\n if (!props.frontendApp) {\n props.frontendApp = NoRenderApp;\n }\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.getLanguageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\n testOutputDir = props.testOutputDir;\n\n isInitialized = true;\n};\n\n/**\n * Undoes the setup made by `initialize`.\n * @param frontendApp IModelApp implementation\n *\n * @see `initialize`\n *\n * @public\n */\nexport const terminate = async (frontendApp = IModelApp) => {\n if (!isInitialized) {\n return;\n }\n\n // store directory that needs to be cleaned-up\n let hierarchiesCacheDirectory: string | undefined;\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\n } else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\n }\n\n // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory) {\n rimraf.sync(hierarchiesCacheDirectory);\n }\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
@@ -2,6 +2,7 @@
2
2
  * @module Helpers
3
3
  */
4
4
  import { IModelHostOptions } from "@itwin/core-backend";
5
+ import { RpcInterfaceDefinition } from "@itwin/core-common";
5
6
  import { IModelApp, IModelAppOptions } from "@itwin/core-frontend";
6
7
  import { HierarchyCacheMode, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from "@itwin/presentation-backend";
7
8
  import { PresentationProps as PresentationFrontendProps } from "@itwin/presentation-frontend";
@@ -10,6 +11,12 @@ export declare const getTestOutputDir: () => string;
10
11
  export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
11
12
  /** @public */
12
13
  export interface PresentationTestingInitProps {
14
+ /**
15
+ * RPC interfaces to enable. Defaults to `[SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]`.
16
+ *
17
+ * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.
18
+ */
19
+ rpcs?: RpcInterfaceDefinition[];
13
20
  /** Properties for backend initialization */
14
21
  backendProps?: PresentationBackendProps;
15
22
  /** Properties for `IModelHost` */
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAOH,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAElB,wBAAwB,IAAI,wBAAwB,EACpD,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AA0BpI,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,QAAO,MAEnC,CAAC;AAGF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,CAAC;AAEjF,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,6CAA6C;IAC7C,aAAa,CAAC,EAAE,yBAAyB,CAAC;IAC1C,+BAA+B;IAC/B,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IACtE,0BAA0B;IAC1B,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IACtC,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,WAAkB,4BAA4B,kBAoCpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDA0BrB,CAAC"}
1
+ {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAOH,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAqE,sBAAsB,EAA8B,MAAM,oBAAoB,CAAC;AAC3J,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAElB,wBAAwB,IAAI,wBAAwB,EACpD,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AA0BpI,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,QAAO,MAEnC,CAAC;AAGF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,CAAC;AAEjF,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,IAAI,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAChC,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,6CAA6C;IAC7C,aAAa,CAAC,EAAE,yBAAyB,CAAC;IAC1C,+BAA+B;IAC/B,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IACtE,0BAA0B;IAC1B,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IACtC,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,WAAkB,4BAA4B,kBAoCpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDA0BrB,CAAC"}
@@ -65,7 +65,7 @@ export const initialize = async (props) => {
65
65
  props = {};
66
66
  }
67
67
  // set up rpc interfaces
68
- initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);
68
+ initializeRpcInterfaces(props.rpcs ?? [SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);
69
69
  // init backend
70
70
  // make sure backend gets assigned an id which puts its resources into a unique directory
71
71
  props.backendProps = props.backendProps ?? {};
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,0BAA0B,CAAC,uGAAuG;AAElI,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAA0B,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAC3J,OAAO,EAAE,SAAS,EAAoB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,YAAY,IAAI,mBAAmB,EAEnC,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,YAAY,IAAI,oBAAoB,EAAkD,MAAM,8BAA8B,CAAC;AAEpI,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,MAAM,GAAG,KAAM,SAAQ,uBAAuB;QAArC;;YACG;;;;uBAAkB,GAAG,EAAE,CAAC,UAAU;eAAC;QACrD,CAAC;KAAA,CAAC;IAEF,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE;QACnC,gBAAgB,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAA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EAAE;QAC7B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;KACxC;IAED,qBAAqB;IACrB,oBAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Helpers\n */\n\n/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.\n\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid } from \"@itwin/core-bentley\";\nimport { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface } from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport {\n HierarchyCacheMode,\n Presentation as PresentationBackend,\n PresentationManagerProps as PresentationBackendProps,\n PresentationManagerMode,\n} from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\n\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\n const config = class extends RpcDefaultConfiguration {\n public override interfaces: any = () => interfaces;\n };\n\n for (const definition of interfaces) {\n RpcConfiguration.assign(definition, () => config); // eslint-disable-line @itwin/no-internal\n }\n\n const instance = RpcConfiguration.obtain(config); // eslint-disable-line @itwin/no-internal\n\n try {\n RpcConfiguration.initializeInterfaces(instance); // eslint-disable-line @itwin/no-internal\n } catch {\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\n // multiple different tests want to set up rpc interfaces\n }\n}\n\nlet isInitialized = false;\n\nconst defaultTestOutputDir = tmpdir();\nlet testOutputDir: string | undefined;\n\n/** @internal */\nexport const getTestOutputDir = (): string => {\n return testOutputDir ?? defaultTestOutputDir;\n};\n\n// eslint-disable-next-line deprecation/deprecation\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\n /** Properties for `IModelHost` */\n backendHostProps?: IModelHostOptions;\n /** Properties for frontend initialization */\n frontendProps?: PresentationFrontendProps;\n /** IModelApp implementation */\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\n /** `IModelApp` options */\n frontendAppOptions?: IModelAppOptions;\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\n testOutputDir?: string;\n}\n\n/**\n * Initialize the framework for presentation testing. The function sets up backend,\n * frontend and RPC communication between them.\n *\n * @see `terminate`\n *\n * @public\n */\nexport const initialize = async (props?: PresentationTestingInitProps) => {\n if (isInitialized) {\n return;\n }\n\n if (!props) {\n props = {};\n }\n\n // set up rpc interfaces\n initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init backend\n // make sure backend gets assigned an id which puts its resources into a unique directory\n props.backendProps = props.backendProps ?? {};\n // eslint-disable-next-line @itwin/no-internal\n if (!props.backendProps.id) {\n props.backendProps.id = `test-${Guid.createValue()}`; // eslint-disable-line @itwin/no-internal\n }\n await IModelHost.startup({ cacheDir: join(__dirname, \".cache\"), ...props.backendHostProps });\n PresentationBackend.initialize(props.backendProps);\n\n // init frontend\n if (!props.frontendApp) {\n props.frontendApp = NoRenderApp;\n }\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.getLanguageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\n testOutputDir = props.testOutputDir;\n\n isInitialized = true;\n};\n\n/**\n * Undoes the setup made by `initialize`.\n * @param frontendApp IModelApp implementation\n *\n * @see `initialize`\n *\n * @public\n */\nexport const terminate = async (frontendApp = IModelApp) => {\n if (!isInitialized) {\n return;\n }\n\n // store directory that needs to be cleaned-up\n let hierarchiesCacheDirectory: string | undefined;\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\n } else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\n }\n\n // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory) {\n rimraf.sync(hierarchiesCacheDirectory);\n }\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
1
+ {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,0BAA0B,CAAC,uGAAuG;AAElI,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAA0B,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAC3J,OAAO,EAAE,SAAS,EAAoB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,YAAY,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8CAA8C;IAC9C,IAAI,yBAA6C,CAAC;IAClD,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC;IACnF,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,IAAI,EAAE;QAC5D,yBAAyB,GAAG,sBAAsB,EAAE,SAAS,CAAC;KAC/D;SAAM,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,MAAM,EAAE;QACrE,yBAAyB,GAAG,sBAAsB,EAAE,IAAI,EAAE,SAAS,CAAC;KACrE;IAED,oBAAoB;IACpB,mBAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB,EAAE;QAC7B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;KACxC;IAED,qBAAqB;IACrB,oBAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Helpers\n */\n\n/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.\n\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid } from \"@itwin/core-bentley\";\nimport { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface } from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport {\n HierarchyCacheMode,\n Presentation as PresentationBackend,\n PresentationManagerProps as PresentationBackendProps,\n PresentationManagerMode,\n} from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\n\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\n const config = class extends RpcDefaultConfiguration {\n public override interfaces: any = () => interfaces;\n };\n\n for (const definition of interfaces) {\n RpcConfiguration.assign(definition, () => config); // eslint-disable-line @itwin/no-internal\n }\n\n const instance = RpcConfiguration.obtain(config); // eslint-disable-line @itwin/no-internal\n\n try {\n RpcConfiguration.initializeInterfaces(instance); // eslint-disable-line @itwin/no-internal\n } catch {\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\n // multiple different tests want to set up rpc interfaces\n }\n}\n\nlet isInitialized = false;\n\nconst defaultTestOutputDir = tmpdir();\nlet testOutputDir: string | undefined;\n\n/** @internal */\nexport const getTestOutputDir = (): string => {\n return testOutputDir ?? defaultTestOutputDir;\n};\n\n// eslint-disable-next-line deprecation/deprecation\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /**\n * RPC interfaces to enable. Defaults to `[SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]`.\n *\n * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.\n */\n rpcs?: RpcInterfaceDefinition[];\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\n /** Properties for `IModelHost` */\n backendHostProps?: IModelHostOptions;\n /** Properties for frontend initialization */\n frontendProps?: PresentationFrontendProps;\n /** IModelApp implementation */\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\n /** `IModelApp` options */\n frontendAppOptions?: IModelAppOptions;\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\n testOutputDir?: string;\n}\n\n/**\n * Initialize the framework for presentation testing. The function sets up backend,\n * frontend and RPC communication between them.\n *\n * @see `terminate`\n *\n * @public\n */\nexport const initialize = async (props?: PresentationTestingInitProps) => {\n if (isInitialized) {\n return;\n }\n\n if (!props) {\n props = {};\n }\n\n // set up rpc interfaces\n initializeRpcInterfaces(props.rpcs ?? [SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init backend\n // make sure backend gets assigned an id which puts its resources into a unique directory\n props.backendProps = props.backendProps ?? {};\n // eslint-disable-next-line @itwin/no-internal\n if (!props.backendProps.id) {\n props.backendProps.id = `test-${Guid.createValue()}`; // eslint-disable-line @itwin/no-internal\n }\n await IModelHost.startup({ cacheDir: join(__dirname, \".cache\"), ...props.backendHostProps });\n PresentationBackend.initialize(props.backendProps);\n\n // init frontend\n if (!props.frontendApp) {\n props.frontendApp = NoRenderApp;\n }\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.getLanguageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\n testOutputDir = props.testOutputDir;\n\n isInitialized = true;\n};\n\n/**\n * Undoes the setup made by `initialize`.\n * @param frontendApp IModelApp implementation\n *\n * @see `initialize`\n *\n * @public\n */\nexport const terminate = async (frontendApp = IModelApp) => {\n if (!isInitialized) {\n return;\n }\n\n // store directory that needs to be cleaned-up\n let hierarchiesCacheDirectory: string | undefined;\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\n } else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\n }\n\n // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory) {\n rimraf.sync(hierarchiesCacheDirectory);\n }\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/presentation-testing",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Testing utilities for iTwin.js Presentation library",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -36,7 +36,7 @@
36
36
  "extract-api": "betools extract-api --entry=presentation-testing --apiReportFolder=./api --apiReportTempFolder=./api/temp --apiSummaryFolder=./api"
37
37
  },
38
38
  "dependencies": {
39
- "rimraf": "^5.0.0",
39
+ "rimraf": "^5.0.1",
40
40
  "sanitize-filename": "^1.6.3"
41
41
  },
42
42
  "peerDependencies": {
@@ -48,28 +48,28 @@
48
48
  "@itwin/core-frontend": "^3.6.3 || ^4.0.0",
49
49
  "@itwin/presentation-backend": "^3.6.3 || ^4.0.0",
50
50
  "@itwin/presentation-common": "^3.6.3 || ^4.0.0",
51
- "@itwin/presentation-components": "^4.0.1",
51
+ "@itwin/presentation-components": "^4.1.0",
52
52
  "@itwin/presentation-frontend": "^3.6.3 || ^4.0.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@itwin/appui-abstract": "^4.1.0-dev.35",
56
- "@itwin/build-tools": "^4.1.0-dev.35",
57
- "@itwin/components-react": "^4.1.0",
58
- "@itwin/core-backend": "^4.1.0-dev.35",
59
- "@itwin/core-bentley": "^4.1.0-dev.35",
60
- "@itwin/core-common": "^4.1.0-dev.35",
61
- "@itwin/core-frontend": "^4.1.0-dev.35",
62
- "@itwin/core-geometry": "^4.1.0-dev.35",
63
- "@itwin/core-orbitgt": "^4.1.0-dev.35",
64
- "@itwin/core-quantity": "^4.1.0-dev.35",
65
- "@itwin/core-react": "^4.1.0",
66
- "@itwin/ecschema-metadata": "^4.1.0-dev.35",
67
- "@itwin/eslint-plugin": "4.0.0-dev.38",
68
- "@itwin/presentation-backend": "^4.1.0-dev.35",
69
- "@itwin/presentation-common": "^4.1.0-dev.35",
70
- "@itwin/presentation-components": "^4.0.1",
71
- "@itwin/presentation-frontend": "^4.1.0-dev.35",
72
- "@itwin/webgl-compatibility": "^4.1.0-dev.35",
55
+ "@itwin/appui-abstract": "4.1.0-dev.71",
56
+ "@itwin/build-tools": "4.1.0-dev.71",
57
+ "@itwin/components-react": "^4.3.0",
58
+ "@itwin/core-backend": "4.1.0-dev.71",
59
+ "@itwin/core-bentley": "4.1.0-dev.71",
60
+ "@itwin/core-common": "4.1.0-dev.71",
61
+ "@itwin/core-frontend": "4.1.0-dev.71",
62
+ "@itwin/core-geometry": "4.1.0-dev.71",
63
+ "@itwin/core-orbitgt": "4.1.0-dev.71",
64
+ "@itwin/core-quantity": "4.1.0-dev.71",
65
+ "@itwin/core-react": "^4.3.0",
66
+ "@itwin/ecschema-metadata": "4.1.0-dev.71",
67
+ "@itwin/eslint-plugin": "^4.0.0-dev.48",
68
+ "@itwin/presentation-backend": "4.1.0-dev.71",
69
+ "@itwin/presentation-common": "4.1.0-dev.71",
70
+ "@itwin/presentation-components": "^4.1.0",
71
+ "@itwin/presentation-frontend": "4.1.0-dev.71",
72
+ "@itwin/webgl-compatibility": "4.1.0-dev.71",
73
73
  "@opentelemetry/api": "^1.4.1",
74
74
  "@types/chai": "4.3.1",
75
75
  "@types/chai-as-promised": "^7.1.5",
@@ -81,7 +81,7 @@
81
81
  "chai-as-promised": "^7.1.1",
82
82
  "chai-jest-snapshot": "^2.0.0",
83
83
  "cpx2": "^3.0.2",
84
- "eslint": "^8.42.0",
84
+ "eslint": "^8.45.0",
85
85
  "ignore-styles": "^5.0.1",
86
86
  "jsdom": "^22.1.0",
87
87
  "jsdom-global": "3.0.2",
@@ -89,7 +89,7 @@
89
89
  "nyc": "^15.1.0",
90
90
  "react": "^17.0.0",
91
91
  "react-dom": "^17.0.0",
92
- "sinon": "^15.1.2",
92
+ "sinon": "^15.2.0",
93
93
  "sinon-chai": "^3.7.0",
94
94
  "typemoq": "^2.1.0",
95
95
  "typescript": "~5.0.4"