This commit is contained in:
Jovan Krunić
2026-10-12 15:54:21 +02:00
parent 29e9d0753b
commit d1ef5731c7
8 changed files with 485 additions and 94 deletions
+64
View File
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2026 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*
* tsconfig.spec.json maps every `@capacitor/*` import to this folder, so this
* file replaces `@capacitor/core` in all tests – including the imports made by
* real Capacitor plugins (registerPlugin, WebPlugin, CapacitorHttp, …).
*
* Therefore everything is re-exported from the real package (imported via a
* relative path, which bypasses the path mapping) and only `Capacitor` is
* replaced by a controllable mock. The local export shadows the one from
* `export *`.
*/
export * from '../../node_modules/@capacitor/core';
type Platform = 'web' | 'ios' | 'android';
export class CapacitorMock {
private platform: Platform = 'web';
getPlatform(): Platform {
return this.platform;
}
isNativePlatform(): boolean {
return this.platform !== 'web';
}
isPluginAvailable(_name: string): boolean {
return this.isNativePlatform();
}
convertFileSrc(filePath: string): string {
return filePath;
}
/**
* Test helper: simulate running on the given platform.
*/
setPlatform(platform: Platform): void {
this.platform = platform;
}
/**
* Test helper: back to the default (web), call this in afterEach.
*/
reset(): void {
this.platform = 'web';
}
}
export const Capacitor = new CapacitorMock();