Skip to content

Commit b8d2bbd

Browse files
committed
chore: populate global mock of the extension API
it will allow to avoid per test mocking for global declaration related to podman-desktop#14493 Signed-off-by: Florent Benoit <fbenoit@redhat.com>
1 parent 5cd3e56 commit b8d2bbd

File tree

1 file changed

+145
-2
lines changed
  • __mocks__/@podman-desktop

1 file changed

+145
-2
lines changed

__mocks__/@podman-desktop/api.js

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************
2-
* Copyright (C) 2022 Red Hat, Inc.
2+
* Copyright (C) 2022-2025 Red Hat, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,9 +16,152 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19+
import { vi, beforeEach } from 'vitest';
20+
1921
/**
2022
* Mock the extension API for vitest.
2123
* This file is referenced from vitest.config.js file.
2224
*/
23-
const plugin = {};
25+
26+
const cli = {
27+
createCliTool: vi.fn(),
28+
};
29+
30+
const commands = {
31+
registerCommand: vi.fn(),
32+
};
33+
34+
const configuration = {
35+
onDidChangeConfiguration: vi.fn(),
36+
getConfiguration: vi.fn(),
37+
};
38+
39+
const containerEngine = {
40+
info: vi.fn(),
41+
listContainers: vi.fn(),
42+
saveImage: vi.fn(),
43+
onEvent: vi.fn(),
44+
};
45+
46+
const context = {
47+
setValue: vi.fn(),
48+
};
49+
50+
const env = {
51+
createTelemetryLogger: vi.fn(),
52+
openExternal: vi.fn(),
53+
54+
isLinux: false,
55+
isWindows: false,
56+
isMac: false,
57+
};
58+
59+
const kubernetes = {
60+
createResources: vi.fn(),
61+
getKubeconfig: vi.fn(),
62+
onDidUpdateKubeconfig: vi.fn(),
63+
};
64+
65+
const net = {
66+
getFreePort: vi.fn(),
67+
};
68+
69+
const process = {
70+
exec: vi.fn(),
71+
};
72+
73+
const eventEmitterListeners = [];
74+
75+
const extensions = {
76+
getExtension: vi.fn(),
77+
};
78+
79+
const proxy = {
80+
isEnabled: vi.fn(),
81+
onDidUpdateProxy: vi.fn(),
82+
onDidStateChange: vi.fn(),
83+
getProxySettings: vi.fn(),
84+
};
85+
86+
const provider = {
87+
createProvider: vi.fn(),
88+
onDidRegisterContainerConnection: vi.fn(),
89+
onDidUnregisterContainerConnection: vi.fn(),
90+
onDidUpdateProvider: vi.fn(),
91+
onDidUpdateContainerConnection: vi.fn(),
92+
onDidUpdateVersion: vi.fn(),
93+
registerUpdate: vi.fn(),
94+
getContainerConnections: vi.fn(),
95+
};
96+
97+
const registry = {
98+
registerRegistryProvider: vi.fn(),
99+
registerRegistry: vi.fn(),
100+
unregisterRegistry: vi.fn(),
101+
onDidRegisterRegistry: vi.fn(),
102+
onDidUnregisterRegistry: vi.fn(),
103+
onDidUpdateRegistry: vi.fn(),
104+
suggestRegistry: vi.fn(),
105+
};
106+
107+
const window = {
108+
showInformationMessage: vi.fn(),
109+
showErrorMessage: vi.fn(),
110+
withProgress: vi.fn(),
111+
showNotification: vi.fn(),
112+
showWarningMessage: vi.fn(),
113+
114+
showQuickPick: vi.fn(),
115+
showInputBox: vi.fn(),
116+
createStatusBarItem: vi.fn(),
117+
};
118+
119+
const Disposable = { from: vi.fn(), dispose: vi.fn() };
120+
121+
class EventEmitter {
122+
event(callback) {
123+
eventEmitterListeners.push(callback);
124+
}
125+
126+
fire(data) {
127+
eventEmitterListeners.forEach(listener => listener(data));
128+
}
129+
130+
dispose() {}
131+
}
132+
133+
const ProgressLocation = {
134+
APP_ICON: 1,
135+
TASK_WIDGET: 2,
136+
};
137+
138+
const Uri = {
139+
parse: vi.fn(),
140+
};
141+
142+
const plugin = {
143+
cli,
144+
commands,
145+
configuration,
146+
containerEngine,
147+
context,
148+
env,
149+
extensions,
150+
kubernetes,
151+
net,
152+
process,
153+
provider,
154+
proxy,
155+
registry,
156+
window,
157+
Disposable,
158+
EventEmitter,
159+
ProgressLocation,
160+
Uri,
161+
};
162+
163+
beforeEach(() => {
164+
eventEmitterListeners.length = 0;
165+
});
166+
24167
module.exports = plugin;

0 commit comments

Comments
 (0)