From d5aae2497e17742b907dacb8c1e085b63663e589 Mon Sep 17 00:00:00 2001 From: Tim deBoer Date: Fri, 19 Jan 2024 10:31:34 -0500 Subject: [PATCH] chore: cleanup bootc.ts The original template had a bootc.ts that we didn't use. None of the other extensions have this pattern, so we've decided to just clean it up for now. Tests merged in and extra files deleted. Fixes #55. Signed-off-by: Tim deBoer --- src/bootc.spec.ts | 58 ------------------------------------------- src/bootc.ts | 35 -------------------------- src/extension.spec.ts | 37 ++++++++++----------------- src/extension.ts | 8 ++---- 4 files changed, 15 insertions(+), 123 deletions(-) delete mode 100644 src/bootc.spec.ts delete mode 100644 src/bootc.ts diff --git a/src/bootc.spec.ts b/src/bootc.spec.ts deleted file mode 100644 index cbe34286..00000000 --- a/src/bootc.spec.ts +++ /dev/null @@ -1,58 +0,0 @@ -/********************************************************************** - * Copyright (C) 2024 Red Hat, Inc. - * - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - ***********************************************************************/ - -/* eslint-disable @typescript-eslint/no-explicit-any */ - -import { afterEach, beforeEach, expect, test, vi } from 'vitest'; -import { BootC } from './bootc'; -import type { ExtensionContext } from '@podman-desktop/api'; - -const mockedExtensionContext = {} as unknown as ExtensionContext; - -const bootc = new BootC(mockedExtensionContext); - -vi.mock('@podman-desktop/api', async () => { - return {}; -}); - -/// mock console.log -const originalConsoleLog = console.log; -const consoleLogMock = vi.fn(); - -beforeEach(() => { - vi.clearAllMocks(); - console.log = consoleLogMock; -}); - -afterEach(() => { - console.log = originalConsoleLog; -}); - -test('check activate ', async () => { - await bootc.activate(); - - // expect the activate method to be called on the bootc class - expect(consoleLogMock).toBeCalledWith('starting boot-c extension'); -}); - -test('check deactivate ', async () => { - await bootc.deactivate(); - - // expect the deactivate method to be called on the bootc class - expect(consoleLogMock).toBeCalledWith('stopping boot-c extension'); -}); diff --git a/src/bootc.ts b/src/bootc.ts deleted file mode 100644 index fd7e7063..00000000 --- a/src/bootc.ts +++ /dev/null @@ -1,35 +0,0 @@ -/********************************************************************** - * Copyright (C) 2024 Red Hat, Inc. - * - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - ***********************************************************************/ - -import type { ExtensionContext } from '@podman-desktop/api'; - -export class BootC { - readonly #extensionContext: ExtensionContext; - - constructor(readonly extensionContext: ExtensionContext) { - this.#extensionContext = extensionContext; - } - - public async activate(): Promise { - console.log('starting boot-c extension'); - } - - public async deactivate(): Promise { - console.log('stopping boot-c extension'); - } -} diff --git a/src/extension.spec.ts b/src/extension.spec.ts index 9dade514..7c129a41 100644 --- a/src/extension.spec.ts +++ b/src/extension.spec.ts @@ -18,12 +18,13 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { beforeEach, expect, test, vi } from 'vitest'; +import { afterEach, beforeEach, expect, test, vi } from 'vitest'; import type * as podmanDesktopApi from '@podman-desktop/api'; import { activate, deactivate } from './extension'; -const bootcActivateMock = vi.fn(); -const bootcDeactivateMock = vi.fn(); +/// mock console.log +const originalConsoleLog = console.log; +const consoleLogMock = vi.fn(); vi.mock('@podman-desktop/api', async () => { return { @@ -36,20 +37,16 @@ vi.mock('@podman-desktop/api', async () => { }; }); -vi.mock('./bootc', async () => { - return { - BootC: class { - public activate = bootcActivateMock; - public deactivate = bootcDeactivateMock; - }, - }; -}); - beforeEach(() => { vi.clearAllMocks(); + console.log = consoleLogMock; }); -test('check we call activate method on bootc ', async () => { +afterEach(() => { + console.log = originalConsoleLog; +}); + +test('check activate', async () => { const fakeContext = { subscriptions: { push: vi.fn(), @@ -58,19 +55,11 @@ test('check we call activate method on bootc ', async () => { await activate(fakeContext); - // expect the activate method to be called on the bootc class - expect(bootcActivateMock).toBeCalledTimes(1); - - // no call on deactivate - expect(bootcDeactivateMock).not.toBeCalled(); + expect(consoleLogMock).toBeCalledWith('starting bootc extension'); }); -test('check we call deactivate method on bootc ', async () => { +test('check deactivate', async () => { await deactivate(); - // expect the activate method to be called on the bootc class - expect(bootcDeactivateMock).toBeCalledTimes(1); - - // no call on activate - expect(bootcActivateMock).not.toBeCalled(); + expect(consoleLogMock).toBeCalledWith('stopping bootc extension'); }); diff --git a/src/extension.ts b/src/extension.ts index 5e8c9c05..10eb6d12 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -18,15 +18,11 @@ import type { ExtensionContext } from '@podman-desktop/api'; import * as extensionApi from '@podman-desktop/api'; -import { BootC } from './bootc'; import { launchVFKit } from './launch-vfkit'; import { buildDiskImage } from './build-disk-image'; -let bootc: BootC | undefined; - export async function activate(extensionContext: ExtensionContext): Promise { - bootc = new BootC(extensionContext); - await bootc?.activate(); + console.log('starting bootc extension'); extensionContext.subscriptions.push( extensionApi.commands.registerCommand('bootc.vfkit', async container => { @@ -40,5 +36,5 @@ export async function activate(extensionContext: ExtensionContext): Promise { - await bootc?.deactivate(); + console.log('stopping bootc extension'); }