@open-pioneer/test-utils 4.2.0-dev.20251017113502 → 4.2.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.
package/CHANGELOG.md CHANGED
@@ -1,17 +1,35 @@
1
1
  # @open-pioneer/test-utils
2
2
 
3
- ## 4.2.0-dev.20251017113502
3
+ ## 4.2.0
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - 1b95a62: Update chakra-ui to 3.27.1
7
+ - 9fa7f7c: The `createService` helper no longer returns a promise.
8
+ It can now be used in a synchronous fashion (no `await`).
9
+
10
+ Note that this change is backwards compatible.
11
+ But if you have been using this function in your code, you can simply remove the `await`.
12
+
13
+ It originally returned a promise to support (future) asynchronous initialization of services,
14
+ which has not been implemented and seems not to be needed.
15
+
16
+ Example:
17
+
18
+ ```ts
19
+ // In your unit tests:
20
+ import { createService } from "@open-pioneer/test-utils/services";
21
+
22
+ const service = createService(MyServiceClass, options);
23
+ ```
24
+
25
+ - 1b95a62: Update chakra-ui to 3.28.0
8
26
 
9
27
  ### Patch Changes
10
28
 
11
29
  - 81308c0: Update to eslint 9
12
30
  - Updated dependencies [81308c0]
13
31
  - Updated dependencies [1b95a62]
14
- - @open-pioneer/runtime@4.2.0-dev.20251017113502
32
+ - @open-pioneer/runtime@4.2.0
15
33
 
16
34
  ## 4.1.0
17
35
 
package/README.md CHANGED
@@ -96,7 +96,7 @@ import { createService } from "@open-pioneer/test-utils/services";
96
96
  import { MyService } from "./MyService"; // User defined service
97
97
 
