@backstage/backend-test-utils 1.11.1-next.0 → 1.11.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,21 @@
|
|
|
1
1
|
# @backstage/backend-test-utils
|
|
2
2
|
|
|
3
|
+
## 1.11.1-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 62f0a53: Fixed error forwarding in the actions registry so that known errors like `InputError` and `NotFoundError` thrown by actions preserve their original status codes and messages instead of being wrapped in `ForwardedError` and coerced to 500.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/backend-defaults@0.16.0-next.1
|
|
10
|
+
- @backstage/plugin-auth-node@0.6.14-next.1
|
|
11
|
+
- @backstage/backend-app-api@1.5.1-next.0
|
|
12
|
+
- @backstage/backend-plugin-api@1.7.1-next.0
|
|
13
|
+
- @backstage/config@1.3.6
|
|
14
|
+
- @backstage/errors@1.2.7
|
|
15
|
+
- @backstage/types@1.2.2
|
|
16
|
+
- @backstage/plugin-events-node@0.4.20-next.0
|
|
17
|
+
- @backstage/plugin-permission-common@0.9.6
|
|
18
|
+
|
|
3
19
|
## 1.11.1-next.0
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -51,26 +51,19 @@ class MockActionsRegistry {
|
|
|
51
51
|
if (!input.success) {
|
|
52
52
|
throw new errors.InputError(`Invalid input to action "${opts.id}"`, input.error);
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
output.error
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return { output: output.data };
|
|
68
|
-
} catch (error) {
|
|
69
|
-
throw new errors.ForwardedError(
|
|
70
|
-
`Failed execution of action "${opts.id}"`,
|
|
71
|
-
error
|
|
54
|
+
const result = await action.action({
|
|
55
|
+
input: input.data,
|
|
56
|
+
credentials: opts.credentials ?? mockCredentials.mockCredentials.none(),
|
|
57
|
+
logger: this.logger
|
|
58
|
+
});
|
|
59
|
+
const output = action.schema?.output ? action.schema.output(zod.z).safeParse(result?.output) : { success: true, data: result?.output };
|
|
60
|
+
if (!output.success) {
|
|
61
|
+
throw new errors.InputError(
|
|
62
|
+
`Invalid output from action "${opts.id}"`,
|
|
63
|
+
output.error
|
|
72
64
|
);
|
|
73
65
|
}
|
|
66
|
+
return { output: output.data };
|
|
74
67
|
}
|
|
75
68
|
register(options) {
|
|
76
69
|
const id = `test:${options.name}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockActionsRegistry.cjs.js","sources":["../../../src/alpha/services/MockActionsRegistry.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\nimport {\n BackstageCredentials,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport {
|
|
1
|
+
{"version":3,"file":"MockActionsRegistry.cjs.js","sources":["../../../src/alpha/services/MockActionsRegistry.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\nimport {\n BackstageCredentials,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport { InputError, NotFoundError } from '@backstage/errors';\nimport { JsonObject, JsonValue } from '@backstage/types';\nimport { z, AnyZodObject } from 'zod';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { mockCredentials } from '../../services';\nimport {\n ActionsRegistryActionOptions,\n ActionsRegistryService,\n ActionsService,\n ActionsServiceAction,\n} from '@backstage/backend-plugin-api/alpha';\n\n/**\n * A mock implementation of the ActionsRegistryService and ActionsService that can be used in tests.\n *\n * This is useful for testing actions that are registered with the ActionsRegistryService and ActionsService.\n *\n * The plugin ID is hardcoded to `testing` in the mock implementation.\n *\n * @example\n * ```ts\n * const actionsRegistry = mockServices.actionsRegistry();\n *\n * actionsRegistry.register({\n * name: 'test',\n * title: 'Test',\n * description: 'Test',\n * schema: {\n * input: z.object({ name: z.string() }),\n * output: z.object({ name: z.string() }),\n * },\n * action: async ({ input }) => ({ output: { name: input.name } }),\n * });\n *\n *\n * const result = await actionsRegistry.invoke({\n * id: 'testing:test',\n * input: { name: 'test' },\n * });\n *\n * expect(result).toEqual({ output: { name: 'test' } });\n * ```\n *\n * @alpha\n */\nexport class MockActionsRegistry\n implements ActionsRegistryService, ActionsService\n{\n private readonly logger: LoggerService;\n\n private constructor(logger: LoggerService) {\n this.logger = logger;\n }\n\n static create(opts: { logger: LoggerService }) {\n return new MockActionsRegistry(opts.logger);\n }\n\n readonly actions: Map<string, ActionsRegistryActionOptions<any, any>> =\n new Map();\n\n async list(): Promise<{ actions: ActionsServiceAction[] }> {\n return {\n actions: Array.from(this.actions.entries()).map(([id, action]) => ({\n id,\n name: action.name,\n title: action.title,\n description: action.description,\n attributes: {\n destructive: action.attributes?.destructive ?? true,\n idempotent: action.attributes?.idempotent ?? false,\n readOnly: action.attributes?.readOnly ?? false,\n },\n schema: {\n input: action.schema?.input\n ? zodToJsonSchema(action.schema.input(z))\n : zodToJsonSchema(z.object({})),\n output: action.schema?.output\n ? zodToJsonSchema(action.schema.output(z))\n : zodToJsonSchema(z.object({})),\n } as ActionsServiceAction['schema'],\n })),\n };\n }\n\n async invoke(opts: {\n id: string;\n input?: JsonObject;\n credentials?: BackstageCredentials;\n }): Promise<{ output: JsonValue }> {\n const action = this.actions.get(opts.id);\n\n if (!action) {\n const availableActionIds = Array.from(this.actions.keys()).join(', ');\n throw new NotFoundError(\n `Action \"${opts.id}\" not found, available actions: ${\n availableActionIds ? `\"${availableActionIds}\"` : 'none'\n }`,\n );\n }\n\n const input = action.schema?.input\n ? action.schema.input(z).safeParse(opts.input)\n : ({ success: true, data: undefined } as const);\n\n if (!input.success) {\n throw new InputError(`Invalid input to action \"${opts.id}\"`, input.error);\n }\n\n const result = await action.action({\n input: input.data,\n credentials: opts.credentials ?? mockCredentials.none(),\n logger: this.logger,\n });\n\n const output = action.schema?.output\n ? action.schema.output(z).safeParse(result?.output)\n : ({ success: true, data: result?.output } as const);\n\n if (!output.success) {\n throw new InputError(\n `Invalid output from action \"${opts.id}\"`,\n output.error,\n );\n }\n\n return { output: output.data };\n }\n\n register<\n TInputSchema extends AnyZodObject,\n TOutputSchema extends AnyZodObject,\n >(options: ActionsRegistryActionOptions<TInputSchema, TOutputSchema>): void {\n // hardcode test: prefix similar to how the default actions registry does it\n // and other places around the testing ecosystem:\n // https://github.com/backstage/backstage/blob/a9219496d5c073aaa0b8caf32ece10455cf65e61/packages/backend-test-utils/src/next/services/mockServices.ts#L321\n // https://github.com/backstage/backstage/blob/861f162b4a39117b824669d67a951ed1db142e3d/packages/backend-test-utils/src/next/wiring/ServiceFactoryTester.ts#L99\n const id = `test:${options.name}`;\n\n if (this.actions.has(id)) {\n throw new Error(`Action with id \"${id}\" is already registered`);\n }\n\n this.actions.set(id, options);\n }\n}\n"],"names":["zodToJsonSchema","z","NotFoundError","InputError","mockCredentials"],"mappings":";;;;;;;;;;;;;AAgEO,MAAM,mBAAA,CAEb;AAAA,EACmB,MAAA;AAAA,EAET,Y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OAAA,EAAS;AACnB,MAAA,MAAM,IAAIE,iBAAA;AAAA,QACR,CAAA,4BAAA,EAA+B,KAAK,EAAE,CAAA,CAAA,CAAA;AAAA,QACtC,MAAA,CAAO;AAAA,OACT;AAAA,IACF;AAEA,IAAA,OAAO,EAAE,MAAA,EAAQ,MAAA,CAAO,IAAA,EAAK;AAAA,EAC/B;AAAA,EAEA,SAGE,OAAA,EAA0E;AAK1E,IAAA,MAAM,EAAA,GAAK,CAAA,KAAA,EAAQ,OAAA,CAAQ,IAAI,CAAA,CAAA;AAE/B,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,EAAE,CAAA,EAAG;AACxB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gBAAA,EAAmB,EAAE,CAAA,uBAAA,CAAyB,CAAA;AAAA,IAChE;AAEA,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,EAAA,EAAI,OAAO,CAAA;AAAA,EAC9B;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/backend-test-utils",
|
|
3
|
-
"version": "1.11.1-next.
|
|
3
|
+
"version": "1.11.1-next.1",
|
|
4
4
|
"description": "Test helpers library for Backstage backends",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@backstage/backend-app-api": "1.5.1-next.0",
|
|
61
|
-
"@backstage/backend-defaults": "0.
|
|
61
|
+
"@backstage/backend-defaults": "0.16.0-next.1",
|
|
62
62
|
"@backstage/backend-plugin-api": "1.7.1-next.0",
|
|
63
63
|
"@backstage/config": "1.3.6",
|
|
64
64
|
"@backstage/errors": "1.2.7",
|
|
65
|
-
"@backstage/plugin-auth-node": "0.6.14-next.
|
|
65
|
+
"@backstage/plugin-auth-node": "0.6.14-next.1",
|
|
66
66
|
"@backstage/plugin-events-node": "0.4.20-next.0",
|
|
67
67
|
"@backstage/plugin-permission-common": "0.9.6",
|
|
68
68
|
"@backstage/types": "1.2.2",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"zod-to-json-schema": "^3.25.1"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@backstage/cli": "0.
|
|
94
|
+
"@backstage/cli": "0.36.0-next.1",
|
|
95
95
|
"@types/jest": "*",
|
|
96
96
|
"@types/lodash": "^4.14.151",
|
|
97
97
|
"@types/supertest": "^2.0.8",
|