@backstage/frontend-test-utils 0.5.1-next.0 → 0.5.1-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @backstage/frontend-test-utils
2
2
 
3
+ ## 0.5.1-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 479282f: Fixed type inference of `TestApiPair` when using tuple syntax by wrapping `MockWithApiFactory` in `NoInfer`.
8
+ - Updated dependencies
9
+ - @backstage/plugin-app@0.4.1-next.1
10
+ - @backstage/config@1.3.6
11
+ - @backstage/core-app-api@1.19.6-next.0
12
+ - @backstage/core-plugin-api@1.12.4-next.0
13
+ - @backstage/frontend-app-api@0.15.1-next.0
14
+ - @backstage/frontend-plugin-api@0.14.2-next.0
15
+ - @backstage/test-utils@1.7.16-next.0
16
+ - @backstage/types@1.2.2
17
+ - @backstage/version-bridge@1.0.12
18
+ - @backstage/plugin-app-react@0.2.1-next.0
19
+ - @backstage/plugin-permission-common@0.9.6
20
+ - @backstage/plugin-permission-react@0.4.41-next.0
21
+
3
22
  ## 0.5.1-next.0
4
23
 
5
24
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"TestApiProvider.esm.js","sources":["../../src/apis/TestApiProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactNode } from 'react';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { ApiProvider } from '../../../core-app-api/src/apis/system';\nimport { ApiHolder, ApiRef } from '@backstage/frontend-plugin-api';\nimport {\n getMockApiFactory,\n type MockWithApiFactory,\n} from './MockWithApiFactory';\n\n/**\n * Represents a single API implementation, either as a tuple of the reference and the implementation, or a mock with an embedded factory.\n * @public\n */\nexport type TestApiPair<TApi> =\n | readonly [ApiRef<TApi>, TApi extends infer TImpl ? Partial<TImpl> : never]\n | MockWithApiFactory<TApi>;\n\n/**\n * Represents an array of mock API implementation.\n * @public\n */\nexport type TestApiPairs<TApiPairs> = {\n [TIndex in keyof TApiPairs]: TestApiPair<TApiPairs[TIndex]>;\n};\n\n/** @internal */\nexport function resolveTestApiEntries<const TApiPairs extends any[]>(\n apis: readonly [...TestApiPairs<TApiPairs>],\n): ApiHolder {\n const apiMap = new Map<string, unknown>();\n\n for (const entry of apis) {\n const mockFactory = getMockApiFactory(entry);\n if (mockFactory) {\n apiMap.set(mockFactory.api.id, mockFactory.factory({}));\n } else {\n const [apiRef, impl] = entry as readonly [ApiRef<any>, any];\n apiMap.set(apiRef.id, impl);\n }\n }\n\n return {\n get: <T,>(ref: ApiRef<T>) => apiMap.get(ref.id) as T | undefined,\n };\n}\n\n/**\n * Properties for the {@link TestApiProvider} component.\n *\n * @public\n */\nexport type TestApiProviderProps<TApiPairs extends any[]> = {\n apis: readonly [...TestApiPairs<TApiPairs>];\n children: ReactNode;\n};\n\n/**\n * The `TestApiProvider` is a Utility API context provider for standalone rendering\n * scenarios where you're not using `renderInTestApp` or other test utilities.\n *\n * It lets you provide any number of API implementations, without necessarily\n * having to fully implement each of the APIs.\n *\n * @remarks\n *\n * For most test scenarios, prefer using the `apis` option in `renderInTestApp` or\n * `createExtensionTester` instead of wrapping components with `TestApiProvider`.\n *\n * @example\n * ```tsx\n * import { render } from '\\@testing-library/react';\n * import { myCustomApiRef } from '../apis';\n * import { TestApiProvider, mockApis } from '\\@backstage/frontend-test-utils';\n *\n * // Mock custom APIs with tuple syntax\n * const myCustomApiMock = { myMethod: jest.fn() };\n * render(\n * <TestApiProvider\n * apis={[\n * [myCustomApiRef, myCustomApiMock]\n * ]}\n * >\n * <MyComponent />\n * </TestApiProvider>\n * );\n *\n * // Use with built-in mock APIs (no tuples needed)\n * render(\n * <TestApiProvider\n * apis={[\n * mockApis.identity({ userEntityRef: 'user:default/guest' }),\n * mockApis.alert(),\n * ]}\n * >\n * <MyComponent />\n * </TestApiProvider>\n * );\n * ```\n *\n * @public\n */\nexport function TestApiProvider<const TApiPairs extends any[]>(\n props: TestApiProviderProps<TApiPairs>,\n): JSX.Element {\n return (\n <ApiProvider\n apis={resolveTestApiEntries(props.apis)}\n children={props.children}\n />\n );\n}\n"],"names":[],"mappings":";;;;AA0CO,SAAS,sBACd,IAAA,EACW;AACX,EAAA,MAAM,MAAA,uBAAa,GAAA,EAAqB;AAExC,EAAA,KAAA,MAAW,SAAS,IAAA,EAAM;AACxB,IAAA,MAAM,WAAA,GAAc,kBAAkB,KAAK,CAAA;AAC3C,IAAA,IAAI,WAAA,EAAa;AACf,MAAA,MAAA,CAAO,GAAA,CAAI,YAAY,GAAA,CAAI,EAAA,EAAI,YAAY,OAAA,CAAQ,EAAE,CAAC,CAAA;AAAA,IACxD,CAAA,MAAO;AACL,MAAA,MAAM,CAAC,MAAA,EAAQ,IAAI,CAAA,GAAI,KAAA;AACvB,MAAA,MAAA,CAAO,GAAA,CAAI,MAAA,CAAO,EAAA,EAAI,IAAI,CAAA;AAAA,IAC5B;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,KAAK,CAAK,GAAA,KAAmB,MAAA,CAAO,GAAA,CAAI,IAAI,EAAE;AAAA,GAChD;AACF;AAyDO,SAAS,gBACd,KAAA,EACa;AACb,EAAA,uBACE,GAAA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACC,IAAA,EAAM,qBAAA,CAAsB,KAAA,CAAM,IAAI,CAAA;AAAA,MACtC,UAAU,KAAA,CAAM;AAAA;AAAA,GAClB;AAEJ;;;;"}
1
+ {"version":3,"file":"TestApiProvider.esm.js","sources":["../../src/apis/TestApiProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactNode } from 'react';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { ApiProvider } from '../../../core-app-api/src/apis/system';\nimport { ApiHolder, ApiRef } from '@backstage/frontend-plugin-api';\nimport {\n getMockApiFactory,\n type MockWithApiFactory,\n} from './MockWithApiFactory';\n\n/**\n * Represents a single API implementation, either as a tuple of the reference and the implementation, or a mock with an embedded factory.\n * @public\n */\nexport type TestApiPair<TApi> =\n | readonly [ApiRef<TApi>, TApi extends infer TImpl ? Partial<TImpl> : never]\n | MockWithApiFactory<NoInfer<TApi>>;\n\n/**\n * Represents an array of mock API implementation.\n * @public\n */\nexport type TestApiPairs<TApiPairs> = {\n [TIndex in keyof TApiPairs]: TestApiPair<TApiPairs[TIndex]>;\n};\n\n/** @internal */\nexport function resolveTestApiEntries<const TApiPairs extends any[]>(\n apis: readonly [...TestApiPairs<TApiPairs>],\n): ApiHolder {\n const apiMap = new Map<string, unknown>();\n\n for (const entry of apis) {\n const mockFactory = getMockApiFactory(entry);\n if (mockFactory) {\n apiMap.set(mockFactory.api.id, mockFactory.factory({}));\n } else {\n const [apiRef, impl] = entry as readonly [ApiRef<any>, any];\n apiMap.set(apiRef.id, impl);\n }\n }\n\n return {\n get: <T,>(ref: ApiRef<T>) => apiMap.get(ref.id) as T | undefined,\n };\n}\n\n/**\n * Properties for the {@link TestApiProvider} component.\n *\n * @public\n */\nexport type TestApiProviderProps<TApiPairs extends any[]> = {\n apis: readonly [...TestApiPairs<TApiPairs>];\n children: ReactNode;\n};\n\n/**\n * The `TestApiProvider` is a Utility API context provider for standalone rendering\n * scenarios where you're not using `renderInTestApp` or other test utilities.\n *\n * It lets you provide any number of API implementations, without necessarily\n * having to fully implement each of the APIs.\n *\n * @remarks\n *\n * For most test scenarios, prefer using the `apis` option in `renderInTestApp` or\n * `createExtensionTester` instead of wrapping components with `TestApiProvider`.\n *\n * @example\n * ```tsx\n * import { render } from '\\@testing-library/react';\n * import { myCustomApiRef } from '../apis';\n * import { TestApiProvider, mockApis } from '\\@backstage/frontend-test-utils';\n *\n * // Mock custom APIs with tuple syntax\n * const myCustomApiMock = { myMethod: jest.fn() };\n * render(\n * <TestApiProvider\n * apis={[\n * [myCustomApiRef, myCustomApiMock]\n * ]}\n * >\n * <MyComponent />\n * </TestApiProvider>\n * );\n *\n * // Use with built-in mock APIs (no tuples needed)\n * render(\n * <TestApiProvider\n * apis={[\n * mockApis.identity({ userEntityRef: 'user:default/guest' }),\n * mockApis.alert(),\n * ]}\n * >\n * <MyComponent />\n * </TestApiProvider>\n * );\n * ```\n *\n * @public\n */\nexport function TestApiProvider<const TApiPairs extends any[]>(\n props: TestApiProviderProps<TApiPairs>,\n): JSX.Element {\n return (\n <ApiProvider\n apis={resolveTestApiEntries(props.apis)}\n children={props.children}\n />\n );\n}\n"],"names":[],"mappings":";;;;AA0CO,SAAS,sBACd,IAAA,EACW;AACX,EAAA,MAAM,MAAA,uBAAa,GAAA,EAAqB;AAExC,EAAA,KAAA,MAAW,SAAS,IAAA,EAAM;AACxB,IAAA,MAAM,WAAA,GAAc,kBAAkB,KAAK,CAAA;AAC3C,IAAA,IAAI,WAAA,EAAa;AACf,MAAA,MAAA,CAAO,GAAA,CAAI,YAAY,GAAA,CAAI,EAAA,EAAI,YAAY,OAAA,CAAQ,EAAE,CAAC,CAAA;AAAA,IACxD,CAAA,MAAO;AACL,MAAA,MAAM,CAAC,MAAA,EAAQ,IAAI,CAAA,GAAI,KAAA;AACvB,MAAA,MAAA,CAAO,GAAA,CAAI,MAAA,CAAO,EAAA,EAAI,IAAI,CAAA;AAAA,IAC5B;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,KAAK,CAAK,GAAA,KAAmB,MAAA,CAAO,GAAA,CAAI,IAAI,EAAE;AAAA,GAChD;AACF;AAyDO,SAAS,gBACd,KAAA,EACa;AACb,EAAA,uBACE,GAAA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACC,IAAA,EAAM,qBAAA,CAAsB,KAAA,CAAM,IAAI,CAAA;AAAA,MACtC,UAAU,KAAA,CAAM;AAAA;AAAA,GAClB;AAEJ;;;;"}
package/dist/index.d.ts CHANGED
@@ -651,7 +651,7 @@ declare namespace mockApis {
651
651
  * Represents a single API implementation, either as a tuple of the reference and the implementation, or a mock with an embedded factory.
652
652
  * @public
653
653
  */
654
- type TestApiPair<TApi> = readonly [ApiRef<TApi>, TApi extends infer TImpl ? Partial<TImpl> : never] | MockWithApiFactory<TApi>;
654
+ type TestApiPair<TApi> = readonly [ApiRef<TApi>, TApi extends infer TImpl ? Partial<TImpl> : never] | MockWithApiFactory<NoInfer<TApi>>;
655
655
  /**
656
656
  * Represents an array of mock API implementation.
657
657
  * @public
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/frontend-test-utils",
3
- "version": "0.5.1-next.0",
3
+ "version": "0.5.1-next.1",
4
4
  "backstage": {
5
5
  "role": "web-library"
6
6
  },
@@ -36,7 +36,7 @@
36
36
  "@backstage/core-plugin-api": "1.12.4-next.0",
37
37
  "@backstage/frontend-app-api": "0.15.1-next.0",
38
38
  "@backstage/frontend-plugin-api": "0.14.2-next.0",
39
- "@backstage/plugin-app": "0.4.1-next.0",
39
+ "@backstage/plugin-app": "0.4.1-next.1",
40
40
  "@backstage/plugin-app-react": "0.2.1-next.0",
41
41
  "@backstage/plugin-permission-common": "0.9.6",
42
42
  "@backstage/plugin-permission-react": "0.4.41-next.0",
@@ -48,7 +48,7 @@
48
48
  "zod": "^3.25.76"
49
49
  },
50
50
  "devDependencies": {
51
- "@backstage/cli": "0.35.5-next.0",
51
+ "@backstage/cli": "0.36.0-next.1",
52
52
  "@testing-library/jest-dom": "^6.0.0",
53
53
  "@types/jest": "*",
54
54
  "@types/react": "^18.0.0",