Skip to content

Commit

Permalink
chore: cleanup bootc.ts
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
deboer-tim committed Jan 19, 2024
1 parent 40cd556 commit d5aae24
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 123 deletions.
58 changes: 0 additions & 58 deletions src/bootc.spec.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/bootc.ts

This file was deleted.

37 changes: 13 additions & 24 deletions src/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand All @@ -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');
});
8 changes: 2 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
bootc = new BootC(extensionContext);
await bootc?.activate();
console.log('starting bootc extension');

extensionContext.subscriptions.push(
extensionApi.commands.registerCommand('bootc.vfkit', async container => {
Expand All @@ -40,5 +36,5 @@ export async function activate(extensionContext: ExtensionContext): Promise<void
}

export async function deactivate(): Promise<void> {
await bootc?.deactivate();
console.log('stopping bootc extension');
}

0 comments on commit d5aae24

Please sign in to comment.