First working POC
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
// Mock for $app/environment
|
||||
export const browser = true;
|
||||
export const dev = false;
|
||||
export const building = false;
|
||||
export const version = "test";
|
||||
@@ -0,0 +1,11 @@
|
||||
// Mock for $app/navigation
|
||||
import { vi } from "vitest";
|
||||
|
||||
export const goto = vi.fn();
|
||||
export const invalidate = vi.fn();
|
||||
export const invalidateAll = vi.fn();
|
||||
export const preloadData = vi.fn();
|
||||
export const preloadCode = vi.fn();
|
||||
export const beforeNavigate = vi.fn();
|
||||
export const afterNavigate = vi.fn();
|
||||
export const disableScrollHandling = vi.fn();
|
||||
@@ -0,0 +1,19 @@
|
||||
// Mock for $app/stores
|
||||
import { writable, readable } from "svelte/store";
|
||||
|
||||
export const page = readable({
|
||||
url: new URL("http://localhost"),
|
||||
params: {},
|
||||
route: { id: "/" },
|
||||
status: 200,
|
||||
error: null,
|
||||
data: {},
|
||||
form: null,
|
||||
});
|
||||
|
||||
export const navigating = readable(null);
|
||||
|
||||
export const updated = {
|
||||
subscribe: readable(false).subscribe,
|
||||
check: async () => false,
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
// Global setup that runs before any other setup
|
||||
// This file must be loaded first to set up the window object
|
||||
|
||||
// Setup jsdom/happy-dom globals
|
||||
// The test environment should provide window and document
|
||||
if (typeof window !== "undefined") {
|
||||
// Setup Tauri internals on window
|
||||
Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: {
|
||||
platform: "linux",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Ensure document and window are available as globals (not just on globalThis)
|
||||
if (typeof globalThis !== "undefined") {
|
||||
if (typeof window !== "undefined" && !(global as any).window) {
|
||||
(global as any).window = window;
|
||||
}
|
||||
|
||||
if (typeof document !== "undefined" && !(global as any).document) {
|
||||
(global as any).document = document;
|
||||
}
|
||||
|
||||
// Also ensure they're on globalThis
|
||||
if (typeof window !== "undefined" && !globalThis.window) {
|
||||
(globalThis as any).window = window;
|
||||
}
|
||||
|
||||
if (typeof document !== "undefined" && !globalThis.document) {
|
||||
(globalThis as any).document = document;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Test setup file for Vitest
|
||||
|
||||
import { vi } from "vitest";
|
||||
|
||||
// Setup window.__TAURI_OS_PLUGIN_INTERNALS__ before any imports
|
||||
if (typeof window !== "undefined") {
|
||||
Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
value: {
|
||||
platform: "linux",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Mock SvelteKit environment
|
||||
vi.mock("$app/environment", () => ({
|
||||
browser: true,
|
||||
dev: false,
|
||||
building: false,
|
||||
version: "test",
|
||||
}));
|
||||
|
||||
// Mock Tauri API
|
||||
vi.mock("@tauri-apps/api/core", () => ({
|
||||
invoke: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock Tauri event API
|
||||
vi.mock("@tauri-apps/api/event", () => ({
|
||||
listen: vi.fn(),
|
||||
emit: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock Tauri OS plugin
|
||||
vi.mock("@tauri-apps/plugin-os", () => ({
|
||||
platform: vi.fn(() => "linux"),
|
||||
}));
|
||||
|
||||
// Setup global test utilities
|
||||
global.ResizeObserver = vi.fn().mockImplementation(() => ({
|
||||
observe: vi.fn(),
|
||||
unobserve: vi.fn(),
|
||||
disconnect: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock window.matchMedia
|
||||
Object.defineProperty(window, "matchMedia", {
|
||||
writable: true,
|
||||
value: vi.fn().mockImplementation((query) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
})),
|
||||
});
|
||||
Reference in New Issue
Block a user