@itwin/presentation-testing 5.0.16 → 5.1.0

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/lib/cjs/presentation-testing/FilenameUtils.d.ts +47 -0
  3. package/lib/cjs/presentation-testing/FilenameUtils.d.ts.map +1 -0
  4. package/lib/cjs/presentation-testing/{InternalUtils.js → FilenameUtils.js} +33 -11
  5. package/lib/cjs/presentation-testing/FilenameUtils.js.map +1 -0
  6. package/lib/cjs/presentation-testing/Helpers.d.ts.map +1 -1
  7. package/lib/cjs/presentation-testing/Helpers.js +13 -6
  8. package/lib/cjs/presentation-testing/Helpers.js.map +1 -1
  9. package/lib/cjs/presentation-testing/IModelBuilderImpl.d.ts +1 -1
  10. package/lib/cjs/presentation-testing/IModelBuilderImpl.d.ts.map +1 -1
  11. package/lib/cjs/presentation-testing/IModelBuilderImpl.js.map +1 -1
  12. package/lib/cjs/presentation-testing/IModelUtilities.js +5 -5
  13. package/lib/cjs/presentation-testing/IModelUtilities.js.map +1 -1
  14. package/lib/cjs/presentation-testing.d.ts +5 -4
  15. package/lib/cjs/presentation-testing.d.ts.map +1 -1
  16. package/lib/cjs/presentation-testing.js +11 -5
  17. package/lib/cjs/presentation-testing.js.map +1 -1
  18. package/lib/esm/presentation-testing/FilenameUtils.d.ts +47 -0
  19. package/lib/esm/presentation-testing/FilenameUtils.d.ts.map +1 -0
  20. package/lib/esm/presentation-testing/{InternalUtils.js → FilenameUtils.js} +33 -11
  21. package/lib/esm/presentation-testing/FilenameUtils.js.map +1 -0
  22. package/lib/esm/presentation-testing/Helpers.d.ts.map +1 -1
  23. package/lib/esm/presentation-testing/Helpers.js +12 -5
  24. package/lib/esm/presentation-testing/Helpers.js.map +1 -1
  25. package/lib/esm/presentation-testing/IModelBuilderImpl.d.ts +1 -1
  26. package/lib/esm/presentation-testing/IModelBuilderImpl.d.ts.map +1 -1
  27. package/lib/esm/presentation-testing/IModelBuilderImpl.js.map +1 -1
  28. package/lib/esm/presentation-testing/IModelUtilities.js +3 -3
  29. package/lib/esm/presentation-testing/IModelUtilities.js.map +1 -1
  30. package/lib/esm/presentation-testing.d.ts +5 -4
  31. package/lib/esm/presentation-testing.d.ts.map +1 -1
  32. package/lib/esm/presentation-testing.js +6 -5
  33. package/lib/esm/presentation-testing.js.map +1 -1
  34. package/package.json +39 -30
  35. package/lib/cjs/presentation-testing/InternalUtils.d.ts +0 -25
  36. package/lib/cjs/presentation-testing/InternalUtils.d.ts.map +0 -1
  37. package/lib/cjs/presentation-testing/InternalUtils.js.map +0 -1
  38. package/lib/esm/presentation-testing/InternalUtils.d.ts +0 -25
  39. package/lib/esm/presentation-testing/InternalUtils.d.ts.map +0 -1
  40. package/lib/esm/presentation-testing/InternalUtils.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Change Log - @itwin/presentation-testing
2
2
 
