From 118acbb71b8b2b61e652510bd270052a7b20dc7b Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 12 Mar 2022 10:24:46 +0100 Subject: [PATCH] scaffolder-backend: inline @gitbeaker/node mock Signed-off-by: Patrik Oldsberg --- .../__mocks__/@gitbeaker/node/index.ts | 33 ------------------- .../actions/builtin/publish/gitlab.test.ts | 22 +++++++++++-- 2 files changed, 19 insertions(+), 36 deletions(-) delete mode 100644 plugins/scaffolder-backend/src/scaffolder/__mocks__/@gitbeaker/node/index.ts diff --git a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@gitbeaker/node/index.ts b/plugins/scaffolder-backend/src/scaffolder/__mocks__/@gitbeaker/node/index.ts deleted file mode 100644 index 7166dc0f63..0000000000 --- a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@gitbeaker/node/index.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const mockGitlabClient = { - Namespaces: { - show: jest.fn(), - }, - Projects: { - create: jest.fn(), - }, - Users: { - current: jest.fn(), - }, -}; - -export class Gitlab { - constructor() { - return mockGitlabClient; - } -} diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.test.ts index db4ad5a019..ed8df4e5e8 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.test.ts @@ -14,7 +14,6 @@ * limitations under the License. */ jest.mock('../helpers'); -jest.mock('@gitbeaker/node'); import { createPublishGitlabAction } from './gitlab'; import { ScmIntegrations } from '@backstage/integration'; @@ -23,6 +22,25 @@ import { getVoidLogger } from '@backstage/backend-common'; import { PassThrough } from 'stream'; import { initRepoAndPush } from '../helpers'; +const mockGitlabClient = { + Namespaces: { + show: jest.fn(), + }, + Projects: { + create: jest.fn(), + }, + Users: { + current: jest.fn(), + }, +}; +jest.mock('@gitbeaker/node', () => ({ + Gitlab: class { + constructor() { + return mockGitlabClient; + } + }, +})); + describe('publish:gitlab', () => { const config = new ConfigReader({ integrations: { @@ -54,8 +72,6 @@ describe('publish:gitlab', () => { createTemporaryDirectory: jest.fn(), }; - const { mockGitlabClient } = require('@gitbeaker/node'); - beforeEach(() => { jest.resetAllMocks(); });