From 7ec0a5ae397320541e125c9c72374e545873fecd Mon Sep 17 00:00:00 2001 From: Bogdan Nechyporenko Date: Thu, 13 Feb 2025 21:50:54 +0100 Subject: [PATCH] Changing the default behaviour of the checkpoint in createMockActionContext. It will reduce the code boilerplate in the tests where checkpoint is used. Signed-off-by: Bogdan Nechyporenko --- .changeset/six-elephants-rest.md | 5 +++++ .../src/actions/mockActionContext.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/six-elephants-rest.md diff --git a/.changeset/six-elephants-rest.md b/.changeset/six-elephants-rest.md new file mode 100644 index 0000000000..f76fe08389 --- /dev/null +++ b/.changeset/six-elephants-rest.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-node-test-utils': patch +--- + +Changing the default behaviour of the checkpoint in createMockActionContext. It will reduce the code boilerplate in the tests where checkpoint is used. diff --git a/plugins/scaffolder-node-test-utils/src/actions/mockActionContext.ts b/plugins/scaffolder-node-test-utils/src/actions/mockActionContext.ts index 1d45051753..076bb0ce22 100644 --- a/plugins/scaffolder-node-test-utils/src/actions/mockActionContext.ts +++ b/plugins/scaffolder-node-test-utils/src/actions/mockActionContext.ts @@ -21,7 +21,7 @@ import { mockCredentials, mockServices, } from '@backstage/backend-test-utils'; -import { JsonObject } from '@backstage/types'; +import { JsonObject, JsonValue } from '@backstage/types'; import { ActionContext } from '@backstage/plugin-scaffolder-node'; /** @@ -43,7 +43,12 @@ export const createMockActionContext = < output: jest.fn(), createTemporaryDirectory: jest.fn(), input: {} as TActionInput, - checkpoint: jest.fn(), + async checkpoint(opts: { + key: string; + fn: () => Promise | T; + }): Promise { + return opts.fn(); + }, getInitiatorCredentials: () => Promise.resolve(credentials), task: { id: 'mock-task-id',