3
+ ## 5.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#754](https://github.com/iTwin/presentation/pull/754): Define `type` and `exports` attributes in `package.json`.
8
+
9
+ The change moves this package a step closer towards dropping CommonJS support - it's now transpiled from ESM to CommonJS instead of the opposite.
10
+
11
+ In addition, the `exports` attribute has been added to `package.json` to prohibit access to APIs that are not intended to be used by external consumers.
12
+
13
+ - [#754](https://github.com/iTwin/presentation/pull/754): Export file name utility functions.
14
+
15
+ - `getTestOutputDir` and `setTestOutputDir` - get/set functions for the global test output directory used by this package.
16
+ - `setupOutputFileLocation` - given a file name, returns a full path to the file in the test output directory.
17
+ - `createFileNameFromString` - creates a valid, sanitized file name from any string.
18
+ - `limitFilePathLength` - makes sure the given file path is shorter than 260 characters.
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies:
23
+ - @itwin/presentation-components@5.6.0
24
+
25
+ ## 5.0.17
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies:
30
+ - @itwin/presentation-components@5.5.0
31
+
3
32
  ## 5.0.16
4
33
 
5
34
  ### Patch Changes
@@ -0,0 +1,47 @@
1
+ import { LocalFileName } from "@itwin/core-common";
2
+ /**
3
+ * Get the output directory used by `setupOutputFileLocation` utility.
4
+ * @public
5
+ */
6
+ export declare function getTestOutputDir(): string;
7
+ /**
8
+ * Set the output directory used by `setupOutputFileLocation` utility.
9
+ * @public
10
+ */
11
+ export declare function setTestOutputDir(directoryPath: string | undefined): void;
12
+ /**
13
+ * Prepare for an output file path by:
14
+ * - Resolving the output file name under the known test output directory (see `getTestOutputDir` & `setTestOutputDir`).
15
+ * - Making sure the output directories exist.
16
+ * - Removing a previous copy of the output file.
17
+ *
18
+ * @param fileName Name of output file. The actual file name may get modified to fit within the file system limits.
19
+ *
20
+ * @public
21
+ */
22
+ export declare function setupOutputFileLocation(fileName: string): LocalFileName;
23
+ /**
24
+ * An utility to create a valid file name from any string. Sanitizes all invalid characters,
25
+ * replaces spaces with `-`, makes everything lower case.
26
+ *
27
+ * @public
28
+ */
29
+ export declare function createFileNameFromString(str: string): string;
30
+ /**
31
+ * `itwinjs-core` creates some accompanying files for each iModels and their names are formed by appending
32
+ * a suffix to iModel file name. This constant should account for the maximum suffix length.
33
+ * @internal
34
+ */
35
+ export declare const FILE_PATH_RESERVED_CHARACTERS = 13;
36
+ /**
37
+ * An utility to make sure file path is shorter than 260 characters.
38
+ *
39
+ * 1. Takes a full file path, splits into directory and file name parts.
40
+ * 2. If the path is already short enough, returns it.
41
+ * 3. Else, calculates tha max allowed file name length, and shortens the file name by replacing the middle part with `...`.
42
+ * 4. Joins back the directory with the shortened file name and returns it.
43
+ *
44
+ * @public
45
+ */
46
+ export declare function limitFilePathLength(filePath: string): string;
47
+ //# sourceMappingURL=FilenameUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilenameUtils.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/FilenameUtils.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD;;;GAGG;AACH,wBAAgB,gBAAgB,WAE/B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,QAEjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAMvE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,UAEnD;AAED;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,UAiBnD"}
@@ -19,30 +19,43 @@ const sanitize_filename_1 = __importDefault(require("sanitize-filename"));
19
19
  const core_backend_1 = require("@itwin/core-backend");
20
20
  const defaultTestOutputDir = (0, os_1.tmpdir)();
21
21
  let testOutputDir;
22
- /** @internal */
22
+ /**
23
+ * Get the output directory used by `setupOutputFileLocation` utility.
24
+ * @public
25
+ */
23
26
  function getTestOutputDir() {
24
27
  return testOutputDir ?? defaultTestOutputDir;
25
28
  }
26
- /** @internal */
29
+ /**
30
+ * Set the output directory used by `setupOutputFileLocation` utility.
31
+ * @public
32
+ */
27
33
  function setTestOutputDir(directoryPath) {
28
34
  testOutputDir = directoryPath;
29
35
  }
30
36
  /**
31
- * Prepare for an output file by:
32
- * - Resolving the output file name under the known test output directory
33
- * - Making directories as necessary
34
- * - Removing a previous copy of the output file
37
+ * Prepare for an output file path by:
38
+ * - Resolving the output file name under the known test output directory (see `getTestOutputDir` & `setTestOutputDir`).
39
+ * - Making sure the output directories exist.
40
+ * - Removing a previous copy of the output file.
41
+ *
35
42
  * @param fileName Name of output file. The actual file name may get modified to fit within the file system limits.
36
- * @internal
43
+ *
44
+ * @public
37
45
  */
38
46
  function setupOutputFileLocation(fileName) {
39
47
  const outputDirectoryPath = getTestOutputDir();
40
48
  !core_backend_1.IModelJsFs.existsSync(outputDirectoryPath) && core_backend_1.IModelJsFs.mkdirSync(outputDirectoryPath);
41
- const outputFilePath = limitFilePathLength(path_1.default.join(outputDirectoryPath, `${fileName}.bim`));
49
+ const outputFilePath = limitFilePathLength(path_1.default.join(outputDirectoryPath, fileName));
42
50
  core_backend_1.IModelJsFs.existsSync(outputFilePath) && core_backend_1.IModelJsFs.unlinkSync(outputFilePath);
43
51
  return outputFilePath;
44
52
  }
45
- /** @internal */
53
+ /**
54
+ * An utility to create a valid file name from any string. Sanitizes all invalid characters,
55
+ * replaces spaces with `-`, makes everything lower case.
56
+ *
57
+ * @public
58
+ */
46
59
  function createFileNameFromString(str) {
47
60
  return (0, sanitize_filename_1.default)(str.replace(/[ ]+/g, "-").replaceAll("`", "").replaceAll("'", "")).toLocaleLowerCase();
48
61
  }
@@ -52,7 +65,16 @@ function createFileNameFromString(str) {
52
65
  * @internal
53
66
  */
54
67
  exports.FILE_PATH_RESERVED_CHARACTERS = 13;
55
- /** @internal */
68
+ /**
69
+ * An utility to make sure file path is shorter than 260 characters.
70
+ *
71
+ * 1. Takes a full file path, splits into directory and file name parts.
72
+ * 2. If the path is already short enough, returns it.
73
+ * 3. Else, calculates tha max allowed file name length, and shortens the file name by replacing the middle part with `...`.
74
+ * 4. Joins back the directory with the shortened file name and returns it.
75
+ *
76
+ * @public
77
+ */
56
78
  function limitFilePathLength(filePath) {
57
79
  const { dir, name, ext } = path_1.default.parse(filePath);
58
80
  const THREE_DOTS_LENGTH = 3;
@@ -68,4 +90,4 @@ function limitFilePathLength(filePath) {
68
90
  const shortenedName = `${name.slice(0, Math.ceil(pieceLength))}...${name.slice(Math.ceil(name.length - pieceLength))}`;
69
91
  return path_1.default.join(dir, `${shortenedName}${ext}`);
70
92
  }
71
- //# sourceMappingURL=InternalUtils.js.map
93
+ //# sourceMappingURL=FilenameUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilenameUtils.js","sourceRoot":"","sources":["../../../src/presentation-testing/FilenameUtils.ts"],"names":[],"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GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,cAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,iBAAiB,GAAG,CAAC,CAAC;IAE5B,IAAI,qBAAqB,GAAG,GAAG,GAAG,qCAA6B,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC;IAChG,IAAI,IAAI,CAAC,MAAM,IAAI,qBAAqB,EAAE,CAAC;QACzC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,qBAAqB,IAAI,iBAAiB,CAAC;IAC3C,IAAI,qBAAqB,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,cAAc,QAAQ,gBAAgB,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,WAAW,GAAG,qBAAqB,GAAG,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC;IACvH,OAAO,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,GAAG,GAAG,EAAE,CAAC,CAAC;AAClD,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\nimport { tmpdir } from \"os\";\nimport path from \"path\";\nimport sanitize from \"sanitize-filename\";\nimport { IModelJsFs } from \"@itwin/core-backend\";\nimport { LocalFileName } from \"@itwin/core-common\";\n\nconst defaultTestOutputDir = tmpdir();\nlet testOutputDir: string | undefined;\n\n/**\n * Get the output directory used by `setupOutputFileLocation` utility.\n * @public\n */\nexport function getTestOutputDir() {\n return testOutputDir ?? defaultTestOutputDir;\n}\n\n/**\n * Set the output directory used by `setupOutputFileLocation` utility.\n * @public\n */\nexport function setTestOutputDir(directoryPath: string | undefined) {\n testOutputDir = directoryPath;\n}\n\n/**\n * Prepare for an output file path by:\n * - Resolving the output file name under the known test output directory (see `getTestOutputDir` & `setTestOutputDir`).\n * - Making sure the output directories exist.\n * - Removing a previous copy of the output file.\n *\n * @param fileName Name of output file. The actual file name may get modified to fit within the file system limits.\n *\n * @public\n */\nexport function setupOutputFileLocation(fileName: string): LocalFileName {\n const outputDirectoryPath = getTestOutputDir();\n !IModelJsFs.existsSync(outputDirectoryPath) && IModelJsFs.mkdirSync(outputDirectoryPath);\n const outputFilePath = limitFilePathLength(path.join(outputDirectoryPath, fileName));\n IModelJsFs.existsSync(outputFilePath) && IModelJsFs.unlinkSync(outputFilePath);\n return outputFilePath;\n}\n\n/**\n * An utility to create a valid file name from any string. Sanitizes all invalid characters,\n * replaces spaces with `-`, makes everything lower case.\n *\n * @public\n */\nexport function createFileNameFromString(str: string) {\n return sanitize(str.replace(/[ ]+/g, \"-\").replaceAll(\"`\", \"\").replaceAll(\"'\", \"\")).toLocaleLowerCase();\n}\n\n/**\n * `itwinjs-core` creates some accompanying files for each iModels and their names are formed by appending\n * a suffix to iModel file name. This constant should account for the maximum suffix length.\n * @internal\n */\nexport const FILE_PATH_RESERVED_CHARACTERS = 13;\n\n/**\n * An utility to make sure file path is shorter than 260 characters.\n *\n * 1. Takes a full file path, splits into directory and file name parts.\n * 2. If the path is already short enough, returns it.\n * 3. Else, calculates tha max allowed file name length, and shortens the file name by replacing the middle part with `...`.\n * 4. Joins back the directory with the shortened file name and returns it.\n *\n * @public\n */\nexport function limitFilePathLength(filePath: string) {\n const { dir, name, ext } = path.parse(filePath);\n const THREE_DOTS_LENGTH = 3;\n\n let allowedFileNameLength = 260 - FILE_PATH_RESERVED_CHARACTERS - (dir.length + 1) - ext.length;\n if (name.length <= allowedFileNameLength) {\n return filePath;\n }\n\n allowedFileNameLength -= THREE_DOTS_LENGTH;\n if (allowedFileNameLength <= 0) {\n throw new Error(`File path \"${filePath}\" is too long.`);\n }\n\n const pieceLength = allowedFileNameLength / 2;\n const shortenedName = `${name.slice(0, Math.ceil(pieceLength))}...${name.slice(Math.ceil(name.length - pieceLength))}`;\n return path.join(dir, `${shortenedName}${ext}`);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,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,EAAE,kBAAkB,EAAuC,wBAAwB,IAAI,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAE5J,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAwBpI,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,CAAC;AAExD,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,CA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eAAO,MAAM,SAAS,mDA0BrB,CAAC"}
@@ -41,22 +41,25 @@ const presentation_backend_1 = require("@itwin/presentation-backend");
41
41
  Object.defineProperty(exports, "HierarchyCacheMode", { enumerable: true, get: function () { return presentation_backend_1.HierarchyCacheMode; } });
42
42
  const presentation_common_1 = require("@itwin/presentation-common");
43
43
  const presentation_frontend_1 = require("@itwin/presentation-frontend");
44
- const InternalUtils_1 = require("./InternalUtils");
44
+ const FilenameUtils_js_1 = require("./FilenameUtils.js");
45
45
  function initializeRpcInterfaces(interfaces) {
46
46
  const config = class extends core_common_1.RpcDefaultConfiguration {
47
47
  interfaces = () => interfaces;
48
48
  };
49
49
  for (const definition of interfaces) {
50
- core_common_1.RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config); // eslint-disable-line @itwin/no-internal
50
+ // eslint-disable-next-line @itwin/no-internal
51
+ core_common_1.RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config);
51
52
  }
52
- const instance = core_common_1.RpcConfiguration.obtain(config); // eslint-disable-line @itwin/no-internal
53
+ const instance = core_common_1.RpcConfiguration.obtain(config);
53
54
  try {
54
- core_common_1.RpcConfiguration.initializeInterfaces(instance); // eslint-disable-line @itwin/no-internal
55
+ core_common_1.RpcConfiguration.initializeInterfaces(instance);
56
+ /* c8 ignore start */
55
57
  }
56
58
  catch {
57
59
  // this may fail with "Error: RPC interface "xxx" is already initialized." because
58
60
  // multiple different tests want to set up rpc interfaces
59
61
  }
62
+ /* c8 ignore end */
60
63
  }
61
64
  let isInitialized = false;
62
65
  /**
@@ -83,7 +86,11 @@ const initialize = async (props) => {
83
86
  if (!props.backendProps.id) {
84
87
  props.backendProps.id = `test-${core_bentley_1.Guid.createValue()}`; // eslint-disable-line @itwin/no-internal
85
88
  }
86
- await core_backend_1.IModelHost.startup({ cacheDir: (0, path_1.join)(__dirname, ".cache"), ...props.backendHostProps });
89
+ await core_backend_1.IModelHost.startup({
90
+ // @ts-ignore TS1343
91
+ cacheDir: (0, path_1.join)(typeof __dirname !== "undefined" ? __dirname : import.meta.url, ".cache", `${process.pid}`),
92
+ ...props.backendHostProps,
93
+ });
87
94
  presentation_backend_1.Presentation.initialize(props.backendProps);
88
95
  // init frontend
89
96
  if (!props.frontendApp) {
@@ -96,7 +103,7 @@ const initialize = async (props) => {
96
103
  },
97
104
  };
98
105
  await presentation_frontend_1.Presentation.initialize({ ...defaultFrontendProps, ...props.frontendProps });
99
- (0, InternalUtils_1.setTestOutputDir)(props.testOutputDir);
106
+ (0, FilenameUtils_js_1.setTestOutputDir)(props.testOutputDir);
100
107
  isInitialized = true;
101
108
  };
102
109
  exports.initialize = initialize;
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+BAA4B;AAC5B,+CAAiC;AACjC,sDAAoE;AACpE,sDAA2C;AAC3C,oDAA2J;AAC3J,wDAAgF;AAChF,sEAA4J;AA0BnJ,mGA1BA,yCAAkB,OA0BA;AAzB3B,oEAAsE;AACtE,wEAAoI;AACpI,mDAAmD;AAEnD,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,MAAM,GAAG,KAAM,SAAQ,qCAAuB;QAClC,UAAU,GAAQ,GAAG,EAAE,CAAC,UAAU,CAAC;KACpD,CAAC;IAEF,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE,CAAC;QACpC,8BAAgB,CAAC,MAAM,CAAC,UAAU,EAAE,0BAA0B,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,yCAAyC;IACzH,CAAC;IAED,MAAM,QAAQ,GAAG,8BAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,yCAAyC;IAE3F,IAAI,CAAC;QACH,8BAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,yCAAyC;IAC5F,CAAC;IAAC,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AAC;SAC1D;KACF,CAAC;IACF,MAAM,oCAAoB,CAAC,UAAU,CAAC,EAAE,GAAG,oBAAoB,EAAE,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAC3F,IAAA,gCAAgB,EAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAEtC,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,CAAC;QACnB,OAAO;IACT,CAAC;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,CAAC;QAC7D,yBAAyB,GAAG,sBAAsB,EAAE,SAAS,CAAC;IAChE,CAAC;SAAM,IAAI,sBAAsB,EAAE,IAAI,KAAK,yCAAkB,CAAC,MAAM,EAAE,CAAC;QACtE,yBAAyB,GAAG,sBAAsB,EAAE,IAAI,EAAE,SAAS,CAAC;IACtE,CAAC;IAED,oBAAoB;IACpB,mCAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,yBAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;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\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 { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps } from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\nimport { setTestOutputDir } from \"./InternalUtils\";\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, /* istanbul ignore next */ () => 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\nexport { HierarchyCacheMode, 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 setTestOutputDir(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,+BAA4B;AAC5B,+CAAiC;AACjC,sDAAoE;AACpE,sDAA2C;AAC3C,oDAA2J;AAC3J,wDAAgF;AAChF,sEAA4J;AA6BnJ,mGA7BA,yCAAkB,OA6BA;AA5B3B,oEAAsE;AACtE,wEAAoI;AACpI,yDAAsD;AAEtD,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,MAAM,GAAG,KAAM,SAAQ,qCAAuB;QAClC,UAAU,GAAQ,GAAG,EAAE,CAAC,UAAU,CAAC;KACpD,CAAC;IAEF,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE,CAAC;QACpC,8CAA8C;QAC9C,8BAAgB,CAAC,MAAM,CAAC,UAAU,EAAE,0BAA0B,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;IAC/E,CAAC;IAED,MAAM,QAAQ,GAAG,8BAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAI,CAAC;QACH,8BAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAChD,qBAAqB;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,kFAAkF;QAClF,yDAAyD;IAC3D,CAAC;IACD,mBAAmB;AACrB,CAAC;AAED,IAAI,aAAa,GAAG,KAAK,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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\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 { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps } from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\nimport { setTestOutputDir } from \"./FilenameUtils.js\";\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 // eslint-disable-next-line @itwin/no-internal\n RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config);\n }\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\n /* c8 ignore start */\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 /* c8 ignore end */\n}\n\nlet isInitialized = false;\n\nexport { HierarchyCacheMode, 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({\n // @ts-ignore TS1343\n cacheDir: join(typeof __dirname !== \"undefined\" ? __dirname : import.meta.url, \".cache\", `${process.pid}`),\n ...props.backendHostProps,\n });\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 setTestOutputDir(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"]}
@@ -4,7 +4,7 @@
4
4
  import { IModelDb } from "@itwin/core-backend";
5
5
  import { Id64String } from "@itwin/core-bentley";
6
6
  import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from "@itwin/core-common";
7
- import { TestIModelBuilder } from "./IModelUtilities";
7
+ import { TestIModelBuilder } from "./IModelUtilities.js";
8
8
  /**
9
9
  * Default implementation of the IModel builder interface.
10
10
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"IModelBuilderImpl.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelBuilderImpl.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAY,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClJ,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,iBAAiB;IAC7D,OAAO,CAAC,OAAO,CAAW;gBAEd,MAAM,EAAE,QAAQ;IAIrB,WAAW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B;QACzC,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACtD,CAAC;CACF;AA/BD,sDA+BC","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 { IModelDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, CodeSpec, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { TestIModelBuilder } from \"./IModelUtilities\";\n\n/**\n * Default implementation of the IModel builder interface.\n * @internal\n */\nexport class TestIModelBuilderImpl 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): Id64String {\n return this._iModel.elements.insertAspect(props);\n }\n\n public insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String {\n return this._iModel.relationships.insertInstance(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 public async importSchema(schemaXml: string) {\n await this._iModel.importSchemaStrings([schemaXml]);\n }\n}\n"]}
1
+ {"version":3,"file":"IModelBuilderImpl.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelBuilderImpl.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAIH,oDAAkJ;AAGlJ;;;GAGG;AACH,MAAa,qBAAqB;IACxB,OAAO,CAAW;IAE1B,YAAY,MAAgB;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAEM,WAAW,CAA4B,KAAa;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAEM,aAAa,CAA8B,KAAa;QAC7D,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAEM,YAAY,CAAoC,KAAa;QAClE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;IAEM,kBAAkB,CAAmC,KAAa;QACvE,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC1D,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,kBAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAChF,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,SAAiB;QACzC,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACtD,CAAC;CACF;AA/BD,sDA+BC","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 { IModelDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, CodeSpec, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { TestIModelBuilder } from \"./IModelUtilities.js\";\n\n/**\n * Default implementation of the IModel builder interface.\n * @internal\n */\nexport class TestIModelBuilderImpl 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): Id64String {\n return this._iModel.elements.insertAspect(props);\n }\n\n public insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String {\n return this._iModel.relationships.insertInstance(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 public async importSchema(schemaXml: string) {\n await this._iModel.importSchemaStrings([schemaXml]);\n }\n}\n"]}
@@ -10,13 +10,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.buildTestIModel = buildTestIModel;
11
11
  const core_backend_1 = require("@itwin/core-backend");
