@itwin/presentation-testing 4.0.0-dev.22 → 4.0.0-dev.24
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 +46 -1
- package/lib/cjs/presentation-testing/IModelUtilities.d.ts +10 -2
- package/lib/cjs/presentation-testing/IModelUtilities.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/IModelUtilities.js +9 -9
- package/lib/cjs/presentation-testing/IModelUtilities.js.map +1 -1
- package/lib/esm/presentation-testing/IModelUtilities.d.ts +10 -2
- package/lib/esm/presentation-testing/IModelUtilities.d.ts.map +1 -1
- package/lib/esm/presentation-testing/IModelUtilities.js +7 -8
- package/lib/esm/presentation-testing/IModelUtilities.js.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
This log was last generated on Wed, 30 Nov 2022 14:28:19 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
|
+
## 3.6.0
|
|
6
|
+
Wed, 08 Feb 2023 14:58:40 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- Use `EmptyLocalization` for localization in tests to increase test performance
|
|
11
|
+
- Deprecate `ContentBuilder` methods: `createContentForAllInstances` and `createContentForInstancePerClass`.
|
|
12
|
+
- Added reference docs generation
|
|
13
|
+
|
|
14
|
+
## 3.5.6
|
|
15
|
+
Fri, 24 Feb 2023 16:02:47 GMT
|
|
16
|
+
|
|
17
|
+
_Version update only_
|
|
18
|
+
|
|
19
|
+
## 3.5.5
|
|
20
|
+
Thu, 26 Jan 2023 22:53:28 GMT
|
|
21
|
+
|
|
22
|
+
_Version update only_
|
|
23
|
+
|
|
24
|
+
## 3.5.4
|
|
25
|
+
Wed, 18 Jan 2023 15:27:15 GMT
|
|
26
|
+
|
|
27
|
+
_Version update only_
|
|
28
|
+
|
|
29
|
+
## 3.5.3
|
|
30
|
+
Fri, 13 Jan 2023 17:23:07 GMT
|
|
31
|
+
|
|
32
|
+
_Version update only_
|
|
33
|
+
|
|
34
|
+
## 3.5.2
|
|
35
|
+
Wed, 11 Jan 2023 16:46:30 GMT
|
|
36
|
+
|
|
37
|
+
_Version update only_
|
|
38
|
+
|
|
39
|
+
## 3.5.1
|
|
40
|
+
Thu, 15 Dec 2022 16:38:29 GMT
|
|
41
|
+
|
|
42
|
+
_Version update only_
|
|
43
|
+
|
|
44
|
+
## 3.5.0
|
|
45
|
+
Wed, 07 Dec 2022 19:12:37 GMT
|
|
46
|
+
|
|
47
|
+
### Updates
|
|
48
|
+
|
|
49
|
+
- Add `buildTestIModel` API for creating test iModels
|
|
50
|
+
|
|
5
51
|
## 3.4.7
|
|
6
52
|
Wed, 30 Nov 2022 14:28:19 GMT
|
|
7
53
|
|
|
@@ -924,4 +970,3 @@ Thu, 10 Jan 2019 22:46:17 GMT
|
|
|
924
970
|
### Updates
|
|
925
971
|
|
|
926
972
|
- Added initialization/termination helpers.
|
|
927
|
-
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module IModel
|
|
3
3
|
*/
|
|
4
|
+
/// <reference types="mocha" />
|
|
4
5
|
import { IModelDb } from "@itwin/core-backend";
|
|
5
6
|
import { Id64String } from "@itwin/core-bentley";
|
|
6
7
|
import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps } from "@itwin/core-common";
|
|
7
8
|
import { IModelConnection } from "@itwin/core-frontend";
|
|
8
9
|
/**
|
|
9
10
|
* Interface for IModel builder pattern. Used for building IModels to test rulesets.
|
|
10
|
-
*
|
|
11
11
|
* @beta
|
|
12
12
|
*/
|
|
13
13
|
export interface TestIModelBuilder {
|
|
@@ -27,10 +27,16 @@ export interface TestIModelBuilder {
|
|
|
27
27
|
* Function that creates an iModel and returns a connection to it.
|
|
28
28
|
* @param name Name of test IModel
|
|
29
29
|
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
30
|
-
*
|
|
31
30
|
* @beta
|
|
32
31
|
*/
|
|
33
32
|
export declare function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;
|
|
33
|
+
/**
|
|
34
|
+
* Function that creates an iModel and returns a connection to it.
|
|
35
|
+
* @param mochaContext Mocha context to generate iModel name from
|
|
36
|
+
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
37
|
+
* @beta
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;
|
|
34
40
|
/**
|
|
35
41
|
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
36
42
|
*
|
|
@@ -44,4 +50,6 @@ export declare class IModelBuilder implements TestIModelBuilder {
|
|
|
44
50
|
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
45
51
|
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
46
52
|
}
|
|
53
|
+
/** @internal */
|
|
54
|
+
export declare function createFileNameFromString(str: string): string;
|
|
47
55
|
//# sourceMappingURL=IModelUtilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG
|
|
1
|
+
{"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG;;AAIH,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,OA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,IAAI;CAIpG;AAkBD,gBAAgB;AAChB,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,UAEnD"}
|
|
@@ -10,20 +10,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.IModelBuilder = exports.buildTestIModel = void 0;
|
|
13
|
+
exports.createFileNameFromString = exports.IModelBuilder = exports.buildTestIModel = void 0;
|
|
14
14
|
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const sanitize_filename_1 = __importDefault(require("sanitize-filename"));
|
|
15
16
|
const core_backend_1 = require("@itwin/core-backend");
|
|
16
17
|
const core_common_1 = require("@itwin/core-common");
|
|
17
18
|
const core_frontend_1 = require("@itwin/core-frontend");
|
|
18
19
|
const Helpers_1 = require("./Helpers");
|
|
19
|
-
|
|
20
|
-
|
|
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) {
|
|
20
|
+
async function buildTestIModel(nameParam, cb) {
|
|
21
|
+
const name = (typeof nameParam === "string") ? nameParam : createFileNameFromString(nameParam.test.fullTitle());
|
|
27
22
|
const outputFile = setupOutputFileLocation(name);
|
|
28
23
|
const db = core_backend_1.SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });
|
|
29
24
|
const builder = new IModelBuilder(db);
|
|
@@ -81,4 +76,9 @@ function setupOutputFileLocation(fileName) {
|
|
|
81
76
|
core_backend_1.IModelJsFs.existsSync(outputFile) && core_backend_1.IModelJsFs.unlinkSync(outputFile);
|
|
82
77
|
return outputFile;
|
|
83
78
|
}
|
|
79
|
+
/** @internal */
|
|
80
|
+
function createFileNameFromString(str) {
|
|
81
|
+
return (0, sanitize_filename_1.default)(str.replace(" ", "-")).toLocaleLowerCase();
|
|
82
|
+
}
|
|
83
|
+
exports.createFileNameFromString = createFileNameFromString;
|
|
84
84
|
//# sourceMappingURL=IModelUtilities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;AAEH,gDAAwB;AACxB,sDAAuE;AAEvE,oDAA8I;AAC9I,wDAA4E;AAC5E,uCAA6C;
|
|
1
|
+
{"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;AAEH,gDAAwB;AACxB,0EAAyC;AACzC,sDAAuE;AAEvE,oDAA8I;AAC9I,wDAA4E;AAC5E,uCAA6C;AAmCtC,KAAK,UAAU,eAAe,CAAC,SAAiC,EAAE,EAAwC;IAC/G,MAAM,IAAI,GAAG,CAAC,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,wBAAwB,CAAC,SAAS,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IACjH,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,CAAC,OAAO,CAAC,CAAC;KACb;YAAS;QACR,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACtC,EAAE,CAAC,KAAK,EAAE,CAAC;KACZ;IACD,OAAO,kCAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CA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AC;AAED,gBAAgB;AAChB,SAAgB,wBAAwB,CAAC,GAAW;IAClD,OAAO,IAAA,2BAAQ,EAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;AAC7D,CAAC;AAFD,4DAEC","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 IModel\n */\n\nimport path from \"path\";\nimport sanitize from \"sanitize-filename\";\nimport { IModelDb, IModelJsFs, SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, CodeSpec, ElementAspectProps, ElementProps, LocalFileName, ModelProps } from \"@itwin/core-common\";\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\nimport { getTestOutputDir } from \"./Helpers\";\n\n/**\n * Interface for IModel builder pattern. Used for building IModels to test rulesets.\n * @beta\n */\nexport interface TestIModelBuilder {\n /** Insert a model into the builder's iModel */\n insertModel<TProps extends ModelProps>(props: TProps): Id64String;\n /** Insert an element into the builder's iModel */\n insertElement<TProps extends ElementProps>(props: TProps): Id64String;\n /** Insert an element aspect into the specified element */\n insertAspect<TProps extends ElementAspectProps>(props: TProps): void;\n /**\n * Create code for specified element.\n * Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).\n */\n createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;\n}\n\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection> {\n const name = (typeof nameParam === \"string\") ? nameParam : createFileNameFromString(nameParam.test!.fullTitle());\n const outputFile = setupOutputFileLocation(name);\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\n const builder = new IModelBuilder(db);\n try {\n cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return SnapshotConnection.openFile(outputFile);\n}\n\n/**\n * Default implementation of IModel builder pattern. Used for building IModels to test rulesets.\n *\n * @internal\n */\nexport class IModelBuilder implements TestIModelBuilder {\n private _iModel: IModelDb;\n\n constructor(iModel: IModelDb) {\n this._iModel = iModel;\n }\n\n public insertModel<TProps extends ModelProps>(props: TProps): Id64String {\n return this._iModel.models.insertModel(props);\n }\n\n public insertElement<TProps extends ElementProps>(props: TProps): Id64String {\n return this._iModel.elements.insertElement(props);\n }\n\n public insertAspect<TProps extends ElementAspectProps>(props: TProps): void {\n this._iModel.elements.insertAspect(props);\n }\n\n public createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code {\n const codeSpec: CodeSpec = this._iModel.codeSpecs.getByName(codeSpecName);\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\n }\n}\n\n/**\n * Prepare for an output file by:\n * - Resolving the output file name under the known test output directory\n * - Making directories as necessary\n * - Removing a previous copy of the output file\n * @param fileName Name of output file\n */\nfunction setupOutputFileLocation(fileName: string): LocalFileName {\n const testOutputDir = getTestOutputDir();\n !IModelJsFs.existsSync(testOutputDir) && IModelJsFs.mkdirSync(testOutputDir);\n\n const outputFile = path.join(testOutputDir, `${fileName}.bim`);\n IModelJsFs.existsSync(outputFile) && IModelJsFs.unlinkSync(outputFile);\n return outputFile;\n}\n\n/** @internal */\nexport function createFileNameFromString(str: string) {\n return sanitize(str.replace(\" \", \"-\")).toLocaleLowerCase();\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module IModel
|
|
3
3
|
*/
|
|
4
|
+
/// <reference types="mocha" />
|
|
4
5
|
import { IModelDb } from "@itwin/core-backend";
|
|
5
6
|
import { Id64String } from "@itwin/core-bentley";
|
|
6
7
|
import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps } from "@itwin/core-common";
|
|
7
8
|
import { IModelConnection } from "@itwin/core-frontend";
|
|
8
9
|
/**
|
|
9
10
|
* Interface for IModel builder pattern. Used for building IModels to test rulesets.
|
|
10
|
-
*
|
|
11
11
|
* @beta
|
|
12
12
|
*/
|
|
13
13
|
export interface TestIModelBuilder {
|
|
@@ -27,10 +27,16 @@ export interface TestIModelBuilder {
|
|
|
27
27
|
* Function that creates an iModel and returns a connection to it.
|
|
28
28
|
* @param name Name of test IModel
|
|
29
29
|
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
30
|
-
*
|
|
31
30
|
* @beta
|
|
32
31
|
*/
|
|
33
32
|
export declare function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;
|
|
33
|
+
/**
|
|
34
|
+
* Function that creates an iModel and returns a connection to it.
|
|
35
|
+
* @param mochaContext Mocha context to generate iModel name from
|
|
36
|
+
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
37
|
+
* @beta
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;
|
|
34
40
|
/**
|
|
35
41
|
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
36
42
|
*
|
|
@@ -44,4 +50,6 @@ export declare class IModelBuilder implements TestIModelBuilder {
|
|
|
44
50
|
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
45
51
|
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
46
52
|
}
|
|
53
|
+
/** @internal */
|
|
54
|
+
export declare function createFileNameFromString(str: string): string;
|
|
47
55
|
//# sourceMappingURL=IModelUtilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG
|
|
1
|
+
{"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG;;AAIH,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;AAG5E;;;GAGG;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;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACzH;;;;;GAKG;AAEH,wBAAsB,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAexI;;;;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;AAkBD,gBAAgB;AAChB,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,UAEnD"}
|
|
@@ -6,18 +6,13 @@
|
|
|
6
6
|
* @module IModel
|
|
7
7
|
*/
|
|
8
8
|
import path from "path";
|
|
9
|
+
import sanitize from "sanitize-filename";
|
|
9
10
|
import { IModelJsFs, SnapshotDb } from "@itwin/core-backend";
|
|
10
11
|
import { Code } from "@itwin/core-common";
|
|
11
12
|
import { SnapshotConnection } from "@itwin/core-frontend";
|
|
12
13
|
import { getTestOutputDir } from "./Helpers";
|
|
13
|
-
|
|
14
|
-
|
|
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) {
|
|
14
|
+
export async function buildTestIModel(nameParam, cb) {
|
|
15
|
+
const name = (typeof nameParam === "string") ? nameParam : createFileNameFromString(nameParam.test.fullTitle());
|
|
21
16
|
const outputFile = setupOutputFileLocation(name);
|
|
22
17
|
const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });
|
|
23
18
|
const builder = new IModelBuilder(db);
|
|
@@ -73,4 +68,8 @@ function setupOutputFileLocation(fileName) {
|
|
|
73
68
|
IModelJsFs.existsSync(outputFile) && IModelJsFs.unlinkSync(outputFile);
|
|
74
69
|
return outputFile;
|
|
75
70
|
}
|
|
71
|
+
/** @internal */
|
|
72
|
+
export function createFileNameFromString(str) {
|
|
73
|
+
return sanitize(str.replace(" ", "-")).toLocaleLowerCase();
|
|
74
|
+
}
|
|
76
75
|
//# sourceMappingURL=IModelUtilities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,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,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAY,UAAU,EAAE,UAAU,EAAE,MAAM,q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CAAoC,KAAa;QAClE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAEM,UAAU,CAAC,YAA4B,EAAE,YAAyB,EAAE,SAAiB;QAC1F,MAAM,QAAQ,GAAa,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QAC1E,OAAO,IAAI,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAChF,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;AAED,gBAAgB;AAChB,MAAM,UAAU,wBAAwB,CAAC,GAAW;IAClD,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;AAC7D,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 IModel\n */\n\nimport path from \"path\";\nimport sanitize from \"sanitize-filename\";\nimport { IModelDb, IModelJsFs, SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, CodeSpec, ElementAspectProps, ElementProps, LocalFileName, ModelProps } from \"@itwin/core-common\";\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\nimport { getTestOutputDir } from \"./Helpers\";\n\n/**\n * Interface for IModel builder pattern. Used for building IModels to test rulesets.\n * @beta\n */\nexport interface TestIModelBuilder {\n /** Insert a model into the builder's iModel */\n insertModel<TProps extends ModelProps>(props: TProps): Id64String;\n /** Insert an element into the builder's iModel */\n insertElement<TProps extends ElementProps>(props: TProps): Id64String;\n /** Insert an element aspect into the specified element */\n insertAspect<TProps extends ElementAspectProps>(props: TProps): void;\n /**\n * Create code for specified element.\n * Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).\n */\n createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;\n}\n\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection> {\n const name = (typeof nameParam === \"string\") ? nameParam : createFileNameFromString(nameParam.test!.fullTitle());\n const outputFile = setupOutputFileLocation(name);\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\n const builder = new IModelBuilder(db);\n try {\n cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return SnapshotConnection.openFile(outputFile);\n}\n\n/**\n * Default implementation of IModel builder pattern. Used for building IModels to test rulesets.\n *\n * @internal\n */\nexport class IModelBuilder implements TestIModelBuilder {\n private _iModel: IModelDb;\n\n constructor(iModel: IModelDb) {\n this._iModel = iModel;\n }\n\n public insertModel<TProps extends ModelProps>(props: TProps): Id64String {\n return this._iModel.models.insertModel(props);\n }\n\n public insertElement<TProps extends ElementProps>(props: TProps): Id64String {\n return this._iModel.elements.insertElement(props);\n }\n\n public insertAspect<TProps extends ElementAspectProps>(props: TProps): void {\n this._iModel.elements.insertAspect(props);\n }\n\n public createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code {\n const codeSpec: CodeSpec = this._iModel.codeSpecs.getByName(codeSpecName);\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\n }\n}\n\n/**\n * Prepare for an output file by:\n * - Resolving the output file name under the known test output directory\n * - Making directories as necessary\n * - Removing a previous copy of the output file\n * @param fileName Name of output file\n */\nfunction setupOutputFileLocation(fileName: string): LocalFileName {\n const testOutputDir = getTestOutputDir();\n !IModelJsFs.existsSync(testOutputDir) && IModelJsFs.mkdirSync(testOutputDir);\n\n const outputFile = path.join(testOutputDir, `${fileName}.bim`);\n IModelJsFs.existsSync(outputFile) && IModelJsFs.unlinkSync(outputFile);\n return outputFile;\n}\n\n/** @internal */\nexport function createFileNameFromString(str: string) {\n return sanitize(str.replace(\" \", \"-\")).toLocaleLowerCase();\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/presentation-testing",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
3
|
+
"version": "4.0.0-dev.24",
|
|
4
4
|
"description": "Testing utilities for iTwin.js Presentation library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"test": "mocha --config ./.mocharc.json \"./lib/cjs/test/**/*.test.js\""
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"rimraf": "^3.0.2"
|
|
37
|
+
"rimraf": "^3.0.2",
|
|
38
|
+
"sanitize-filename": "^1.6.3"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"@itwin/appui-abstract": "^3.6.0 || ^4.0.0-dev.37",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"@itwin/presentation-backend": "^3.6.0 || ^4.0.0-dev.37",
|
|
47
48
|
"@itwin/presentation-common": "^3.6.0 || ^4.0.0-dev.37",
|
|
48
49
|
"@itwin/presentation-frontend": "^3.6.0 || ^4.0.0-dev.37",
|
|
49
|
-
"@itwin/presentation-components": "^4.0.0-dev.
|
|
50
|
+
"@itwin/presentation-components": "^4.0.0-dev.24"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@itwin/appui-abstract": "^4.0.0-dev.37",
|
|
@@ -65,7 +66,7 @@
|
|
|
65
66
|
"@itwin/presentation-backend": "^4.0.0-dev.37",
|
|
66
67
|
"@itwin/presentation-common": "^4.0.0-dev.37",
|
|
67
68
|
"@itwin/presentation-frontend": "^4.0.0-dev.37",
|
|
68
|
-
"@itwin/presentation-components": "^4.0.0-dev.
|
|
69
|
+
"@itwin/presentation-components": "^4.0.0-dev.24",
|
|
69
70
|
"@itwin/webgl-compatibility": "^4.0.0-dev.37",
|
|
70
71
|
"@types/chai": "4.3.1",
|
|
71
72
|
"@types/chai-as-promised": "^7",
|