Skip to content

Commit

Permalink
fix: remove hoist from test (#84)
Browse files Browse the repository at this point in the history
Signed-off-by: lstocchi <lstocchi@redhat.com>
  • Loading branch information
lstocchi authored Jul 25, 2024
1 parent 52c33f4 commit aa1534f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
22 changes: 7 additions & 15 deletions src/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ import type { MinikubeInstaller } from './minikube-installer';
import * as fs from 'node:fs';
import * as path from 'node:path';

const { config } = vi.hoisted(() => {
return {
config: {
get: vi.fn(),
has: vi.fn(),
update: vi.fn(),
},
};
});

vi.mock('@podman-desktop/api', async () => {
return {
window: {
Expand All @@ -52,7 +42,7 @@ vi.mock('@podman-desktop/api', async () => {
isLinux: vi.fn(),
},
configuration: {
getConfiguration: (): extensionApi.Configuration => config,
getConfiguration: vi.fn(),
},
ProgressLocation: {
APP_ICON: 1,
Expand All @@ -73,9 +63,13 @@ vi.mock('node:fs', async () => {
});

const originalProcessEnv = process.env;
const configGetMock = vi.fn();
beforeEach(() => {
vi.resetAllMocks();
process.env = {};
vi.mocked(extensionApi.configuration.getConfiguration).mockReturnValue({
get: configGetMock,
} as unknown as extensionApi.Configuration);
});

afterEach(() => {
Expand Down Expand Up @@ -103,8 +97,7 @@ test('getMinikubeHome with empty configuration property', async () => {
const existingConfigHome = '';
process.env.MINIKUBE_HOME = existingEnvHome;

const spyGetConfiguration = vi.spyOn(config, 'get');
spyGetConfiguration.mockReturnValue(existingConfigHome);
configGetMock.mockReturnValue(existingConfigHome);

const computedHome = getMinikubeHome();

Expand All @@ -117,8 +110,7 @@ test('getMinikubeHome with empty configuration property', async () => {
const existingConfigHome = '/my-another-existing-minikube-home';
process.env.MINIKUBE_HOME = existingEnvHome;

const spyGetConfiguration = vi.spyOn(config, 'get');
spyGetConfiguration.mockReturnValue(existingConfigHome);
configGetMock.mockReturnValue(existingConfigHome);

const computedHome = getMinikubeHome();

Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export interface RunOptions {
logger?: extensionApi.Logger;
}

const minikubeConfiguration = extensionApi.configuration.getConfiguration('minikube');
const macosExtraPath = '/usr/local/bin:/opt/homebrew/bin:/opt/local/bin:/opt/podman/bin';

export function getMinikubePath(): string {
Expand All @@ -50,6 +49,7 @@ export function getMinikubePath(): string {
}

export function getMinikubeHome(): string | undefined {
const minikubeConfiguration = extensionApi.configuration.getConfiguration('minikube');
const minikubeHome = minikubeConfiguration.get<string>('home');
// Check env if configuration is not applied in UI
if (!minikubeHome) {
Expand Down

0 comments on commit aa1534f

Please sign in to comment.