12
12
  const core_frontend_1 = require("@itwin/core-frontend");
13
- const IModelBuilderImpl_1 = require("./IModelBuilderImpl");
14
- const InternalUtils_1 = require("./InternalUtils");
13
+ const FilenameUtils_js_1 = require("./FilenameUtils.js");
14
+ const IModelBuilderImpl_js_1 = require("./IModelBuilderImpl.js");
15
15
  async function buildTestIModel(nameParam, cb) {
16
- const name = typeof nameParam === "string" ? nameParam : (0, InternalUtils_1.createFileNameFromString)(nameParam.test.fullTitle());
17
- const outputFile = (0, InternalUtils_1.setupOutputFileLocation)(name);
16
+ const name = typeof nameParam === "string" ? nameParam : (0, FilenameUtils_js_1.createFileNameFromString)(nameParam.test.fullTitle());
17
+ const outputFile = (0, FilenameUtils_js_1.setupOutputFileLocation)(`${name}.bim`);
18
18
  const db = core_backend_1.SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });
19
- const builder = new IModelBuilderImpl_1.TestIModelBuilderImpl(db);
19
+ const builder = new IModelBuilderImpl_js_1.TestIModelBuilderImpl(db);
20
20
  try {
21
21
  await cb(builder);
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;AAqEH,0CAYC;AA/ED,sDAAiD;AAGjD,wDAA4E;AAC5E,2DAA4D;AAC5D,mDAAoF;AA8D7E,KAAK,UAAU,eAAe,CAAC,SAAiC,EAAE,EAAwD;IAC/H,MAAM,IAAI,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,wCAAwB,EAAC,SAAS,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/G,MAAM,UAAU,GAAG,IAAA,uCAAuB,EAAC,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,yCAAqB,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACtC,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,kCAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACjD,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 { SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\nimport { TestIModelBuilderImpl } from \"./IModelBuilderImpl\";\nimport { createFileNameFromString, setupOutputFileLocation } from \"./InternalUtils\";\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): Id64String;\n /**\n * Insert a relationship between two instances. The relationship is expected to be a subclass\n * of `BisCore:ElementRefersToElements` or `BisCore:ElementDrivesElement`.\n */\n insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String;\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 * Import an ECSchema in a form of XML string into the builder's iModel.\n */\n importSchema(schemaXml: string): Promise<void>;\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 * @deprecated in 4.x. Use an overload with `cb` returning a promise.\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 name Name of test IModel\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(name: string, cb: (builder: TestIModelBuilder) => Promise<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 * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, 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) => Promise<void>): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void | Promise<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 TestIModelBuilderImpl(db);\n try {\n await cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return SnapshotConnection.openFile(outputFile);\n}\n"]}
1
+ {"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;AAqEH,0CAYC;AA/ED,sDAAiD;AAGjD,wDAA4E;AAC5E,yDAAuF;AACvF,iEAA+D;AA8DxD,KAAK,UAAU,eAAe,CAAC,SAAiC,EAAE,EAAwD;IAC/H,MAAM,IAAI,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,2CAAwB,EAAC,SAAS,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/G,MAAM,UAAU,GAAG,IAAA,0CAAuB,EAAC,GAAG,IAAI,MAAM,CAAC,CAAC;IAC1D,MAAM,EAAE,GAAG,yBAAU,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,4CAAqB,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACtC,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,kCAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACjD,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 { SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\nimport { createFileNameFromString, setupOutputFileLocation } from \"./FilenameUtils.js\";\nimport { TestIModelBuilderImpl } from \"./IModelBuilderImpl.js\";\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): Id64String;\n /**\n * Insert a relationship between two instances. The relationship is expected to be a subclass\n * of `BisCore:ElementRefersToElements` or `BisCore:ElementDrivesElement`.\n */\n insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String;\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 * Import an ECSchema in a form of XML string into the builder's iModel.\n */\n importSchema(schemaXml: string): Promise<void>;\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 * @deprecated in 4.x. Use an overload with `cb` returning a promise.\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 name Name of test IModel\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(name: string, cb: (builder: TestIModelBuilder) => Promise<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 * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, 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) => Promise<void>): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void | Promise<void>): Promise<IModelConnection> {\n const name = typeof nameParam === \"string\" ? nameParam : createFileNameFromString(nameParam.test!.fullTitle());\n const outputFile = setupOutputFileLocation(`${name}.bim`);\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\n const builder = new TestIModelBuilderImpl(db);\n try {\n await cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return SnapshotConnection.openFile(outputFile);\n}\n"]}
@@ -5,27 +5,28 @@ import { PresentationManagerMode } from "@itwin/presentation-backend";
5
5
  * @docs-group-description Hierarchies
6
6
  * Types for testing hierarchies.
7
7
  */
8
- export * from "./presentation-testing/HierarchyBuilder";
8
+ export * from "./presentation-testing/HierarchyBuilder.js";
9
9
  /**
10
10
  * @module Content
11
11
  *
12
12
  * @docs-group-description Content
13
13
  * Types for testing content.
14
14
  */
15
- export * from "./presentation-testing/ContentBuilder";
15
+ export * from "./presentation-testing/ContentBuilder.js";
16
16
  /**
17
17
  * @module Helpers
18
18
  *
19
19
  * @docs-group-description Helpers
20
20
  * Various test helpers.
21
21
  */
22
- export * from "./presentation-testing/Helpers";
22
+ export * from "./presentation-testing/Helpers.js";
23
+ export { createFileNameFromString, getTestOutputDir, limitFilePathLength, setTestOutputDir, setupOutputFileLocation, } from "./presentation-testing/FilenameUtils.js";
23
24
  /**
24
25
  * @module IModel
25
26
  *
26
27
  * @docs-group-description IModel
27
28
  * Utilities for creating test iModels that can be used to exercise presentation rules.
28
29
  */
29
- export * from "./presentation-testing/IModelUtilities";
30
+ export * from "./presentation-testing/IModelUtilities.js";
30
31
  export { PresentationManagerMode };
31
32
  //# sourceMappingURL=presentation-testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"presentation-testing.d.ts","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;GAKG;AACH,cAAc,yCAAyC,CAAC;AAExD;;;;;GAKG;AACH,cAAc,uCAAuC,CAAC;AAEtD;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC;AAE/C;;;;;GAKG;AACH,cAAc,wCAAwC,CAAC;AAEvD,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
