UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

159 lines 5.34 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var runtime_exports = {}; __export(runtime_exports, { ScriptableRuntime: () => ScriptableRuntime, runtime: () => runtime }); module.exports = __toCommonJS(runtime_exports); var import_preferences = require("./preferences"); var import_registry = require("./registry"); var import_system = require("./system"); var import_runtime2 = require("./types/runtime"); const _ScriptableRuntime = class _ScriptableRuntime { constructor() { __publicField(this, "preferences"); if (_ScriptableRuntime.instance) { throw new Error("ScriptableRuntime is a singleton. Use ScriptableRuntime.getInstance()"); } this.preferences = import_preferences.Preferences.getInstance(); } /** * Get the singleton instance of ScriptableRuntime */ static getInstance() { if (!_ScriptableRuntime.instance) { _ScriptableRuntime.instance = new _ScriptableRuntime(); } return _ScriptableRuntime.instance; } /** * Configure runtime with preset or custom configuration * @param config Runtime configuration or preset name */ configure(config) { if (typeof config === "string") { const preset = import_runtime2.RuntimePresets[config]; if (!preset) { throw new Error(`Preset "${config}" not found`); } this.applyConfig(preset); } else { this.applyConfig(config); } } /** * Apply configuration to runtime * @param config Runtime configuration */ applyConfig(config) { if (config.device) { this.preferences.updateMock("device", config.device); } if (config.widget) { this.preferences.updateMock("config", config.widget); } if (config.script) { this.preferences.updateMock("script", config.script); } if (config.location) { this.preferences.updateMock("location", { currentLocation: config.location.currentLocation ?? { latitude: 0, longitude: 0, altitude: 0, horizontalAccuracy: 5, verticalAccuracy: 5 }, accuracy: config.location.accuracy ?? "best", simulatedDelay: config.location.simulatedDelay ?? 100 }); } } /** * Initialize the runtime and setup mocks * @throws Error if called while a test is running */ setupMocks() { this.assertTestNotRunning(); if (_ScriptableRuntime.isInitialized) { throw new Error("ScriptableRuntime is already initialized. Call clearMocks() first."); } import_registry.GlobalMockManager.initialize(); this.preferences.reset(); _ScriptableRuntime.isInitialized = true; _ScriptableRuntime.isTestRunning = true; } /** * Clear all mocks and reset the runtime state * @throws Error if called while no test is running */ clearMocks() { import_system.SystemState.reset(); this.preferences.reset(); import_registry.GlobalMockManager.clear(); _ScriptableRuntime.isInitialized = false; _ScriptableRuntime.isTestRunning = false; } assertTestNotRunning() { if (_ScriptableRuntime.isTestRunning) { throw new Error("A test is currently running. Call clearMocks() before starting a new test."); } } // #region UI State Shortcuts get isDarkMode() { return this.preferences.get().device.appearance?.isUsingDarkAppearance ?? false; } set isDarkMode(value) { this.preferences.updateMock("device", { appearance: { isUsingDarkAppearance: value } }); } get widgetFamily() { return this.preferences.get().config.widgetFamily ?? "small"; } set widgetFamily(value) { this.preferences.updateMock("config", { widgetFamily: value }); } get alertResponse() { return this.preferences.get().device.alertResponse; } set alertResponse(value) { this.preferences.updateMock("device", { alertResponse: value }); } // #endregion }; __publicField(_ScriptableRuntime, "instance"); __publicField(_ScriptableRuntime, "isInitialized", false); __publicField(_ScriptableRuntime, "isTestRunning", false); let ScriptableRuntime = _ScriptableRuntime; const runtime = ScriptableRuntime.getInstance(); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ScriptableRuntime, runtime }); //# sourceMappingURL=runtime.js.map