98
98
  it("creates a new service instance with the defined references", async () => {
99
- const service = await createService(MyService, {
99
+ const service = createService(MyService, {
100
100
  references: {
101
101
  // Will be injected into the constructor.
102
102
  // TypeScript checks are intentionally relaxed a bit.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@open-pioneer/test-utils",
4
- "version": "4.2.0-dev.20251017113502",
4
+ "version": "4.2.0",
5
5
  "description": "Contains test utilities that make it easier to test parts of an Open Pioneer Trails application.",
6
6
  "keywords": [
7
7
  "open-pioneer-trails"
@@ -19,7 +19,7 @@
19
19
  "react-dom": "^19.2.0",
20
20
  "@testing-library/dom": "^10.4.1",
21
21
  "@formatjs/intl": "^3.1.8",
22
- "@open-pioneer/runtime": "4.2.0-dev.20251017113502"
22
+ "@open-pioneer/runtime": "^4.2.0"
23
23
  },
24
24
  "exports": {
25
25
  "./package.json": "./package.json",
package/services.d.ts CHANGED
@@ -57,5 +57,5 @@ type PartialServiceReferences<References> = {
57
57
  * @param options options passed to the service constructor
58
58
  * @returns a new instance of the given service class
59
59
  */
60
- export declare function createService<References extends {}, Interface extends {}>(clazz: ServiceConstructor<References, Interface>, options?: CreateServiceOptions<References>): Promise<Service<Interface>>;
60
+ export declare function createService<References extends {}, Interface extends {}>(clazz: ServiceConstructor<References, Interface>, options?: CreateServiceOptions<References>): Service<Interface>;
61
61
  export {};
package/services.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createIntl } from './vanilla.js';
2
2
 
3
- async function createService(clazz, options) {
3
+ function createService(clazz, options) {
4
4
  const references = options?.references ?? {};
5
5
  const referencesMeta = Object.fromEntries(
6
6
  Object.entries(references).map(([referenceName, reference]) => [
package/services.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"services.js","sources":["services.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReferenceMeta, Service, ServiceConstructor } from \"@open-pioneer/runtime\";\nimport { createIntl } from \"./vanilla\";\n\n/**\n * Options for the {@link createService} function.\n */\nexport interface CreateServiceOptions<References> {\n /**\n * References provided to the service constructor.\n *\n * @default {}\n */\n references?: PartialServiceReferences<References>;\n\n /**\n * Properties provided to the service constructor.\n *\n * @default {}\n */\n properties?: Record<string, unknown>;\n\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * The locale for embedded default messages.\n *\n * See also https://formatjs.io/docs/intl#message-descriptor\n *\n * @default \"en\"\n */\n defaultMessageLocale?: string;\n\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n messages?: Record<string, string>;\n}\n\ntype PartialServiceReferences<References> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [referenceName in keyof References]?: References[referenceName] extends any[]\n ? Partial<References[referenceName][number]>[]\n : Partial<References[referenceName]>;\n};\n\n/**\n * Creates a new service instance of `clazz`.\n *\n * The options passed into the constructor of `clazz` are taking from the `options` parameter.\n *\n * This function allows the user to define mock- or test objects as service references.\n *\n * Most type-checking features are disabled for convenience, but by default this function's types\n * enforce that a value provided for a reference must match the partial interface of the actually required type.\n *\n * For example, if a service depends on `{ ctx: ApplicationContext }`, this function ensures\n * that the test value for `ctx` implements `Partial<ApplicationContext>`.\n * This can of course be disabled by casting the value explicitly.\n *\n * @param clazz a service class\n * @param options options passed to the service constructor\n * @returns a new instance of the given service class\n */\nexport async function createService<References extends {}, Interface extends {}>(\n clazz: ServiceConstructor<References, Interface>,\n options?: CreateServiceOptions<References>\n): Promise<Service<Interface>> {\n const references = options?.references ?? {};\n const referencesMeta = Object.fromEntries(\n Object.entries(references).map(([referenceName, reference]) => [\n referenceName,\n referenceMeta(referenceName, reference)\n ])\n );\n\n const intl = createIntl(options);\n return new clazz({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n references: references as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n referencesMeta: referencesMeta as any,\n properties: options?.properties ?? {},\n intl\n });\n}\n\nfunction referenceMeta(referenceName: string, reference: unknown): ReferenceMeta | ReferenceMeta[] {\n if (Array.isArray(reference)) {\n return reference.map<ReferenceMeta>((_, index) => ({\n serviceId: `test-utils::${referenceName}-${index}`\n }));\n }\n return {\n serviceId: `test-utils::${referenceName}`\n };\n}\n"],"names":[],"mappings":";;AAwEA,eAAsB,aAAA,CAClB,OACA,OAAA,EAC2B;AAC3B,EAAA,MAAM,UAAA,GAAa,OAAA,EAAS,UAAA,IAAc,EAAC;AAC3C,EAAA,MAAM,iBAAiB,MAAA,CAAO,WAAA;AAAA,IAC1B,MAAA,CAAO,QAAQ,UAAU,CAAA,CAAE,IAAI,CAAC,CAAC,aAAA,EAAe,SAAS,CAAA,KAAM;AAAA,MAC3D,aAAA;AAAA,MACA,aAAA,CAAc,eAAe,SAAS;AAAA,KACzC;AAAA,GACL;AAEA,EAAA,MAAM,IAAA,GAAO,WAAW,OAAO,CAAA;AAC/B,EAAA,OAAO,IAAI,KAAA,CAAM;AAAA;AAAA,IAEb,UAAA;AAAA;AAAA,IAEA,cAAA;AAAA,IACA,UAAA,EAAY,OAAA,EAAS,UAAA,IAAc,EAAC;AAAA,IACpC;AAAA,GACH,CAAA;AACL;AAEA,SAAS,aAAA,CAAc,eAAuB,SAAA,EAAqD;AAC/F,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,SAAS,CAAA,EAAG;AAC1B,IAAA,OAAO,SAAA,CAAU,GAAA,CAAmB,CAAC,CAAA,EAAG,KAAA,MAAW;AAAA,MAC/C,SAAA,EAAW,CAAA,YAAA,EAAe,aAAa,CAAA,CAAA,EAAI,KAAK,CAAA;AAAA,KACpD,CAAE,CAAA;AAAA,EACN;AACA,EAAA,OAAO;AAAA,IACH,SAAA,EAAW,eAAe,aAAa,CAAA;AAAA,GAC3C;AACJ;;;;"}
1
+ {"version":3,"file":"services.js","sources":["services.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReferenceMeta, Service, ServiceConstructor } from \"@open-pioneer/runtime\";\nimport { createIntl } from \"./vanilla\";\n\n/**\n * Options for the {@link createService} function.\n */\nexport interface CreateServiceOptions<References> {\n /**\n * References provided to the service constructor.\n *\n * @default {}\n */\n references?: PartialServiceReferences<References>;\n\n /**\n * Properties provided to the service constructor.\n *\n * @default {}\n */\n properties?: Record<string, unknown>;\n\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * The locale for embedded default messages.\n *\n * See also https://formatjs.io/docs/intl#message-descriptor\n *\n * @default \"en\"\n */\n defaultMessageLocale?: string;\n\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n messages?: Record<string, string>;\n}\n\ntype PartialServiceReferences<References> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [referenceName in keyof References]?: References[referenceName] extends any[]\n ? Partial<References[referenceName][number]>[]\n : Partial<References[referenceName]>;\n};\n\n/**\n * Creates a new service instance of `clazz`.\n *\n * The options passed into the constructor of `clazz` are taking from the `options` parameter.\n *\n * This function allows the user to define mock- or test objects as service references.\n *\n * Most type-checking features are disabled for convenience, but by default this function's types\n * enforce that a value provided for a reference must match the partial interface of the actually required type.\n *\n * For example, if a service depends on `{ ctx: ApplicationContext }`, this function ensures\n * that the test value for `ctx` implements `Partial<ApplicationContext>`.\n * This can of course be disabled by casting the value explicitly.\n *\n * @param clazz a service class\n * @param options options passed to the service constructor\n * @returns a new instance of the given service class\n */\nexport function createService<References extends {}, Interface extends {}>(\n clazz: ServiceConstructor<References, Interface>,\n options?: CreateServiceOptions<References>\n): Service<Interface> {\n const references = options?.references ?? {};\n const referencesMeta = Object.fromEntries(\n Object.entries(references).map(([referenceName, reference]) => [\n referenceName,\n referenceMeta(referenceName, reference)\n ])\n );\n\n const intl = createIntl(options);\n return new clazz({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n references: references as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n referencesMeta: referencesMeta as any,\n properties: options?.properties ?? {},\n intl\n });\n}\n\nfunction referenceMeta(referenceName: string, reference: unknown): ReferenceMeta | ReferenceMeta[] {\n if (Array.isArray(reference)) {\n return reference.map<ReferenceMeta>((_, index) => ({\n serviceId: `test-utils::${referenceName}-${index}`\n }));\n }\n return {\n serviceId: `test-utils::${referenceName}`\n };\n}\n"],"names":[],"mappings":";;AAwEO,SAAS,aAAA,CACZ,OACA,OAAA,EACkB;AAClB,EAAA,MAAM,UAAA,GAAa,OAAA,EAAS,UAAA,IAAc,EAAC;AAC3C,EAAA,MAAM,iBAAiB,MAAA,CAAO,WAAA;AAAA,IAC1B,MAAA,CAAO,QAAQ,UAAU,CAAA,CAAE,IAAI,CAAC,CAAC,aAAA,EAAe,SAAS,CAAA,KAAM;AAAA,MAC3D,aAAA;AAAA,MACA,aAAA,CAAc,eAAe,SAAS;AAAA,KACzC;AAAA,GACL;AAEA,EAAA,MAAM,IAAA,GAAO,WAAW,OAAO,CAAA;AAC/B,EAAA,OAAO,IAAI,KAAA,CAAM;AAAA;AAAA,IAEb,UAAA;AAAA;AAAA,IAEA,cAAA;AAAA,IACA,UAAA,EAAY,OAAA,EAAS,UAAA,IAAc,EAAC;AAAA,IACpC;AAAA,GACH,CAAA;AACL;AAEA,SAAS,aAAA,CAAc,eAAuB,SAAA,EAAqD;AAC/F,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,SAAS,CAAA,EAAG;AAC1B,IAAA,OAAO,SAAA,CAAU,GAAA,CAAmB,CAAC,CAAA,EAAG,KAAA,MAAW;AAAA,MAC/C,SAAA,EAAW,CAAA,YAAA,EAAe,aAAa,CAAA,CAAA,EAAI,KAAK,CAAA;AAAA,KACpD,CAAE,CAAA;AAAA,EACN;AACA,EAAA,OAAO;AAAA,IACH,SAAA,EAAW,eAAe,aAAa,CAAA;AAAA,GAC3C;AACJ;;;;"}