1
+ {"version":3,"file":"presentation-testing.d.ts","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;GAKG;AACH,cAAc,4CAA4C,CAAC;AAE3D;;;;;GAKG;AACH,cAAc,0CAA0C,CAAC;AAEzD;;;;;GAKG;AACH,cAAc,mCAAmC,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,yCAAyC,CAAC;AAEjD;;;;;GAKG;AACH,cAAc,2CAA2C,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -18,7 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.PresentationManagerMode = void 0;
21
+ exports.PresentationManagerMode = exports.setupOutputFileLocation = exports.setTestOutputDir = exports.limitFilePathLength = exports.getTestOutputDir = exports.createFileNameFromString = void 0;
22
22
  const presentation_backend_1 = require("@itwin/presentation-backend");
23
23
  Object.defineProperty(exports, "PresentationManagerMode", { enumerable: true, get: function () { return presentation_backend_1.PresentationManagerMode; } });
24
24
  /**
@@ -27,26 +27,32 @@ Object.defineProperty(exports, "PresentationManagerMode", { enumerable: true, ge
27
27
  * @docs-group-description Hierarchies
28
28
  * Types for testing hierarchies.
29
29
  */
30
- __exportStar(require("./presentation-testing/HierarchyBuilder"), exports);
30
+ __exportStar(require("./presentation-testing/HierarchyBuilder.js"), exports);
31
31
  /**
32
32
  * @module Content
33
33
  *
34
34
  * @docs-group-description Content
35
35
  * Types for testing content.
36
36
  */
37
- __exportStar(require("./presentation-testing/ContentBuilder"), exports);
37
+ __exportStar(require("./presentation-testing/ContentBuilder.js"), exports);
38
38
  /**
39
39
  * @module Helpers
40
40
  *
41
41
  * @docs-group-description Helpers
42
42
  * Various test helpers.
43
43
  */
44
- __exportStar(require("./presentation-testing/Helpers"), exports);
44
+ __exportStar(require("./presentation-testing/Helpers.js"), exports);
45
+ var FilenameUtils_js_1 = require("./presentation-testing/FilenameUtils.js");
46
+ Object.defineProperty(exports, "createFileNameFromString", { enumerable: true, get: function () { return FilenameUtils_js_1.createFileNameFromString; } });
47
+ Object.defineProperty(exports, "getTestOutputDir", { enumerable: true, get: function () { return FilenameUtils_js_1.getTestOutputDir; } });
48
+ Object.defineProperty(exports, "limitFilePathLength", { enumerable: true, get: function () { return FilenameUtils_js_1.limitFilePathLength; } });
49
+ Object.defineProperty(exports, "setTestOutputDir", { enumerable: true, get: function () { return FilenameUtils_js_1.setTestOutputDir; } });
50
+ Object.defineProperty(exports, "setupOutputFileLocation", { enumerable: true, get: function () { return FilenameUtils_js_1.setupOutputFileLocation; } });
45
51
  /**
46
52
  * @module IModel
47
53
  *
48
54
  * @docs-group-description IModel
49
55
  * Utilities for creating test iModels that can be used to exercise presentation rules.
50
56
  */
51
- __exportStar(require("./presentation-testing/IModelUtilities"), exports);
57
+ __exportStar(require("./presentation-testing/IModelUtilities.js"), exports);
52
58
  //# sourceMappingURL=presentation-testing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;;;;;;;;;;;;;;;AAEhG,sEAAsE;AAkC7D,wGAlCA,8CAAuB,OAkCA;AAhChC;;;;;GAKG;AACH,0EAAwD;AAExD;;;;;GAKG;AACH,wEAAsD;AAEtD;;;;;GAKG;AACH,iEAA+C;AAE/C;;;;;GAKG;AACH,yEAAuD","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\nimport { PresentationManagerMode } from \"@itwin/presentation-backend\";\n\n/**\n * @module Hierarchies\n *\n * @docs-group-description Hierarchies\n * Types for testing hierarchies.\n */\nexport * from \"./presentation-testing/HierarchyBuilder\";\n\n/**\n * @module Content\n *\n * @docs-group-description Content\n * Types for testing content.\n */\nexport * from \"./presentation-testing/ContentBuilder\";\n\n/**\n * @module Helpers\n *\n * @docs-group-description Helpers\n * Various test helpers.\n */\nexport * from \"./presentation-testing/Helpers\";\n\n/**\n * @module IModel\n *\n * @docs-group-description IModel\n * Utilities for creating test iModels that can be used to exercise presentation rules.\n */\nexport * from \"./presentation-testing/IModelUtilities\";\n\nexport { PresentationManagerMode }; // eslint-disable-line deprecation/deprecation\n"]}
1
+ {"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;;;;;;;;;;;;;;;AAEhG,sEAAsE;AAyC7D,wGAzCA,8CAAuB,OAyCA;AAvChC;;;;;GAKG;AACH,6EAA2D;AAE3D;;;;;GAKG;AACH,2EAAyD;AAEzD;;;;;GAKG;AACH,oEAAkD;AAClD,4EAMiD;AAL/C,4HAAA,wBAAwB,OAAA;AACxB,oHAAA,gBAAgB,OAAA;AAChB,uHAAA,mBAAmB,OAAA;AACnB,oHAAA,gBAAgB,OAAA;AAChB,2HAAA,uBAAuB,OAAA;AAGzB;;;;;GAKG;AACH,4EAA0D","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\nimport { PresentationManagerMode } from \"@itwin/presentation-backend\";\n\n/**\n * @module Hierarchies\n *\n * @docs-group-description Hierarchies\n * Types for testing hierarchies.\n */\nexport * from \"./presentation-testing/HierarchyBuilder.js\";\n\n/**\n * @module Content\n *\n * @docs-group-description Content\n * Types for testing content.\n */\nexport * from \"./presentation-testing/ContentBuilder.js\";\n\n/**\n * @module Helpers\n *\n * @docs-group-description Helpers\n * Various test helpers.\n */\nexport * from \"./presentation-testing/Helpers.js\";\nexport {\n createFileNameFromString,\n getTestOutputDir,\n limitFilePathLength,\n setTestOutputDir,\n setupOutputFileLocation,\n} from \"./presentation-testing/FilenameUtils.js\";\n\n/**\n * @module IModel\n *\n * @docs-group-description IModel\n * Utilities for creating test iModels that can be used to exercise presentation rules.\n */\nexport * from \"./presentation-testing/IModelUtilities.js\";\n\nexport { PresentationManagerMode };\n"]}
@@ -0,0 +1,47 @@
1
+ import { LocalFileName } from "@itwin/core-common";
2
+ /**
3
+ * Get the output directory used by `setupOutputFileLocation` utility.
4
+ * @public
5
+ */
6
+ export declare function getTestOutputDir(): string;
7
+ /**
8
+ * Set the output directory used by `setupOutputFileLocation` utility.
9
+ * @public
10
+ */
11
+ export declare function setTestOutputDir(directoryPath: string | undefined): void;
12
+ /**
13
+ * Prepare for an output file path by:
14
+ * - Resolving the output file name under the known test output directory (see `getTestOutputDir` & `setTestOutputDir`).
15
+ * - Making sure the output directories exist.
16
+ * - Removing a previous copy of the output file.
17
+ *
18
+ * @param fileName Name of output file. The actual file name may get modified to fit within the file system limits.
19
+ *
20
+ * @public
21
+ */
22
+ export declare function setupOutputFileLocation(fileName: string): LocalFileName;
23
+ /**
24
+ * An utility to create a valid file name from any string. Sanitizes all invalid characters,
25
+ * replaces spaces with `-`, makes everything lower case.
26
+ *
27
+ * @public
28
+ */
29
+ export declare function createFileNameFromString(str: string): string;
30
+ /**
31
+ * `itwinjs-core` creates some accompanying files for each iModels and their names are formed by appending
32
+ * a suffix to iModel file name. This constant should account for the maximum suffix length.
33
+ * @internal
34
+ */
35
+ export declare const FILE_PATH_RESERVED_CHARACTERS = 13;
36
+ /**
37
+ * An utility to make sure file path is shorter than 260 characters.
38
+ *
39
+ * 1. Takes a full file path, splits into directory and file name parts.
40
+ * 2. If the path is already short enough, returns it.
41
+ * 3. Else, calculates tha max allowed file name length, and shortens the file name by replacing the middle part with `...`.
42
+ * 4. Joins back the directory with the shortened file name and returns it.
43
+ *
44
+ * @public
45
+ */
46
+ export declare function limitFilePathLength(filePath: string): string;
47
+ //# sourceMappingURL=FilenameUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilenameUtils.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/FilenameUtils.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD;;;GAGG;AACH,wBAAgB,gBAAgB,WAE/B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,QAEjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAMvE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,UAEnD;AAED;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,UAiBnD"}
@@ -8,30 +8,43 @@ import sanitize from "sanitize-filename";
8
8
  import { IModelJsFs } from "@itwin/core-backend";
9
9
  const defaultTestOutputDir = tmpdir();
10
10
  let testOutputDir;
11
- /** @internal */
11
+ /**
12
+ * Get the output directory used by `setupOutputFileLocation` utility.
13
+ * @public
14
+ */
12
15
  export function getTestOutputDir() {
13
16
  return testOutputDir ?? defaultTestOutputDir;
14
17
  }
15
- /** @internal */
18
+ /**
19
+ * Set the output directory used by `setupOutputFileLocation` utility.
20
+ * @public
21
+ */
16
22
  export function setTestOutputDir(directoryPath) {
17
23
  testOutputDir = directoryPath;
18
24
  }
19
25
  /**
20
- * Prepare for an output file by:
21
- * - Resolving the output file name under the known test output directory
22
- * - Making directories as necessary
23
- * - Removing a previous copy of the output file
26
+ * Prepare for an output file path by:
27
+ * - Resolving the output file name under the known test output directory (see `getTestOutputDir` & `setTestOutputDir`).
28
+ * - Making sure the output directories exist.
29
+ * - Removing a previous copy of the output file.
30
+ *
24
31
  * @param fileName Name of output file. The actual file name may get modified to fit within the file system limits.
25
- * @internal
32
+ *
33
+ * @public
26
34
  */
