@itwin/presentation-testing 3.5.0-dev.8 → 3.5.1
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 +70 -1
- package/lib/cjs/presentation-testing/Helpers.d.ts +4 -0
- package/lib/cjs/presentation-testing/Helpers.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/Helpers.js +11 -1
- package/lib/cjs/presentation-testing/Helpers.js.map +1 -1
- package/lib/cjs/presentation-testing/IModelUtilities.d.ts +47 -0
- package/lib/cjs/presentation-testing/IModelUtilities.d.ts.map +1 -0
- package/lib/cjs/presentation-testing/IModelUtilities.js +78 -0
- package/lib/cjs/presentation-testing/IModelUtilities.js.map +1 -0
- package/lib/cjs/presentation-testing.d.ts +4 -4
- package/lib/cjs/presentation-testing.d.ts.map +1 -1
- package/lib/cjs/presentation-testing.js +4 -4
- package/lib/cjs/presentation-testing.js.map +1 -1
- package/lib/esm/presentation-testing/Helpers.d.ts +4 -0
- package/lib/esm/presentation-testing/Helpers.d.ts.map +1 -1
- package/lib/esm/presentation-testing/Helpers.js +10 -0
- package/lib/esm/presentation-testing/Helpers.js.map +1 -1
- package/lib/esm/presentation-testing/IModelUtilities.d.ts +47 -0
- package/lib/esm/presentation-testing/IModelUtilities.d.ts.map +1 -0
- package/lib/esm/presentation-testing/IModelUtilities.js +70 -0
- package/lib/esm/presentation-testing/IModelUtilities.js.map +1 -0
- package/lib/esm/presentation-testing.d.ts +4 -4
- package/lib/esm/presentation-testing.d.ts.map +1 -1
- package/lib/esm/presentation-testing.js +4 -4
- package/lib/esm/presentation-testing.js.map +1 -1
- package/package.json +13 -13
- package/lib/cjs/presentation-testing/IModelBuilder.d.ts +0 -46
- package/lib/cjs/presentation-testing/IModelBuilder.d.ts.map +0 -1
- package/lib/cjs/presentation-testing/IModelBuilder.js +0 -171
- package/lib/cjs/presentation-testing/IModelBuilder.js.map +0 -1
- package/lib/cjs/presentation-testing/IModelTestUtility.d.ts +0 -25
- package/lib/cjs/presentation-testing/IModelTestUtility.d.ts.map +0 -1
- package/lib/cjs/presentation-testing/IModelTestUtility.js +0 -63
- package/lib/cjs/presentation-testing/IModelTestUtility.js.map +0 -1
- package/lib/esm/presentation-testing/IModelBuilder.d.ts +0 -46
- package/lib/esm/presentation-testing/IModelBuilder.d.ts.map +0 -1
- package/lib/esm/presentation-testing/IModelBuilder.js +0 -147
- package/lib/esm/presentation-testing/IModelBuilder.js.map +0 -1
- package/lib/esm/presentation-testing/IModelTestUtility.d.ts +0 -25
- package/lib/esm/presentation-testing/IModelTestUtility.d.ts.map +0 -1
- package/lib/esm/presentation-testing/IModelTestUtility.js +0 -59
- package/lib/esm/presentation-testing/IModelTestUtility.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
1
|
# Change Log - @itwin/presentation-testing
|
|
2
2
|
|
|
3
|
-
This log was last generated on Thu,
|
|
3
|
+
This log was last generated on Thu, 15 Dec 2022 16:38:29 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 3.5.1
|
|
6
|
+
Thu, 15 Dec 2022 16:38:29 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 3.5.0
|
|
11
|
+
Wed, 07 Dec 2022 19:12:37 GMT
|
|
12
|
+
|
|
13
|
+
### Updates
|
|
14
|
+
|
|
15
|
+
- Create iModelBuilder for testing
|
|
16
|
+
|
|
17
|
+
## 3.4.7
|
|
18
|
+
Wed, 30 Nov 2022 14:28:19 GMT
|
|
19
|
+
|
|
20
|
+
_Version update only_
|
|
21
|
+
|
|
22
|
+
## 3.4.6
|
|
23
|
+
Tue, 22 Nov 2022 14:24:19 GMT
|
|
24
|
+
|
|
25
|
+
_Version update only_
|
|
26
|
+
|
|
27
|
+
## 3.4.5
|
|
28
|
+
Thu, 17 Nov 2022 21:32:50 GMT
|
|
29
|
+
|
|
30
|
+
_Version update only_
|
|
31
|
+
|
|
32
|
+
## 3.4.4
|
|
33
|
+
Thu, 10 Nov 2022 19:32:17 GMT
|
|
34
|
+
|
|
35
|
+
_Version update only_
|
|
36
|
+
|
|
37
|
+
## 3.4.3
|
|
38
|
+
Fri, 28 Oct 2022 13:34:58 GMT
|
|
39
|
+
|
|
40
|
+
_Version update only_
|
|
41
|
+
|
|
42
|
+
## 3.4.2
|
|
43
|
+
Mon, 24 Oct 2022 13:23:45 GMT
|
|
44
|
+
|
|
45
|
+
_Version update only_
|
|
46
|
+
|
|
47
|
+
## 3.4.1
|
|
48
|
+
Mon, 17 Oct 2022 20:06:51 GMT
|
|
49
|
+
|
|
50
|
+
_Version update only_
|
|
51
|
+
|
|
52
|
+
## 3.4.0
|
|
53
|
+
Thu, 13 Oct 2022 20:24:47 GMT
|
|
54
|
+
|
|
55
|
+
### Updates
|
|
56
|
+
|
|
57
|
+
- Allow supplying `IModelHostOptions` when initializing tests
|
|
58
|
+
|
|
59
|
+
## 3.3.5
|
|
60
|
+
Tue, 27 Sep 2022 11:50:59 GMT
|
|
61
|
+
|
|
62
|
+
_Version update only_
|
|
63
|
+
|
|
64
|
+
## 3.3.4
|
|
65
|
+
Thu, 08 Sep 2022 19:00:05 GMT
|
|
66
|
+
|
|
67
|
+
_Version update only_
|
|
68
|
+
|
|
69
|
+
## 3.3.3
|
|
70
|
+
Tue, 06 Sep 2022 20:54:19 GMT
|
|
71
|
+
|
|
72
|
+
_Version update only_
|
|
4
73
|
|
|
5
74
|
## 3.3.2
|
|
6
75
|
Thu, 01 Sep 2022 14:37:23 GMT
|
|
@@ -2,6 +2,8 @@ import { IModelHostOptions } from "@itwin/core-backend";
|
|
|
2
2
|
import { IModelApp, IModelAppOptions } from "@itwin/core-frontend";
|
|
3
3
|
import { HierarchyCacheMode, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from "@itwin/presentation-backend";
|
|
4
4
|
import { PresentationProps as PresentationFrontendProps } from "@itwin/presentation-frontend";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare const getTestOutputDir: () => string;
|
|
5
7
|
export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
|
|
6
8
|
/** @public */
|
|
7
9
|
export interface PresentationTestingInitProps {
|
|
@@ -17,6 +19,8 @@ export interface PresentationTestingInitProps {
|
|
|
17
19
|
};
|
|
18
20
|
/** `IModelApp` options */
|
|
19
21
|
frontendAppOptions?: IModelAppOptions;
|
|
22
|
+
/** Custom test output directory. Defaults to temporary directory provided by the OS. */
|
|
23
|
+
testOutputDir?: string;
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* Initialize the framework for presentation testing. The function sets up backend,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAUA,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKpE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAAuC,wBAAwB,IAAI,wBAAwB,EAAE,uBAAuB,EACvI,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,qEA+BtB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDAuBrB,CAAC"}
|
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.terminate = exports.initialize = exports.PresentationManagerMode = exports.HierarchyCacheMode = void 0;
|
|
22
|
+
exports.terminate = exports.initialize = exports.PresentationManagerMode = exports.HierarchyCacheMode = exports.getTestOutputDir = void 0;
|
|
23
23
|
/*---------------------------------------------------------------------------------------------
|
|
24
24
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
25
25
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
@@ -27,6 +27,7 @@ exports.terminate = exports.initialize = exports.PresentationManagerMode = expor
|
|
|
27
27
|
/** @packageDocumentation
|
|
28
28
|
* @module Helpers
|
|
29
29
|
*/
|
|
30
|
+
/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.
|
|
30
31
|
const path_1 = require("path");
|
|
31
32
|
const rimraf = __importStar(require("rimraf"));
|
|
32
33
|
const core_backend_1 = require("@itwin/core-backend");
|
|
@@ -38,6 +39,7 @@ Object.defineProperty(exports, "HierarchyCacheMode", { enumerable: true, get: fu
|
|
|
38
39
|
Object.defineProperty(exports, "PresentationManagerMode", { enumerable: true, get: function () { return presentation_backend_1.PresentationManagerMode; } });
|
|
39
40
|
const presentation_common_1 = require("@itwin/presentation-common");
|
|
40
41
|
const presentation_frontend_1 = require("@itwin/presentation-frontend");
|
|
42
|
+
const os_1 = require("os");
|
|
41
43
|
function initializeRpcInterfaces(interfaces) {
|
|
42
44
|
const config = class extends core_common_1.RpcDefaultConfiguration {
|
|
43
45
|
constructor() {
|
|
@@ -57,6 +59,13 @@ function initializeRpcInterfaces(interfaces) {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
let isInitialized = false;
|
|
62
|
+
const defaultTestOutputDir = (0, os_1.tmpdir)();
|
|
63
|
+
let testOutputDir;
|
|
64
|
+
/** @internal */
|
|
65
|
+
const getTestOutputDir = () => {
|
|
66
|
+
return testOutputDir !== null && testOutputDir !== void 0 ? testOutputDir : defaultTestOutputDir;
|
|
67
|
+
};
|
|
68
|
+
exports.getTestOutputDir = getTestOutputDir;
|
|
60
69
|
/**
|
|
61
70
|
* Initialize the framework for presentation testing. The function sets up backend,
|
|
62
71
|
* frontend and RPC communication between them.
|
|
@@ -90,6 +99,7 @@ const initialize = async (props) => {
|
|
|
90
99
|
},
|
|
91
100
|
};
|
|
92
101
|
await presentation_frontend_1.Presentation.initialize({ ...defaultFrontendProps, ...props.frontendProps });
|
|
102
|
+
testOutputDir = props.testOutputDir;
|
|
93
103
|
isInitialized = true;
|
|
94
104
|
};
|
|
95
105
|
exports.initialize = initialize;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,+BAA4B;AAC5B,+CAAiC;AACjC,sDAAoE;AACpE,sDAA2C;AAC3C,oDAE4B;AAC5B,wDAAgF;AAChF,sEAEqC;
|
|
1
|
+
{"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;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AG,MAAA,MAAA,mCAAmB,CAAC,SAAS,0CAAE,OAAO,0CAAE,WAAW,CAAC;IACnF,IAAI,CAAA,sBAAsB,aAAtB,sBAAsB,uBAAtB,sBAAsB,CAAE,IAAI,MAAK,yCAAkB,CAAC,IAAI;QAC1D,yBAAyB,GAAG,sBAAsB,aAAtB,sBAAsB,uBAAtB,sBAAsB,CAAE,SAAS,CAAC;SAC3D,IAAI,CAAA,sBAAsB,aAAtB,sBAAsB,uBAAtB,sBAAsB,CAAE,IAAI,MAAK,yCAAkB,CAAC,MAAM;QACjE,yBAAyB,GAAG,MAAA,sBAAsB,aAAtB,sBAAsB,uBAAtB,sBAAsB,CAAE,IAAI,0CAAE,SAAS,CAAC;IAEtE,oBAAoB;IACpB,mCAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,yBAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB;QAC3B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IAEzC,qBAAqB;IACrB,oCAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC;AAvBW,QAAA,SAAS,aAuBpB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Helpers\r\n */\r\n/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.\r\nimport { join } from \"path\";\r\nimport * as rimraf from \"rimraf\";\r\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\r\nimport { Guid } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface,\r\n} from \"@itwin/core-common\";\r\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\r\nimport {\r\n HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode,\r\n} from \"@itwin/presentation-backend\";\r\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\r\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\r\nimport { tmpdir } from \"os\";\r\n\r\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\r\n const config = class extends RpcDefaultConfiguration {\r\n public override interfaces: any = () => interfaces;\r\n };\r\n\r\n for (const definition of interfaces)\r\n RpcConfiguration.assign(definition, () => config);\r\n\r\n const instance = RpcConfiguration.obtain(config);\r\n\r\n try {\r\n RpcConfiguration.initializeInterfaces(instance);\r\n } catch {\r\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\r\n // multiple different tests want to set up rpc interfaces\r\n }\r\n}\r\n\r\nlet isInitialized = false;\r\n\r\nconst defaultTestOutputDir = tmpdir();\r\nlet testOutputDir: string | undefined;\r\n\r\n/** @internal */\r\nexport const getTestOutputDir = (): string => {\r\n return testOutputDir ?? defaultTestOutputDir;\r\n};\r\n\r\n// eslint-disable-next-line deprecation/deprecation\r\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\r\n\r\n/** @public */\r\nexport interface PresentationTestingInitProps {\r\n /** Properties for backend initialization */\r\n backendProps?: PresentationBackendProps;\r\n /** Properties for `IModelHost` */\r\n backendHostProps?: IModelHostOptions;\r\n /** Properties for frontend initialization */\r\n frontendProps?: PresentationFrontendProps;\r\n /** IModelApp implementation */\r\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\r\n /** `IModelApp` options */\r\n frontendAppOptions?: IModelAppOptions;\r\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\r\n testOutputDir?: string;\r\n}\r\n\r\n/**\r\n * Initialize the framework for presentation testing. The function sets up backend,\r\n * frontend and RPC communication between them.\r\n *\r\n * @see `terminate`\r\n *\r\n * @public\r\n */\r\nexport const initialize = async (props?: PresentationTestingInitProps) => {\r\n if (isInitialized)\r\n return;\r\n\r\n if (!props)\r\n props = {};\r\n\r\n // set up rpc interfaces\r\n initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\r\n\r\n // init backend\r\n // make sure backend gets assigned an id which puts its resources into a unique directory\r\n props.backendProps = props.backendProps ?? {};\r\n if (!props.backendProps.id)\r\n props.backendProps.id = `test-${Guid.createValue()}`;\r\n await IModelHost.startup({ cacheDir: join(__dirname, \".cache\"), ...props.backendHostProps });\r\n PresentationBackend.initialize(props.backendProps);\r\n\r\n // init frontend\r\n if (!props.frontendApp)\r\n props.frontendApp = NoRenderApp;\r\n await props.frontendApp.startup(props.frontendAppOptions);\r\n const defaultFrontendProps: PresentationFrontendProps = {\r\n presentation: {\r\n activeLocale: IModelApp.localization.getLanguageList()[0],\r\n },\r\n };\r\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\r\n testOutputDir = props.testOutputDir;\r\n\r\n isInitialized = true;\r\n};\r\n\r\n/**\r\n * Undoes the setup made by `initialize`.\r\n * @param frontendApp IModelApp implementation\r\n *\r\n * @see `initialize`\r\n *\r\n * @public\r\n */\r\nexport const terminate = async (frontendApp = IModelApp) => {\r\n if (!isInitialized)\r\n return;\r\n\r\n // store directory that needs to be cleaned-up\r\n let hierarchiesCacheDirectory: string | undefined;\r\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\r\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk)\r\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\r\n else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid)\r\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\r\n\r\n // terminate backend\r\n PresentationBackend.terminate();\r\n await IModelHost.shutdown();\r\n if (hierarchiesCacheDirectory)\r\n rimraf.sync(hierarchiesCacheDirectory);\r\n\r\n // terminate frontend\r\n PresentationFrontend.terminate();\r\n await frontendApp.shutdown();\r\n\r\n isInitialized = false;\r\n};\r\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module IModel
|
|
3
|
+
*/
|
|
4
|
+
import { IModelDb } from "@itwin/core-backend";
|
|
5
|
+
import { Id64String } from "@itwin/core-bentley";
|
|
6
|
+
import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps } from "@itwin/core-common";
|
|
7
|
+
import { IModelConnection } from "@itwin/core-frontend";
|
|
8
|
+
/**
|
|
9
|
+
* Interface for IModel builder pattern. Used for building IModels to test rulesets.
|
|
10
|
+
*
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export interface TestIModelBuilder {
|
|
14
|
+
/** Insert a model into the builder's iModel */
|
|
15
|
+
insertModel<TProps extends ModelProps>(props: TProps): Id64String;
|
|
16
|
+
/** Insert an element into the builder's iModel */
|
|
17
|
+
insertElement<TProps extends ElementProps>(props: TProps): Id64String;
|
|
18
|
+
/** Insert an element aspect into the specified element */
|
|
19
|
+
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
20
|
+
/**
|
|
21
|
+
* Create code for specified element.
|
|
22
|
+
* Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).
|
|
23
|
+
*/
|
|
24
|
+
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Function that creates an iModel and returns a connection to it.
|
|
28
|
+
* @param name Name of test IModel
|
|
29
|
+
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
30
|
+
*
|
|
31
|
+
* @beta
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;
|
|
34
|
+
/**
|
|
35
|
+
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export declare class IModelBuilder implements TestIModelBuilder {
|
|
40
|
+
private _iModel;
|
|
41
|
+
constructor(iModel: IModelDb);
|
|
42
|
+
insertModel<TProps extends ModelProps>(props: TProps): Id64String;
|
|
43
|
+
insertElement<TProps extends ElementProps>(props: TProps): Id64String;
|
|
44
|
+
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
45
|
+
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=IModelUtilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAA0B,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAY,kBAAkB,EAAE,YAAY,EAAiB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9I,OAAO,EAAE,gBAAgB,EAAsB,MAAM,sBAAsB,CAAC;AAI5E;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,+CAA+C;IAC/C,WAAW,CAAC,MAAM,SAAS,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IAClE,kDAAkD;IAClD,aAAa,CAAC,MAAM,SAAS,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IACtE,0DAA0D;IAC1D,YAAY,CAAC,MAAM,SAAS,kBAAkB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrE;;;OAGG;IACH,UAAU,CAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9F;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAWvH;AAED;;;;GAIG;AACH,qBAAa,aAAc,YAAW,iBAAiB;IACrD,OAAO,CAAC,OAAO,CAAW;gBAEd,MAAM,EAAE,QAAQ;IAIrB,WAAW,CAAC,MAAM,SAAS,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU;IAIjE,aAAa,CAAC,MAAM,SAAS,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU;IAIrE,YAAY,CAAC,MAAM,SAAS,kBAAkB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIpE,UAAU,CAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;CAIpG"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module IModel
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.IModelBuilder = exports.buildTestIModel = void 0;
|
|
14
|
+
const core_backend_1 = require("@itwin/core-backend");
|
|
15
|
+
const core_common_1 = require("@itwin/core-common");
|
|
16
|
+
const core_frontend_1 = require("@itwin/core-frontend");
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const Helpers_1 = require("./Helpers");
|
|
19
|
+
/**
|
|
20
|
+
* Function that creates an iModel and returns a connection to it.
|
|
21
|
+
* @param name Name of test IModel
|
|
22
|
+
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
23
|
+
*
|
|
24
|
+
* @beta
|
|
25
|
+
*/
|
|
26
|
+
async function buildTestIModel(name, cb) {
|
|
27
|
+
const outputFile = setupOutputFileLocation(name);
|
|
28
|
+
const db = core_backend_1.SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });
|
|
29
|
+
const builder = new IModelBuilder(db);
|
|
30
|
+
try {
|
|
31
|
+
cb(builder);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
db.saveChanges("Created test IModel");
|
|
35
|
+
db.close();
|
|
36
|
+
}
|
|
37
|
+
return core_frontend_1.SnapshotConnection.openFile(outputFile);
|
|
38
|
+
}
|
|
39
|
+
exports.buildTestIModel = buildTestIModel;
|
|
40
|
+
/**
|
|
41
|
+
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
class IModelBuilder {
|
|
46
|
+
constructor(iModel) {
|
|
47
|
+
this._iModel = iModel;
|
|
48
|
+
}
|
|
49
|
+
insertModel(props) {
|
|
50
|
+
return this._iModel.models.insertModel(props);
|
|
51
|
+
}
|
|
52
|
+
insertElement(props) {
|
|
53
|
+
return this._iModel.elements.insertElement(props);
|
|
54
|
+
}
|
|
55
|
+
insertAspect(props) {
|
|
56
|
+
this._iModel.elements.insertAspect(props);
|
|
57
|
+
}
|
|
58
|
+
createCode(scopeModelId, codeSpecName, codeValue) {
|
|
59
|
+
const codeSpec = this._iModel.codeSpecs.getByName(codeSpecName);
|
|
60
|
+
return new core_common_1.Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.IModelBuilder = IModelBuilder;
|
|
64
|
+
/**
|
|
65
|
+
* Prepare for an output file by:
|
|
66
|
+
* - Resolving the output file name under the known test output directory
|
|
67
|
+
* - Making directories as necessary
|
|
68
|
+
* - Removing a previous copy of the output file
|
|
69
|
+
* @param fileName Name of output file
|
|
70
|
+
*/
|
|
71
|
+
function setupOutputFileLocation(fileName) {
|
|
72
|
+
const testOutputDir = (0, Helpers_1.getTestOutputDir)();
|
|
73
|
+
!core_backend_1.IModelJsFs.existsSync(testOutputDir) && core_backend_1.IModelJsFs.mkdirSync(testOutputDir);
|
|
74
|
+
const outputFile = path_1.default.join(testOutputDir, `${fileName}.bim`);
|
|
75
|
+
core_backend_1.IModelJsFs.existsSync(outputFile) && core_backend_1.IModelJsFs.unlinkSync(outputFile);
|
|
76
|
+
return outputFile;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=IModelUtilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;AAEH,sDAAuE;AAEvE,oDAA8I;AAC9I,wDAA4E;AAC5E,gDAAwB;AACxB,uCAA6C;AAqB7C;;;;;;GAMG;AACI,KAAK,UAAU,eAAe,CAAC,IAAY,EAAE,EAAwC;IAC1F,MAAM,UAAU,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IACjD,MAAM,EAAE,GAAG,yBAAU,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC,CAAC;IACtC,IAAI;QACF,EAAE,C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,GAAG,QAAQ,MAAM,CAAC,CAAC;IAC/D,yBAAU,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,yBAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACvE,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module IModel\r\n */\r\n\r\nimport { IModelDb, IModelJsFs, SnapshotDb } from \"@itwin/core-backend\";\r\nimport { Id64String } from \"@itwin/core-bentley\";\r\nimport { BisCodeSpec, Code, CodeScopeProps, CodeSpec, ElementAspectProps, ElementProps, LocalFileName, ModelProps } from \"@itwin/core-common\";\r\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\r\nimport path from \"path\";\r\nimport { getTestOutputDir } from \"./Helpers\";\r\n\r\n/**\r\n * Interface for IModel builder pattern. Used for building IModels to test rulesets.\r\n *\r\n * @beta\r\n */\r\nexport interface TestIModelBuilder {\r\n /** Insert a model into the builder's iModel */\r\n insertModel<TProps extends ModelProps>(props: TProps): Id64String;\r\n /** Insert an element into the builder's iModel */\r\n insertElement<TProps extends ElementProps>(props: TProps): Id64String;\r\n /** Insert an element aspect into the specified element */\r\n insertAspect<TProps extends ElementAspectProps>(props: TProps): void;\r\n /**\r\n * Create code for specified element.\r\n * Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).\r\n */\r\n createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;\r\n}\r\n\r\n/**\r\n * Function that creates an iModel and returns a connection to it.\r\n * @param name Name of test IModel\r\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\r\n *\r\n * @beta\r\n */\r\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection> {\r\n const outputFile = setupOutputFileLocation(name);\r\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\r\n const builder = new IModelBuilder(db);\r\n try {\r\n cb(builder);\r\n } finally {\r\n db.saveChanges(\"Created test IModel\");\r\n db.close();\r\n }\r\n return SnapshotConnection.openFile(outputFile);\r\n}\r\n\r\n/**\r\n * Default implementation of IModel builder pattern. Used for building IModels to test rulesets.\r\n *\r\n * @internal\r\n */\r\nexport class IModelBuilder implements TestIModelBuilder {\r\n private _iModel: IModelDb;\r\n\r\n constructor(iModel: IModelDb) {\r\n this._iModel = iModel;\r\n }\r\n\r\n public insertModel<TProps extends ModelProps>(props: TProps): Id64String {\r\n return this._iModel.models.insertModel(props);\r\n }\r\n\r\n public insertElement<TProps extends ElementProps>(props: TProps): Id64String {\r\n return this._iModel.elements.insertElement(props);\r\n }\r\n\r\n public insertAspect<TProps extends ElementAspectProps>(props: TProps): void {\r\n this._iModel.elements.insertAspect(props);\r\n }\r\n\r\n public createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code {\r\n const codeSpec: CodeSpec = this._iModel.codeSpecs.getByName(codeSpecName);\r\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\r\n }\r\n}\r\n\r\n/**\r\n * Prepare for an output file by:\r\n * - Resolving the output file name under the known test output directory\r\n * - Making directories as necessary\r\n * - Removing a previous copy of the output file\r\n * @param fileName Name of output file\r\n */\r\nfunction setupOutputFileLocation(fileName: string): LocalFileName {\r\n const testOutputDir = getTestOutputDir();\r\n !IModelJsFs.existsSync(testOutputDir) && IModelJsFs.mkdirSync(testOutputDir);\r\n\r\n const outputFile = path.join(testOutputDir, `${fileName}.bim`);\r\n IModelJsFs.existsSync(outputFile) && IModelJsFs.unlinkSync(outputFile);\r\n return outputFile;\r\n}\r\n"]}
|
|
@@ -20,10 +20,10 @@ export * from "./presentation-testing/ContentBuilder";
|
|
|
20
20
|
*/
|
|
21
21
|
export * from "./presentation-testing/Helpers";
|
|
22
22
|
/**
|
|
23
|
-
* @module
|
|
23
|
+
* @module IModel
|
|
24
24
|
*
|
|
25
|
-
* @docs-group-description
|
|
26
|
-
*
|
|
25
|
+
* @docs-group-description IModel
|
|
26
|
+
* Utilities for creating test iModels that can be used to exercise presentation rules.
|
|
27
27
|
*/
|
|
28
|
-
export * from "./presentation-testing/
|
|
28
|
+
export * from "./presentation-testing/IModelUtilities";
|
|
29
29
|
//# sourceMappingURL=presentation-testing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation-testing.d.ts","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,cAAc,yCAAyC,CAAC;AAExD;;;;;GAKG;AACH,cAAc,uCAAuC,CAAC;AAEtD;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC;AAE/C;;;;;GAKG;AACH,cAAc,
|
|
1
|
+
{"version":3,"file":"presentation-testing.d.ts","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,cAAc,yCAAyC,CAAC;AAExD;;;;;GAKG;AACH,cAAc,uCAAuC,CAAC;AAEtD;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC;AAE/C;;;;;GAKG;AACH,cAAc,wCAAwC,CAAC"}
|
|
@@ -36,10 +36,10 @@ __exportStar(require("./presentation-testing/ContentBuilder"), exports);
|
|
|
36
36
|
*/
|
|
37
37
|
__exportStar(require("./presentation-testing/Helpers"), exports);
|
|
38
38
|
/**
|
|
39
|
-
* @module
|
|
39
|
+
* @module IModel
|
|
40
40
|
*
|
|
41
|
-
* @docs-group-description
|
|
42
|
-
*
|
|
41
|
+
* @docs-group-description IModel
|
|
42
|
+
* Utilities for creating test iModels that can be used to exercise presentation rules.
|
|
43
43
|
*/
|
|
44
|
-
__exportStar(require("./presentation-testing/
|
|
44
|
+
__exportStar(require("./presentation-testing/IModelUtilities"), exports);
|
|
45
45
|
//# sourceMappingURL=presentation-testing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;;;;GAKG;AACH,0EAAwD;AAExD;;;;;GAKG;AACH,wEAAsD;AAEtD;;;;;GAKG;AACH,iEAA+C;AAE/C;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;;;;GAKG;AACH,0EAAwD;AAExD;;;;;GAKG;AACH,wEAAsD;AAEtD;;;;;GAKG;AACH,iEAA+C;AAE/C;;;;;GAKG;AACH,yEAAuD","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/**\r\n * @module Hierarchies\r\n *\r\n * @docs-group-description Hierarchies\r\n * Types for testing hierarchies.\r\n */\r\nexport * from \"./presentation-testing/HierarchyBuilder\";\r\n\r\n/**\r\n * @module Content\r\n *\r\n * @docs-group-description Content\r\n * Types for testing content.\r\n */\r\nexport * from \"./presentation-testing/ContentBuilder\";\r\n\r\n/**\r\n * @module Helpers\r\n *\r\n * @docs-group-description Helpers\r\n * Various test helpers.\r\n */\r\nexport * from \"./presentation-testing/Helpers\";\r\n\r\n/**\r\n * @module IModel\r\n *\r\n * @docs-group-description IModel\r\n * Utilities for creating test iModels that can be used to exercise presentation rules.\r\n */\r\nexport * from \"./presentation-testing/IModelUtilities\";\r\n"]}
|
|
@@ -2,6 +2,8 @@ import { IModelHostOptions } from "@itwin/core-backend";
|
|
|
2
2
|
import { IModelApp, IModelAppOptions } from "@itwin/core-frontend";
|
|
3
3
|
import { HierarchyCacheMode, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from "@itwin/presentation-backend";
|
|
4
4
|
import { PresentationProps as PresentationFrontendProps } from "@itwin/presentation-frontend";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare const getTestOutputDir: () => string;
|
|
5
7
|
export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
|
|
6
8
|
/** @public */
|
|
7
9
|
export interface PresentationTestingInitProps {
|
|
@@ -17,6 +19,8 @@ export interface PresentationTestingInitProps {
|
|
|
17
19
|
};
|
|
18
20
|
/** `IModelApp` options */
|
|
19
21
|
frontendAppOptions?: IModelAppOptions;
|
|
22
|
+
/** Custom test output directory. Defaults to temporary directory provided by the OS. */
|
|
23
|
+
testOutputDir?: string;
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* Initialize the framework for presentation testing. The function sets up backend,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAUA,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKpE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAAuC,wBAAwB,IAAI,wBAAwB,EAAE,uBAAuB,EACvI,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,qEA+BtB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDAuBrB,CAAC"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module Helpers
|
|
7
7
|
*/
|
|
8
|
+
/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.
|
|
8
9
|
import { join } from "path";
|
|
9
10
|
import * as rimraf from "rimraf";
|
|
10
11
|
import { IModelHost } from "@itwin/core-backend";
|
|
@@ -14,6 +15,7 @@ import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
|
|
|
14
15
|
import { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerMode, } from "@itwin/presentation-backend";
|
|
15
16
|
import { PresentationRpcInterface } from "@itwin/presentation-common";
|
|
16
17
|
import { Presentation as PresentationFrontend } from "@itwin/presentation-frontend";
|
|
18
|
+
import { tmpdir } from "os";
|
|
17
19
|
function initializeRpcInterfaces(interfaces) {
|
|
18
20
|
const config = class extends RpcDefaultConfiguration {
|
|
19
21
|
constructor() {
|
|
@@ -33,6 +35,13 @@ function initializeRpcInterfaces(interfaces) {
|
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
let isInitialized = false;
|
|
38
|
+
const defaultTestOutputDir = tmpdir();
|
|
39
|
+
let testOutputDir;
|
|
40
|
+
/** @internal */
|
|
41
|
+
export const getTestOutputDir = () => {
|
|
42
|
+
return testOutputDir !== null && testOutputDir !== void 0 ? testOutputDir : defaultTestOutputDir;
|
|
43
|
+
};
|
|
44
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
36
45
|
export { HierarchyCacheMode, PresentationManagerMode };
|
|
37
46
|
/**
|
|
38
47
|
* Initialize the framework for presentation testing. The function sets up backend,
|
|
@@ -67,6 +76,7 @@ export const initialize = async (props) => {
|
|
|
67
76
|
},
|
|
68
77
|
};
|
|
69
78
|
await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });
|
|
79
|
+
testOutputDir = props.testOutputDir;
|
|
70
80
|
isInitialized = true;
|
|
71
81
|
};
|
|
72
82
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,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,EACL,sBAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAA0B,0BAA0B,GACtH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAoB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAAE,YAAY,IAAI,mBAAmB,EAAwD,uBAAuB,GACvI,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,YAAY,IAAI,oBAAoB,EAAkD,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"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CAAC;AACxB,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Helpers\r\n */\r\n/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.\r\nimport { join } from \"path\";\r\nimport * as rimraf from \"rimraf\";\r\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\r\nimport { Guid } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface,\r\n} from \"@itwin/core-common\";\r\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\r\nimport {\r\n HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode,\r\n} from \"@itwin/presentation-backend\";\r\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\r\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\r\nimport { tmpdir } from \"os\";\r\n\r\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\r\n const config = class extends RpcDefaultConfiguration {\r\n public override interfaces: any = () => interfaces;\r\n };\r\n\r\n for (const definition of interfaces)\r\n RpcConfiguration.assign(definition, () => config);\r\n\r\n const instance = RpcConfiguration.obtain(config);\r\n\r\n try {\r\n RpcConfiguration.initializeInterfaces(instance);\r\n } catch {\r\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\r\n // multiple different tests want to set up rpc interfaces\r\n }\r\n}\r\n\r\nlet isInitialized = false;\r\n\r\nconst defaultTestOutputDir = tmpdir();\r\nlet testOutputDir: string | undefined;\r\n\r\n/** @internal */\r\nexport const getTestOutputDir = (): string => {\r\n return testOutputDir ?? defaultTestOutputDir;\r\n};\r\n\r\n// eslint-disable-next-line deprecation/deprecation\r\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\r\n\r\n/** @public */\r\nexport interface PresentationTestingInitProps {\r\n /** Properties for backend initialization */\r\n backendProps?: PresentationBackendProps;\r\n /** Properties for `IModelHost` */\r\n backendHostProps?: IModelHostOptions;\r\n /** Properties for frontend initialization */\r\n frontendProps?: PresentationFrontendProps;\r\n /** IModelApp implementation */\r\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\r\n /** `IModelApp` options */\r\n frontendAppOptions?: IModelAppOptions;\r\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\r\n testOutputDir?: string;\r\n}\r\n\r\n/**\r\n * Initialize the framework for presentation testing. The function sets up backend,\r\n * frontend and RPC communication between them.\r\n *\r\n * @see `terminate`\r\n *\r\n * @public\r\n */\r\nexport const initialize = async (props?: PresentationTestingInitProps) => {\r\n if (isInitialized)\r\n return;\r\n\r\n if (!props)\r\n props = {};\r\n\r\n // set up rpc interfaces\r\n initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\r\n\r\n // init backend\r\n // make sure backend gets assigned an id which puts its resources into a unique directory\r\n props.backendProps = props.backendProps ?? {};\r\n if (!props.backendProps.id)\r\n props.backendProps.id = `test-${Guid.createValue()}`;\r\n await IModelHost.startup({ cacheDir: join(__dirname, \".cache\"), ...props.backendHostProps });\r\n PresentationBackend.initialize(props.backendProps);\r\n\r\n // init frontend\r\n if (!props.frontendApp)\r\n props.frontendApp = NoRenderApp;\r\n await props.frontendApp.startup(props.frontendAppOptions);\r\n const defaultFrontendProps: PresentationFrontendProps = {\r\n presentation: {\r\n activeLocale: IModelApp.localization.getLanguageList()[0],\r\n },\r\n };\r\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\r\n testOutputDir = props.testOutputDir;\r\n\r\n isInitialized = true;\r\n};\r\n\r\n/**\r\n * Undoes the setup made by `initialize`.\r\n * @param frontendApp IModelApp implementation\r\n *\r\n * @see `initialize`\r\n *\r\n * @public\r\n */\r\nexport const terminate = async (frontendApp = IModelApp) => {\r\n if (!isInitialized)\r\n return;\r\n\r\n // store directory that needs to be cleaned-up\r\n let hierarchiesCacheDirectory: string | undefined;\r\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\r\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk)\r\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\r\n else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid)\r\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\r\n\r\n // terminate backend\r\n PresentationBackend.terminate();\r\n await IModelHost.shutdown();\r\n if (hierarchiesCacheDirectory)\r\n rimraf.sync(hierarchiesCacheDirectory);\r\n\r\n // terminate frontend\r\n PresentationFrontend.terminate();\r\n await frontendApp.shutdown();\r\n\r\n isInitialized = false;\r\n};\r\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module IModel
|
|
3
|
+
*/
|
|
4
|
+
import { IModelDb } from "@itwin/core-backend";
|
|
5
|
+
import { Id64String } from "@itwin/core-bentley";
|
|
6
|
+
import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps } from "@itwin/core-common";
|
|
7
|
+
import { IModelConnection } from "@itwin/core-frontend";
|
|
8
|
+
/**
|
|
9
|
+
* Interface for IModel builder pattern. Used for building IModels to test rulesets.
|
|
10
|
+
*
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export interface TestIModelBuilder {
|
|
14
|
+
/** Insert a model into the builder's iModel */
|
|
15
|
+
insertModel<TProps extends ModelProps>(props: TProps): Id64String;
|
|
16
|
+
/** Insert an element into the builder's iModel */
|
|
17
|
+
insertElement<TProps extends ElementProps>(props: TProps): Id64String;
|
|
18
|
+
/** Insert an element aspect into the specified element */
|
|
19
|
+
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
20
|
+
/**
|
|
21
|
+
* Create code for specified element.
|
|
22
|
+
* Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).
|
|
23
|
+
*/
|
|
24
|
+
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Function that creates an iModel and returns a connection to it.
|
|
28
|
+
* @param name Name of test IModel
|
|
29
|
+
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
30
|
+
*
|
|
31
|
+
* @beta
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;
|
|
34
|
+
/**
|
|
35
|
+
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export declare class IModelBuilder implements TestIModelBuilder {
|
|
40
|
+
private _iModel;
|
|
41
|
+
constructor(iModel: IModelDb);
|
|
42
|
+
insertModel<TProps extends ModelProps>(props: TProps): Id64String;
|
|
43
|
+
insertElement<TProps extends ElementProps>(props: TProps): Id64String;
|
|
44
|
+
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
45
|
+
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=IModelUtilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAA0B,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM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0,0 +1,70 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module IModel
|
|
7
|
+
*/
|
|
8
|
+
import { IModelJsFs, SnapshotDb } from "@itwin/core-backend";
|
|
9
|
+
import { Code } from "@itwin/core-common";
|
|
10
|
+
import { SnapshotConnection } from "@itwin/core-frontend";
|
|
11
|
+
import path from "path";
|
|
12
|
+
import { getTestOutputDir } from "./Helpers";
|
|
13
|
+
/**
|
|
14
|
+
* Function that creates an iModel and returns a connection to it.
|
|
15
|
+
* @param name Name of test IModel
|
|
16
|
+
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
17
|
+
*
|
|
18
|
+
* @beta
|
|
19
|
+
*/
|
|
20
|
+
export async function buildTestIModel(name, cb) {
|
|
21
|
+
const outputFile = setupOutputFileLocation(name);
|
|
22
|
+
const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });
|
|
23
|
+
const builder = new IModelBuilder(db);
|
|
24
|
+
try {
|
|
25
|
+
cb(builder);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
db.saveChanges("Created test IModel");
|
|
29
|
+
db.close();
|
|
30
|
+
}
|
|
31
|
+
return SnapshotConnection.openFile(outputFile);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export class IModelBuilder {
|
|
39
|
+
constructor(iModel) {
|
|
40
|
+
this._iModel = iModel;
|
|
41
|
+
}
|
|
42
|
+
insertModel(props) {
|
|
43
|
+
return this._iModel.models.insertModel(props);
|
|
44
|
+
}
|
|
45
|
+
insertElement(props) {
|
|
46
|
+
return this._iModel.elements.insertElement(props);
|
|
47
|
+
}
|
|
48
|
+
insertAspect(props) {
|
|
49
|
+
this._iModel.elements.insertAspect(props);
|
|
50
|
+
}
|
|
51
|
+
createCode(scopeModelId, codeSpecName, codeValue) {
|
|
52
|
+
const codeSpec = this._iModel.codeSpecs.getByName(codeSpecName);
|
|
53
|
+
return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Prepare for an output file by:
|
|
58
|
+
* - Resolving the output file name under the known test output directory
|
|
59
|
+
* - Making directories as necessary
|
|
60
|
+
* - Removing a previous copy of the output file
|
|
61
|
+
* @param fileName Name of output file
|
|
62
|
+
*/
|
|
63
|
+
function setupOutputFileLocation(fileName) {
|
|
64
|
+
const testOutputDir = getTestOutputDir();
|
|
65
|
+
!IModelJsFs.existsSync(testOutputDir) && IModelJsFs.mkdirSync(testOutputDir);
|
|
66
|
+
const outputFile = path.join(testOutputDir, `${fileName}.bim`);
|
|
67
|
+
IModelJsFs.existsSync(outputFile) && IModelJsFs.unlinkSync(outputFile);
|
|
68
|
+
return outputFile;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=IModelUtilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAY,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAe,IAAI,EAAyF,MAAM,oBAAoB,CAAC;AAC9I,OAAO,EAAoB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAqB7C;;;;;;GAMG;AACH,MAAM,CAAC,K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ChF,CAAC;CACF;AAED;;;;;;GAMG;AACH,SAAS,uBAAuB,CAAC,QAAgB;IAC/C,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,CAAC,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAE7E,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,QAAQ,MAAM,CAAC,CAAC;IAC/D,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACvE,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module IModel\r\n */\r\n\r\nimport { IModelDb, IModelJsFs, SnapshotDb } from \"@itwin/core-backend\";\r\nimport { Id64String } from \"@itwin/core-bentley\";\r\nimport { BisCodeSpec, Code, CodeScopeProps, CodeSpec, ElementAspectProps, ElementProps, LocalFileName, ModelProps } from \"@itwin/core-common\";\r\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\r\nimport path from \"path\";\r\nimport { getTestOutputDir } from \"./Helpers\";\r\n\r\n/**\r\n * Interface for IModel builder pattern. Used for building IModels to test rulesets.\r\n *\r\n * @beta\r\n */\r\nexport interface TestIModelBuilder {\r\n /** Insert a model into the builder's iModel */\r\n insertModel<TProps extends ModelProps>(props: TProps): Id64String;\r\n /** Insert an element into the builder's iModel */\r\n insertElement<TProps extends ElementProps>(props: TProps): Id64String;\r\n /** Insert an element aspect into the specified element */\r\n insertAspect<TProps extends ElementAspectProps>(props: TProps): void;\r\n /**\r\n * Create code for specified element.\r\n * Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).\r\n */\r\n createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;\r\n}\r\n\r\n/**\r\n * Function that creates an iModel and returns a connection to it.\r\n * @param name Name of test IModel\r\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\r\n *\r\n * @beta\r\n */\r\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection> {\r\n const outputFile = setupOutputFileLocation(name);\r\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\r\n const builder = new IModelBuilder(db);\r\n try {\r\n cb(builder);\r\n } finally {\r\n db.saveChanges(\"Created test IModel\");\r\n db.close();\r\n }\r\n return SnapshotConnection.openFile(outputFile);\r\n}\r\n\r\n/**\r\n * Default implementation of IModel builder pattern. Used for building IModels to test rulesets.\r\n *\r\n * @internal\r\n */\r\nexport class IModelBuilder implements TestIModelBuilder {\r\n private _iModel: IModelDb;\r\n\r\n constructor(iModel: IModelDb) {\r\n this._iModel = iModel;\r\n }\r\n\r\n public insertModel<TProps extends ModelProps>(props: TProps): Id64String {\r\n return this._iModel.models.insertModel(props);\r\n }\r\n\r\n public insertElement<TProps extends ElementProps>(props: TProps): Id64String {\r\n return this._iModel.elements.insertElement(props);\r\n }\r\n\r\n public insertAspect<TProps extends ElementAspectProps>(props: TProps): void {\r\n this._iModel.elements.insertAspect(props);\r\n }\r\n\r\n public createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code {\r\n const codeSpec: CodeSpec = this._iModel.codeSpecs.getByName(codeSpecName);\r\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\r\n }\r\n}\r\n\r\n/**\r\n * Prepare for an output file by:\r\n * - Resolving the output file name under the known test output directory\r\n * - Making directories as necessary\r\n * - Removing a previous copy of the output file\r\n * @param fileName Name of output file\r\n */\r\nfunction setupOutputFileLocation(fileName: string): LocalFileName {\r\n const testOutputDir = getTestOutputDir();\r\n !IModelJsFs.existsSync(testOutputDir) && IModelJsFs.mkdirSync(testOutputDir);\r\n\r\n const outputFile = path.join(testOutputDir, `${fileName}.bim`);\r\n IModelJsFs.existsSync(outputFile) && IModelJsFs.unlinkSync(outputFile);\r\n return outputFile;\r\n}\r\n"]}
|