mirror of
https://github.com/podman-desktop/podman-desktop
synced 2026-04-21 17:47:22 +00:00
* refactor(mock): generate @podman-desktop/api mock from its definition instead of writing for each function and for each namespace the content reuse the .d.ts definition and wire automatically vi.fn() customize/override some classes implementation manually but most of it is generated fixes https://github.com/podman-desktop/podman-desktop/issues/14493 Signed-off-by: Florent Benoit <fbenoit@redhat.com>
69 lines
2.3 KiB
Text
69 lines
2.3 KiB
Text
/**********************************************************************
|
|
* Copyright (C) 2026 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
|
|
***********************************************************************/
|
|
|
|
/* This file is auto-generated by a vitest globalSetup hook */
|
|
import { beforeEach, vi } from 'vitest';
|
|
|
|
import product from '../../product.json' with { type: 'json' };
|
|
|
|
const namespaceMocks = {} as Record<string, Record<string, unknown>>;
|
|
{{#namespaces}}
|
|
namespaceMocks.{{name}} = {};
|
|
{{#functions}}
|
|
namespaceMocks.{{name}}.{{.}} = vi.fn();
|
|
{{/functions}}
|
|
{{/namespaces}}
|
|
|
|
const classesMocks = {} as Record<string, unknown>;
|
|
{{#classes}}
|
|
const {{name}}Instance: Record<string, unknown> = {};
|
|
{{#methods}}
|
|
{{name}}Instance.{{.}} = vi.fn();
|
|
{{/methods}}
|
|
classesMocks.{{name}} = {{name}}Instance;
|
|
{{/classes}}
|
|
|
|
const eventEmitterListeners: Array<(data: unknown) => unknown> = [];
|
|
beforeEach(() => { eventEmitterListeners.length = 0; });
|
|
class EventEmitter {
|
|
event(callback: (e: unknown) => unknown): void { eventEmitterListeners.push(callback); }
|
|
fire(data: unknown): void { for (const listener of eventEmitterListeners) { listener(data); } }
|
|
dispose(): void {}
|
|
}
|
|
EventEmitter.prototype.dispose = vi.fn();
|
|
|
|
// Normalize env mock
|
|
if (!namespaceMocks.env) namespaceMocks.env = {};
|
|
namespaceMocks.env.isWindows = false;
|
|
namespaceMocks.env.isMac = false;
|
|
namespaceMocks.env.isLinux = false;
|
|
namespaceMocks.env.appName = product.name;
|
|
|
|
const extensionAPI = {
|
|
...namespaceMocks,
|
|
...classesMocks,
|
|
EventEmitter,
|
|
ProgressLocation: { APP_ICON: 1, TASK_WIDGET: 2 },
|
|
StatusBarAlignLeft: 'LEFT',
|
|
StatusBarAlignRight: 'RIGHT',
|
|
StatusBarItemDefaultPriority: 0,
|
|
InputBoxValidationSeverity: { Info: 1, Warning: 2, Error: 3 },
|
|
QuickPickItemKind: { Separator: -1, Default: 0 },
|
|
};
|
|
|
|
module.exports = extensionAPI;
|