27
35
  export function setupOutputFileLocation(fileName) {
28
36
  const outputDirectoryPath = getTestOutputDir();
29
37
  !IModelJsFs.existsSync(outputDirectoryPath) && IModelJsFs.mkdirSync(outputDirectoryPath);
30
- const outputFilePath = limitFilePathLength(path.join(outputDirectoryPath, `${fileName}.bim`));
38
+ const outputFilePath = limitFilePathLength(path.join(outputDirectoryPath, fileName));
31
39
  IModelJsFs.existsSync(outputFilePath) && IModelJsFs.unlinkSync(outputFilePath);
32
40
  return outputFilePath;
33
41
  }
34
- /** @internal */
42
+ /**
43
+ * An utility to create a valid file name from any string. Sanitizes all invalid characters,
44
+ * replaces spaces with `-`, makes everything lower case.
45
+ *
46
+ * @public
47
+ */
35
48
  export function createFileNameFromString(str) {
36
49
  return sanitize(str.replace(/[ ]+/g, "-").replaceAll("`", "").replaceAll("'", "")).toLocaleLowerCase();
37
50
  }
@@ -41,7 +54,16 @@ export function createFileNameFromString(str) {
41
54
  * @internal
42
55
  */
43
56
  export const FILE_PATH_RESERVED_CHARACTERS = 13;
44
- /** @internal */
57
+ /**
58
+ * An utility to make sure file path is shorter than 260 characters.
59
+ *
60
+ * 1. Takes a full file path, splits into directory and file name parts.
61
+ * 2. If the path is already short enough, returns it.
62
+ * 3. Else, calculates tha max allowed file name length, and shortens the file name by replacing the middle part with `...`.
63
+ * 4. Joins back the directory with the shortened file name and returns it.
64
+ *
65
+ * @public
66
+ */
45
67
  export function limitFilePathLength(filePath) {
46
68
  const { dir, name, ext } = path.parse(filePath);
47
69
  const THREE_DOTS_LENGTH = 3;
@@ -57,4 +79,4 @@ export function limitFilePathLength(filePath) {
57
79
  const shortenedName = `${name.slice(0, Math.ceil(pieceLength))}...${name.slice(Math.ceil(name.length - pieceLength))}`;
58
80
  return path.join(dir, `${shortenedName}${ext}`);
59
81
  }
60
- //# sourceMappingURL=InternalUtils.js.map
82
+ //# sourceMappingURL=FilenameUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilenameUtils.js","sourceRoot":"","sources":["../../../src/presentation-testing/FilenameUtils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,MAAM,oBAAoB,GAAG,MAAM,EAAE,CAAC;AACtC,IAAI,aAAiC,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,aAAa,IAAI,oBAAoB,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,aAAiC;IAChE,aAAa,GAAG,aAAa,CAAC;AAChC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAgB;IACtD,MAAM,mBAAmB,GAAG,gBAAgB,EAAE,CAAC;IAC/C,CAAC,UAAU,CAAC,UAAU,CAAC,mBAAmB,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IACzF,MAAM,cAAc,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,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AAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC;IACvH,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,GAAG,GAAG,EAAE,CAAC,CAAC;AAClD,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\nimport { tmpdir } from \"os\";\nimport path from \"path\";\nimport sanitize from \"sanitize-filename\";\nimport { IModelJsFs } from \"@itwin/core-backend\";\nimport { LocalFileName } from \"@itwin/core-common\";\n\nconst defaultTestOutputDir = tmpdir();\nlet testOutputDir: string | undefined;\n\n/**\n * Get the output directory used by `setupOutputFileLocation` utility.\n * @public\n */\nexport function getTestOutputDir() {\n return testOutputDir ?? defaultTestOutputDir;\n}\n\n/**\n * Set the output directory used by `setupOutputFileLocation` utility.\n * @public\n */\nexport function setTestOutputDir(directoryPath: string | undefined) {\n testOutputDir = directoryPath;\n}\n\n/**\n * Prepare for an output file path by:\n * - Resolving the output file name under the known test output directory (see `getTestOutputDir` & `setTestOutputDir`).\n * - Making sure the output directories exist.\n * - Removing a previous copy of the output file.\n *\n * @param fileName Name of output file. The actual file name may get modified to fit within the file system limits.\n *\n * @public\n */\nexport function setupOutputFileLocation(fileName: string): LocalFileName {\n const outputDirectoryPath = getTestOutputDir();\n !IModelJsFs.existsSync(outputDirectoryPath) && IModelJsFs.mkdirSync(outputDirectoryPath);\n const outputFilePath = limitFilePathLength(path.join(outputDirectoryPath, fileName));\n IModelJsFs.existsSync(outputFilePath) && IModelJsFs.unlinkSync(outputFilePath);\n return outputFilePath;\n}\n\n/**\n * An utility to create a valid file name from any string. Sanitizes all invalid characters,\n * replaces spaces with `-`, makes everything lower case.\n *\n * @public\n */\nexport function createFileNameFromString(str: string) {\n return sanitize(str.replace(/[ ]+/g, \"-\").replaceAll(\"`\", \"\").replaceAll(\"'\", \"\")).toLocaleLowerCase();\n}\n\n/**\n * `itwinjs-core` creates some accompanying files for each iModels and their names are formed by appending\n * a suffix to iModel file name. This constant should account for the maximum suffix length.\n * @internal\n */\nexport const FILE_PATH_RESERVED_CHARACTERS = 13;\n\n/**\n * An utility to make sure file path is shorter than 260 characters.\n *\n * 1. Takes a full file path, splits into directory and file name parts.\n * 2. If the path is already short enough, returns it.\n * 3. Else, calculates tha max allowed file name length, and shortens the file name by replacing the middle part with `...`.\n * 4. Joins back the directory with the shortened file name and returns it.\n *\n * @public\n */\nexport function limitFilePathLength(filePath: string) {\n const { dir, name, ext } = path.parse(filePath);\n const THREE_DOTS_LENGTH = 3;\n\n let allowedFileNameLength = 260 - FILE_PATH_RESERVED_CHARACTERS - (dir.length + 1) - ext.length;\n if (name.length <= allowedFileNameLength) {\n return filePath;\n }\n\n allowedFileNameLength -= THREE_DOTS_LENGTH;\n if (allowedFileNameLength <= 0) {\n throw new Error(`File path \"${filePath}\" is too long.`);\n }\n\n const pieceLength = allowedFileNameLength / 2;\n const shortenedName = `${name.slice(0, Math.ceil(pieceLength))}...${name.slice(Math.ceil(name.length - pieceLength))}`;\n return path.join(dir, `${shortenedName}${ext}`);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,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,EAAE,kBAAkB,EAAuC,wBAAwB,IAAI,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAE5J,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BA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C3C;;;;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,kBAwCpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDA0BrB,CAAC"}
@@ -14,22 +14,25 @@ import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
14
14
  import { HierarchyCacheMode, Presentation as PresentationBackend } from "@itwin/presentation-backend";
15
15
  import { PresentationRpcInterface } from "@itwin/presentation-common";
16
16
  import { Presentation as PresentationFrontend } from "@itwin/presentation-frontend";
17
- import { setTestOutputDir } from "./InternalUtils";
17
+ import { setTestOutputDir } from "./FilenameUtils.js";
18
18
  function initializeRpcInterfaces(interfaces) {
19
19
  const config = class extends RpcDefaultConfiguration {
20
20
  interfaces = () => interfaces;
21
21
  };
22
22
  for (const definition of interfaces) {
23
- RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config); // eslint-disable-line @itwin/no-internal
23
+ // eslint-disable-next-line @itwin/no-internal
24
+ RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config);
24
25
  }
25
- const instance = RpcConfiguration.obtain(config); // eslint-disable-line @itwin/no-internal
26
+ const instance = RpcConfiguration.obtain(config);
26
27
  try {
27
- RpcConfiguration.initializeInterfaces(instance); // eslint-disable-line @itwin/no-internal
28
+ RpcConfiguration.initializeInterfaces(instance);
29
+ /* c8 ignore start */
28
30
  }
29
31
  catch {
30
32
  // this may fail with "Error: RPC interface "xxx" is already initialized." because
31
33
  // multiple different tests want to set up rpc interfaces
32
34
  }
35
+ /* c8 ignore end */
33
36
  }
34
37
  let isInitialized = false;
35
38
  export { HierarchyCacheMode };
@@ -57,7 +60,11 @@ export const initialize = async (props) => {
57
60
  if (!props.backendProps.id) {
58
61
  props.backendProps.id = `test-${Guid.createValue()}`; // eslint-disable-line @itwin/no-internal
59
62
  }
60
- await IModelHost.startup({ cacheDir: join(__dirname, ".cache"), ...props.backendHostProps });
63
+ await IModelHost.startup({
64
+ // @ts-ignore TS1343
65
+ cacheDir: join(typeof __dirname !== "undefined" ? __dirname : import.meta.url, ".cache", `${process.pid}`),
66
+ ...props.backendHostProps,
67
+ });
61
68
  PresentationBackend.initialize(props.backendProps);
62
69
  // init frontend
63
70
  if (!props.frontendApp) {
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,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,EAAE,kBAAkB,EAAE,YAAY,IAAI,mBAAmB,EAAwD,MAAM,6BAA6B,CAAC;AAC5J,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC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AAC;QAC7D,yBAAyB,GAAG,sBAAsB,EAAE,SAAS,CAAC;IAChE,CAAC;SAAM,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;QACtE,yBAAyB,GAAG,sBAAsB,EAAE,IAAI,EAAE,SAAS,CAAC;IACtE,CAAC;IAED,oBAAoB;IACpB,mBAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;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\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 { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps } from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\nimport { setTestOutputDir } from \"./InternalUtils\";\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, /* istanbul ignore next */ () => 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\nexport { HierarchyCacheMode, 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 setTestOutputDir(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,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;A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C3F,gBAAgB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAEtC,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,WAAW,GAAG,SAAS,EAAE,EAAE;IACzD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IAED,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,CAAC;QAC7D,yBAAyB,GAAG,sBAAsB,EAAE,SAAS,CAAC;IAChE,CAAC;SAAM,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;QACtE,yBAAyB,GAAG,sBAAsB,EAAE,IAAI,EAAE,SAAS,CAAC;IACtE,CAAC;IAED,oBAAoB;IACpB,mBAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;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\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 { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps } from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\nimport { setTestOutputDir } from \"./FilenameUtils.js\";\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 // eslint-disable-next-line @itwin/no-internal\n RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config);\n }\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\n /* c8 ignore start */\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 /* c8 ignore end */\n}\n\nlet isInitialized = false;\n\nexport { HierarchyCacheMode, 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({\n // @ts-ignore TS1343\n cacheDir: join(typeof __dirname !== \"undefined\" ? __dirname : import.meta.url, \".cache\", `${process.pid}`),\n ...props.backendHostProps,\n });\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 setTestOutputDir(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"]}
@@ -4,7 +4,7 @@
4
4
  import { IModelDb } from "@itwin/core-backend";
5
5
  import { Id64String } from "@itwin/core-bentley";
6
6
  import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from "@itwin/core-common";
7
- import { TestIModelBuilder } from "./IModelUtilities";
7
+ import { TestIModelBuilder } from "./IModelUtilities.js";
8
8
  /**
9
9
  * Default implementation of the IModel builder interface.
10
10
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"IModelBuilderImpl.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelBuilderImpl.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAY,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClJ,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,iBAAiB;IAC7D,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,UAAU;IAI1E,kBAAkB,CAAC,MAAM,SAAS,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU;IAI/E,UAAU,CAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAKtF,YAAY,CAAC,SAAS,EAAE,MAAM;CAG5C"}
1
+ {"version":3,"file":"IModelBuilderImpl.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelBuilderImpl.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAY,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClJ,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,iBAAiB;IAC7D,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,UAAU;IAI1E,kBAAkB,CAAC,MAAM,SAAS,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU;IAI/E,UAAU,CAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAKtF,YAAY,CAAC,SAAS,EAAE,MAAM;CAG5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"IModelBuilderImpl.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelBuilderImpl.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAIH,OAAO,EAAe,IAAI,EAA6F,MAAM,oBAAoB,CAAC;AAGlJ;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IACxB,OAAO,CAAW;IAE1B,YAAY,MAAgB;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAEM,WAAW,CAA4B,KAAa;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAEM,aAAa,CAA8B,KAAa;QAC7D,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAEM,YAAY,CAAoC,KAAa;QAClE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;IAEM,kBAAkB,CAAmC,KAAa;QACvE,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC1D,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;IAEM,KAAK,CAAC,YAAY,CAAC,SAAiB;QACzC,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACtD,CAAC;CACF","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 { IModelDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, CodeSpec, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { TestIModelBuilder } from \"./IModelUtilities\";\n\n/**\n * Default implementation of the IModel builder interface.\n * @internal\n */\nexport class TestIModelBuilderImpl 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): Id64String {\n return this._iModel.elements.insertAspect(props);\n }\n\n public insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String {\n return this._iModel.relationships.insertInstance(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 public async importSchema(schemaXml: string) {\n await this._iModel.importSchemaStrings([schemaXml]);\n }\n}\n"]}
1
+ {"version":3,"file":"IModelBuilderImpl.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelBuilderImpl.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAIH,OAAO,EAAe,IAAI,EAA6F,MAAM,oBAAoB,CAAC;AAGlJ;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IACxB,OAAO,CAAW;IAE1B,YAAY,MAAgB;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAEM,WAAW,CAA4B,KAAa;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAEM,aAAa,CAA8B,KAAa;QAC7D,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAEM,YAAY,CAAoC,KAAa;QAClE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;IAEM,kBAAkB,CAAmC,KAAa;QACvE,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC1D,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;IAEM,KAAK,CAAC,YAAY,CAAC,SAAiB;QACzC,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACtD,CAAC;CACF","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 { IModelDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, CodeSpec, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { TestIModelBuilder } from \"./IModelUtilities.js\";\n\n/**\n * Default implementation of the IModel builder interface.\n * @internal\n */\nexport class TestIModelBuilderImpl 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): Id64String {\n return this._iModel.elements.insertAspect(props);\n }\n\n public insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String {\n return this._iModel.relationships.insertInstance(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 public async importSchema(schemaXml: string) {\n await this._iModel.importSchemaStrings([schemaXml]);\n }\n}\n"]}
@@ -7,11 +7,11 @@
7
7
  */
8
8
  import { SnapshotDb } from "@itwin/core-backend";
9
9
  import { SnapshotConnection } from "@itwin/core-frontend";
10
- import { TestIModelBuilderImpl } from "./IModelBuilderImpl";
11
- import { createFileNameFromString, setupOutputFileLocation } from "./InternalUtils";
10
+ import { createFileNameFromString, setupOutputFileLocation } from "./FilenameUtils.js";
11
+ import { TestIModelBuilderImpl } from "./IModelBuilderImpl.js";
12
12
  export async function buildTestIModel(nameParam, cb) {
13
13
  const name = typeof nameParam === "string" ? nameParam : createFileNameFromString(nameParam.test.fullTitle());
14
- const outputFile = setupOutputFileLocation(name);
14
+ const outputFile = setupOutputFileLocation(`${name}.bim`);
15
15
  const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });
16
16
  const builder = new TestIModelBuilderImpl(db);
17
17
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,OAAO,EAAoB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AA8DpF,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,SAAiC,EAAE,EAAwD;IAC/H,MAAM,IAAI,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,wBAAwB,CAAC,SAAS,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/G,MAAM,UAAU,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IACjD,MAAM,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACtC,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACjD,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 { SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\nimport { TestIModelBuilderImpl } from \"./IModelBuilderImpl\";\nimport { createFileNameFromString, setupOutputFileLocation } from \"./InternalUtils\";\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): Id64String;\n /**\n * Insert a relationship between two instances. The relationship is expected to be a subclass\n * of `BisCore:ElementRefersToElements` or `BisCore:ElementDrivesElement`.\n */\n insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String;\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 * Import an ECSchema in a form of XML string into the builder's iModel.\n */\n importSchema(schemaXml: string): Promise<void>;\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 * @deprecated in 4.x. Use an overload with `cb` returning a promise.\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 name Name of test IModel\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(name: string, cb: (builder: TestIModelBuilder) => Promise<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 * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, 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) => Promise<void>): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void | Promise<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 TestIModelBuilderImpl(db);\n try {\n await cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return SnapshotConnection.openFile(outputFile);\n}\n"]}
1
+ {"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,OAAO,EAAoB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AA8D/D,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,SAAiC,EAAE,EAAwD;IAC/H,MAAM,IAAI,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,wBAAwB,CAAC,SAAS,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/G,MAAM,UAAU,GAAG,uBAAuB,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC;IAC1D,MAAM,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACtC,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACjD,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 { SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\nimport { createFileNameFromString, setupOutputFileLocation } from \"./FilenameUtils.js\";\nimport { TestIModelBuilderImpl } from \"./IModelBuilderImpl.js\";\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): Id64String;\n /**\n * Insert a relationship between two instances. The relationship is expected to be a subclass\n * of `BisCore:ElementRefersToElements` or `BisCore:ElementDrivesElement`.\n */\n insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String;\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 * Import an ECSchema in a form of XML string into the builder's iModel.\n */\n importSchema(schemaXml: string): Promise<void>;\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 * @deprecated in 4.x. Use an overload with `cb` returning a promise.\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 name Name of test IModel\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(name: string, cb: (builder: TestIModelBuilder) => Promise<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 * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, 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) => Promise<void>): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void | Promise<void>): Promise<IModelConnection> {\n const name = typeof nameParam === \"string\" ? nameParam : createFileNameFromString(nameParam.test!.fullTitle());\n const outputFile = setupOutputFileLocation(`${name}.bim`);\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\n const builder = new TestIModelBuilderImpl(db);\n try {\n await cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return SnapshotConnection.openFile(outputFile);\n}\n"]}
@@ -5,27 +5,28 @@ import { PresentationManagerMode } from "@itwin/presentation-backend";
5
5
  * @docs-group-description Hierarchies
6
6
  * Types for testing hierarchies.
7
7
  */
8
- export * from "./presentation-testing/HierarchyBuilder";
8
+ export * from "./presentation-testing/HierarchyBuilder.js";
9
9
  /**
10
10
  * @module Content
11
11
  *
12
12
  * @docs-group-description Content
13
13
  * Types for testing content.
14
14
  */
15
- export * from "./presentation-testing/ContentBuilder";
15
+ export * from "./presentation-testing/ContentBuilder.js";
16
16
  /**
17
17
  * @module Helpers
18
18
  *
19
19
  * @docs-group-description Helpers
20
20
  * Various test helpers.
21
21
  */
22
- export * from "./presentation-testing/Helpers";
22
+ export * from "./presentation-testing/Helpers.js";
23
+ export { createFileNameFromString, getTestOutputDir, limitFilePathLength, setTestOutputDir, setupOutputFileLocation, } from "./presentation-testing/FilenameUtils.js";
23
24
  /**
24
25
  * @module IModel
25
26
  *
26
27
  * @docs-group-description IModel
27
28
  * Utilities for creating test iModels that can be used to exercise presentation rules.
28
29
  */
29
- export * from "./presentation-testing/IModelUtilities";
30
+ export * from "./presentation-testing/IModelUtilities.js";
30
31
  export { PresentationManagerMode };
31
32
  //# sourceMappingURL=presentation-testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"presentation-testing.d.ts","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;GAKG;AACH,cAAc,yCAAyC,CAAC;AAExD;;;;;GAKG;AACH,cAAc,uCAAuC,CAAC;AAEtD;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC;AAE/C;;;;;GAKG;AACH,cAAc,wCAAwC,CAAC;AAEvD,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
1
+ {"version":3,"file":"presentation-testing.d.ts","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;GAKG;AACH,cAAc,4CAA4C,CAAC;AAE3D;;;;;GAKG;AACH,cAAc,0CAA0C,CAAC;AAEzD;;;;;GAKG;AACH,cAAc,mCAAmC,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,yCAAyC,CAAC;AAEjD;;;;;GAKG;AACH,cAAc,2CAA2C,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -9,27 +9,28 @@ import { PresentationManagerMode } from "@itwin/presentation-backend";
9
9
  * @docs-group-description Hierarchies
10
10
  * Types for testing hierarchies.
11
11
  */
12
- export * from "./presentation-testing/HierarchyBuilder";
12
+ export * from "./presentation-testing/HierarchyBuilder.js";
13
13
  /**
14
14
  * @module Content
15
15
  *
16
16
  * @docs-group-description Content
17
17
  * Types for testing content.
18
18
  */
19
- export * from "./presentation-testing/ContentBuilder";
19
+ export * from "./presentation-testing/ContentBuilder.js";
20
20
  /**
21
21
  * @module Helpers
22
22
  *
23
23
  * @docs-group-description Helpers
24
24
  * Various test helpers.
25
25
  */
26
- export * from "./presentation-testing/Helpers";
26
+ export * from "./presentation-testing/Helpers.js";
27
+ export { createFileNameFromString, getTestOutputDir, limitFilePathLength, setTestOutputDir, setupOutputFileLocation, } from "./presentation-testing/FilenameUtils.js";
27
28
  /**
28
29
  * @module IModel
29
30
  *
30
31
  * @docs-group-description IModel
31
32
  * Utilities for creating test iModels that can be used to exercise presentation rules.
32
33
  */
33
- export * from "./presentation-testing/IModelUtilities";
34
- export { PresentationManagerMode }; // eslint-disable-line deprecation/deprecation
34
+ export * from "./presentation-testing/IModelUtilities.js";
35
+ export { PresentationManagerMode };
35
36
  //# sourceMappingURL=presentation-testing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;GAKG;AACH,cAAc,yCAAyC,CAAC;AAExD;;;;;GAKG;AACH,cAAc,uCAAuC,CAAC;AAEtD;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC;AAE/C;;;;;GAKG;AACH,cAAc,wCAAwC,CAAC;AAEvD,OAAO,EAAE,uBAAuB,EAAE,CAAC,CAAC,8CAA8C","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\nimport { PresentationManagerMode } from \"@itwin/presentation-backend\";\n\n/**\n * @module Hierarchies\n *\n * @docs-group-description Hierarchies\n * Types for testing hierarchies.\n */\nexport * from \"./presentation-testing/HierarchyBuilder\";\n\n/**\n * @module Content\n *\n * @docs-group-description Content\n * Types for testing content.\n */\nexport * from \"./presentation-testing/ContentBuilder\";\n\n/**\n * @module Helpers\n *\n * @docs-group-description Helpers\n * Various test helpers.\n */\nexport * from \"./presentation-testing/Helpers\";\n\n/**\n * @module IModel\n *\n * @docs-group-description IModel\n * Utilities for creating test iModels that can be used to exercise presentation rules.\n */\nexport * from \"./presentation-testing/IModelUtilities\";\n\nexport { PresentationManagerMode }; // eslint-disable-line deprecation/deprecation\n"]}
1
+ {"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;GAKG;AACH,cAAc,4CAA4C,CAAC;AAE3D;;;;;GAKG;AACH,cAAc,0CAA0C,CAAC;AAEzD;;;;;GAKG;AACH,cAAc,mCAAmC,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,yCAAyC,CAAC;AAEjD;;;;;GAKG;AACH,cAAc,2CAA2C,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,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\nimport { PresentationManagerMode } from \"@itwin/presentation-backend\";\n\n/**\n * @module Hierarchies\n *\n * @docs-group-description Hierarchies\n * Types for testing hierarchies.\n */\nexport * from \"./presentation-testing/HierarchyBuilder.js\";\n\n/**\n * @module Content\n *\n * @docs-group-description Content\n * Types for testing content.\n */\nexport * from \"./presentation-testing/ContentBuilder.js\";\n\n/**\n * @module Helpers\n *\n * @docs-group-description Helpers\n * Various test helpers.\n */\nexport * from \"./presentation-testing/Helpers.js\";\nexport {\n createFileNameFromString,\n getTestOutputDir,\n limitFilePathLength,\n setTestOutputDir,\n setupOutputFileLocation,\n} from \"./presentation-testing/FilenameUtils.js\";\n\n/**\n * @module IModel\n *\n * @docs-group-description IModel\n * Utilities for creating test iModels that can be used to exercise presentation rules.\n */\nexport * from \"./presentation-testing/IModelUtilities.js\";\n\nexport { PresentationManagerMode };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/presentation-testing",
3
- "version": "5.0.16",
3
+ "version": "5.1.0",
4
4
  "description": "Testing utilities for iTwin.js Presentation library",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -18,13 +18,21 @@
18
18
  "name": "Bentley Systems, Inc.",
19
19
  "url": "http://www.bentley.com"
20
20
  },
21
+ "type": "module",
21
22
  "main": "lib/cjs/presentation-testing.js",
23
+ "types": "lib/cjs/presentation-testing",
22
24
  "module": "lib/esm/presentation-testing.js",
23
- "types": "lib/cjs/presentation-testing.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "import": "./lib/esm/presentation-testing.js",
28
+ "require": "./lib/cjs/presentation-testing.js"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
24
32
  "dependencies": {
25
33
  "rimraf": "^6.0.1",
26
34
  "sanitize-filename": "^1.6.3",
27
- "@itwin/presentation-components": "^5.4.2"
35
+ "@itwin/presentation-components": "^5.6.0"
28
36
  },
29
37
  "peerDependencies": {
30
38
  "@itwin/appui-abstract": "^4.1.0",
@@ -38,23 +46,23 @@
38
46
  "@itwin/presentation-frontend": "^4.1.0"
39
47
  },
40
48
  "devDependencies": {
41
- "@itwin/appui-abstract": "^4.8.0",
42
- "@itwin/build-tools": "^4.8.0",
43
- "@itwin/components-react": "^4.16.0",
44
- "@itwin/core-backend": "^4.8.0",
45
- "@itwin/core-bentley": "^4.8.0",
46
- "@itwin/core-common": "^4.8.0",
47
- "@itwin/core-frontend": "^4.8.0",
48
- "@itwin/core-geometry": "^4.8.0",
49
- "@itwin/core-orbitgt": "^4.8.0",
50
- "@itwin/core-quantity": "^4.8.0",
51
- "@itwin/core-react": "^4.16.0",
52
- "@itwin/ecschema-metadata": "^4.8.0",
53
- "@itwin/eslint-plugin": "^4.1.1",
54
- "@itwin/presentation-backend": "^4.8.0",
55
- "@itwin/presentation-common": "^4.8.0",
56
- "@itwin/presentation-frontend": "^4.8.0",
57
- "@itwin/webgl-compatibility": "^4.8.0",
49
+ "@itwin/appui-abstract": "^4.9.0",
50
+ "@itwin/build-tools": "^4.10.0-dev.33",
51
+ "@itwin/components-react": "^4.17.0",
52
+ "@itwin/core-backend": "^4.9.0",
53
+ "@itwin/core-bentley": "^4.9.0",
54
+ "@itwin/core-common": "^4.9.0",
55
+ "@itwin/core-frontend": "^4.9.0",
56
+ "@itwin/core-geometry": "^4.9.0",
57
+ "@itwin/core-orbitgt": "^4.9.0",
58
+ "@itwin/core-quantity": "^4.9.0",
59
+ "@itwin/core-react": "^4.17.0",
60
+ "@itwin/ecschema-metadata": "^4.9.0",
61
+ "@itwin/eslint-plugin": "5.0.0-dev.1",
62
+ "@itwin/presentation-backend": "^4.9.0",
63
+ "@itwin/presentation-common": "^4.9.0",
64
+ "@itwin/presentation-frontend": "^4.9.0",
65
+ "@itwin/webgl-compatibility": "^4.9.0",
58
66
  "@opentelemetry/api": "^1.8.0",
59
67
  "@types/chai": "^4.3.16",
60
68
  "@types/chai-as-promised": "^7.1.8",
@@ -63,39 +71,40 @@
63
71
  "@types/node": "^20.12.12",
64
72
  "@types/sinon": "^17.0.3",
65
73
  "@types/sinon-chai": "^3.2.12",
74
+ "c8": "^10.1.2",
66
75
  "chai": "^4.4.1",
67
76
  "chai-as-promised": "^7.1.2",
68
77
  "chai-jest-snapshot": "^2.0.0",
69
78
  "cpx2": "^7.0.1",
70
79
  "cross-env": "^7.0.3",
71
- "eslint": "^8.57.0",
72
- "global-jsdom": "^24.0.0",
80
+ "eslint": "^9.13.0",
81
+ "global-jsdom": "^25.0.0",
73
82
  "ignore-styles": "^5.0.1",
74
83
  "inversify": "^6.0.2",
75
- "jsdom": "^24.1.0",
76
- "mocha": "^10.6.0",
77
- "nyc": "^17.0.0",
84
+ "jsdom": "^25.0.1",
85
+ "mocha": "^10.7.3",
78
86
  "react": "^18.3.1",
79
87
  "react-dom": "^18.3.1",
80
88
  "reflect-metadata": "^0.1.14",
81
89
  "sinon": "^18.0.0",
82
90
  "sinon-chai": "^3.7.0",
83
- "typescript": "~5.5.3",
91
+ "testdouble": "^3.20.2",
92
+ "typescript": "~5.6.3",
84
93
  "presentation-build-tools": "^0.0.0",
85
94
  "presentation-test-utilities": "^0.0.0"
86
95
  },
87
96
  "scripts": {
88
97
  "build": "npm run -s build:cjs && npm run -s build:esm",
89
- "build:cjs": "tsc -p tsconfig.cjs.json",
98
+ "build:cjs": "node ../../scripts/package-cjs.mjs ./lib/cjs && tsc -p tsconfig.cjs.json",
90
99
  "build:esm": "tsc -p tsconfig.esm.json",
91
- "build:watch": "npm run -s build:cjs -- -w",
92
100
  "clean": "rimraf lib build",
93
- "cover": "nyc npm -s test",
101
+ "cover": "c8 npm -s test",
94
102
  "docs": "npm run -s docs:reference && npm run -s docs:changelog",
95
103
  "docs:changelog": "cpx ./CHANGELOG.md ./build/docs/reference/presentation-testing",
96
104
  "docs:reference": "cross-env NODE_PROJECT_ROOT_DIRECTORY=../../ betools docs --includes=./build/docs/extract --json=./build/docs/reference/presentation-testing/file.json --tsIndexFile=presentation-testing.ts --onlyJson --testExcludeGlob=./src/test/**",
97
105
  "lint": "eslint ./src/**/*.ts",
98
- "test": "mocha --enable-source-maps --config ./.mocharc.json \"./lib/cjs/test/**/*.test.js\"",
106
+ "test:dev": "cross-env NODE_OPTIONS=\"--import presentation-test-utilities/node-hooks/ignore-styles\" mocha --enable-source-maps --config ./.mocharc.json",
107
+ "test": "npm run test:dev",
99
108
  "extract-api": "extract-api --entry=presentation-testing --apiReportFolder=./api --apiReportTempFolder=./api/temp --apiSummaryFolder=./api",
100
109
  "check-internal": "node ../../scripts/checkInternal.js --apiSummary ./api/presentation-testing.api.md"
101
110
  }
@@ -1,25 +0,0 @@
1
- import { LocalFileName } from "@itwin/core-common";
2
- /** @internal */
3
- export declare function getTestOutputDir(): string;
4
- /** @internal */
5
- export declare function setTestOutputDir(directoryPath: string | undefined): void;
6
- /**
7
- * Prepare for an output file by:
8
- * - Resolving the output file name under the known test output directory
9
- * - Making directories as necessary
10
- * - Removing a previous copy of the output file
11
- * @param fileName Name of output file. The actual file name may get modified to fit within the file system limits.
12
- * @internal
13
- */
14
- export declare function setupOutputFileLocation(fileName: string): LocalFileName;
15
- /** @internal */
16
- export declare function createFileNameFromString(str: string): string;
17
- /**
18
- * `itwinjs-core` creates some accompanying files for each iModels and their names are formed by appending
19
- * a suffix to iModel file name. This constant should account for the maximum suffix length.
20
- * @internal
21
- */
22
- export declare const FILE_PATH_RESERVED_CHARACTERS = 13;
23
- /** @internal */
24
- export declare function limitFilePathLength(filePath: string): string;
25
- //# sourceMappingURL=InternalUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InternalUtils.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/InternalUtils.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,gBAAgB;AAChB,wBAAgB,gBAAgB,WAE/B;AAED,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,QAEjE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAOvE;AAED,gBAAgB;AAChB,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,UAEnD;AAED;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,gBAAgB;AAChB,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,UAiBnD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"InternalUtils.js","sourceRoot":"","sources":["../../../src/presentation-testing/InternalUtils.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;;;;AAYhG,4CAEC;AAGD,4CAEC;AAUD,0DAOC;AAGD,4DAEC;AAUD,kDAiBC;AAlED,2BAA4B;AAC5B,gDAAwB;AACxB,0EAAyC;AACzC,sDAAiD;AAGjD,MAAM,oBAAoB,GAAG,IAAA,WAAM,GAAE,CAAC;AACtC,IAAI,aAAiC,CAAC;AAEtC,gBAAgB;AAChB,SAAgB,gBAAgB;IAC9B,OAAO,aAAa,IAAI,oBAAoB,CAAC;AAC/C,CAAC;AAED,gBAAgB;AAChB,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ClB,CAAC;IAED,qBAAqB,IAAI,iBAAiB,CAAC;IAC3C,IAAI,qBAAqB,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,cAAc,QAAQ,gBAAgB,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,WAAW,GAAG,qBAAqB,GAAG,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC;IACvH,OAAO,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,GAAG,GAAG,EAAE,CAAC,CAAC;AAClD,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\nimport { tmpdir } from \"os\";\nimport path from \"path\";\nimport sanitize from \"sanitize-filename\";\nimport { IModelJsFs } from \"@itwin/core-backend\";\nimport { LocalFileName } from \"@itwin/core-common\";\n\nconst defaultTestOutputDir = tmpdir();\nlet testOutputDir: string | undefined;\n\n/** @internal */\nexport function getTestOutputDir() {\n return testOutputDir ?? defaultTestOutputDir;\n}\n\n/** @internal */\nexport function setTestOutputDir(directoryPath: string | undefined) {\n testOutputDir = directoryPath;\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. The actual file name may get modified to fit within the file system limits.\n * @internal\n */\nexport function setupOutputFileLocation(fileName: string): LocalFileName {\n const outputDirectoryPath = getTestOutputDir();\n !IModelJsFs.existsSync(outputDirectoryPath) && IModelJsFs.mkdirSync(outputDirectoryPath);\n\n const outputFilePath = limitFilePathLength(path.join(outputDirectoryPath, `${fileName}.bim`));\n IModelJsFs.existsSync(outputFilePath) && IModelJsFs.unlinkSync(outputFilePath);\n return outputFilePath;\n}\n\n/** @internal */\nexport function createFileNameFromString(str: string) {\n return sanitize(str.replace(/[ ]+/g, \"-\").replaceAll(\"`\", \"\").replaceAll(\"'\", \"\")).toLocaleLowerCase();\n}\n\n/**\n * `itwinjs-core` creates some accompanying files for each iModels and their names are formed by appending\n * a suffix to iModel file name. This constant should account for the maximum suffix length.\n * @internal\n */\nexport const FILE_PATH_RESERVED_CHARACTERS = 13;\n\n/** @internal */\nexport function limitFilePathLength(filePath: string) {\n const { dir, name, ext } = path.parse(filePath);\n const THREE_DOTS_LENGTH = 3;\n\n let allowedFileNameLength = 260 - FILE_PATH_RESERVED_CHARACTERS - (dir.length + 1) - ext.length;\n if (name.length <= allowedFileNameLength) {\n return filePath;\n }\n\n allowedFileNameLength -= THREE_DOTS_LENGTH;\n if (allowedFileNameLength <= 0) {\n throw new Error(`File path \"${filePath}\" is too long.`);\n }\n\n const pieceLength = allowedFileNameLength / 2;\n const shortenedName = `${name.slice(0, Math.ceil(pieceLength))}...${name.slice(Math.ceil(name.length - pieceLength))}`;\n return path.join(dir, `${shortenedName}${ext}`);\n}\n"]}
@@ -1,25 +0,0 @@
1
- import { LocalFileName } from "@itwin/core-common";
2
- /** @internal */
3
- export declare function getTestOutputDir(): string;
4
- /** @internal */
5
- export declare function setTestOutputDir(directoryPath: string | undefined): void;
6
- /**
7
- * Prepare for an output file by:
8
- * - Resolving the output file name under the known test output directory
9
- * - Making directories as necessary
10
- * - Removing a previous copy of the output file
11
- * @param fileName Name of output file. The actual file name may get modified to fit within the file system limits.
12
- * @internal
13
- */
14
- export declare function setupOutputFileLocation(fileName: string): LocalFileName;
15
- /** @internal */
16
- export declare function createFileNameFromString(str: string): string;
17
- /**
18
- * `itwinjs-core` creates some accompanying files for each iModels and their names are formed by appending
19
- * a suffix to iModel file name. This constant should account for the maximum suffix length.
20
- * @internal
21
- */
22
- export declare const FILE_PATH_RESERVED_CHARACTERS = 13;
23
- /** @internal */
24
- export declare function limitFilePathLength(filePath: string): string;
25
- //# sourceMappingURL=InternalUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InternalUtils.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/InternalUtils.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,gBAAgB;AAChB,wBAAgB,gBAAgB,WAE/B;AAED,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,QAEjE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAOvE;AAED,gBAAgB;AAChB,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,UAEnD;AAED;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,gBAAgB;AAChB,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,UAiBnD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"InternalUtils.js","sourceRoot":"","sources":["../../../src/presentation-testing/InternalUtils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,MAAM,oBAAoB,GAAG,MAAM,EAAE,CAAC;AACtC,IAAI,aAAiC,CAAC;AAEtC,gBAAgB;AAChB,MAAM,UAAU,gBAAgB;IAC9B,OAAO,aAAa,IAAI,oBAAoB,CAAC;AAC/C,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,aAAiC;IAChE,aAAa,GAAG,aAAa,CAAC;AA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3C,IAAI,qBAAqB,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,cAAc,QAAQ,gBAAgB,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,WAAW,GAAG,qBAAqB,GAAG,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC;IACvH,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,GAAG,GAAG,EAAE,CAAC,CAAC;AAClD,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\nimport { tmpdir } from \"os\";\nimport path from \"path\";\nimport sanitize from \"sanitize-filename\";\nimport { IModelJsFs } from \"@itwin/core-backend\";\nimport { LocalFileName } from \"@itwin/core-common\";\n\nconst defaultTestOutputDir = tmpdir();\nlet testOutputDir: string | undefined;\n\n/** @internal */\nexport function getTestOutputDir() {\n return testOutputDir ?? defaultTestOutputDir;\n}\n\n/** @internal */\nexport function setTestOutputDir(directoryPath: string | undefined) {\n testOutputDir = directoryPath;\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. The actual file name may get modified to fit within the file system limits.\n * @internal\n */\nexport function setupOutputFileLocation(fileName: string): LocalFileName {\n const outputDirectoryPath = getTestOutputDir();\n !IModelJsFs.existsSync(outputDirectoryPath) && IModelJsFs.mkdirSync(outputDirectoryPath);\n\n const outputFilePath = limitFilePathLength(path.join(outputDirectoryPath, `${fileName}.bim`));\n IModelJsFs.existsSync(outputFilePath) && IModelJsFs.unlinkSync(outputFilePath);\n return outputFilePath;\n}\n\n/** @internal */\nexport function createFileNameFromString(str: string) {\n return sanitize(str.replace(/[ ]+/g, \"-\").replaceAll(\"`\", \"\").replaceAll(\"'\", \"\")).toLocaleLowerCase();\n}\n\n/**\n * `itwinjs-core` creates some accompanying files for each iModels and their names are formed by appending\n * a suffix to iModel file name. This constant should account for the maximum suffix length.\n * @internal\n */\nexport const FILE_PATH_RESERVED_CHARACTERS = 13;\n\n/** @internal */\nexport function limitFilePathLength(filePath: string) {\n const { dir, name, ext } = path.parse(filePath);\n const THREE_DOTS_LENGTH = 3;\n\n let allowedFileNameLength = 260 - FILE_PATH_RESERVED_CHARACTERS - (dir.length + 1) - ext.length;\n if (name.length <= allowedFileNameLength) {\n return filePath;\n }\n\n allowedFileNameLength -= THREE_DOTS_LENGTH;\n if (allowedFileNameLength <= 0) {\n throw new Error(`File path \"${filePath}\" is too long.`);\n }\n\n const pieceLength = allowedFileNameLength / 2;\n const shortenedName = `${name.slice(0, Math.ceil(pieceLength))}...${name.slice(Math.ceil(name.length - pieceLength))}`;\n return path.join(dir, `${shortenedName}${ext}`);\n}\n"]}