UNPKG

homebridge-tsvesync

Version:

Homebridge plugin for VeSync devices including Levoit air purifiers, humidifiers, and Etekcity smart outlets

82 lines 3.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.resetApiUrl = exports.skipWithoutCredentials = exports.canRunIntegrationTests = exports.TEST_CONFIG = void 0; const dotenv_1 = __importDefault(require("dotenv")); const path_1 = __importDefault(require("path")); const helpers_1 = require("tsvesync/src/lib/helpers"); // Load test environment variables const envPath = path_1.default.resolve(__dirname, '../../.env.test'); if (process.env.DEBUG) { console.log('Loading environment variables from:', envPath); } const result = dotenv_1.default.config({ path: envPath }); if (process.env.DEBUG) { if (result.error) { console.log('Error loading .env.test:', result.error); } else { console.log('Environment variables loaded:', { VESYNC_TEST_USERNAME: process.env.VESYNC_TEST_USERNAME, VESYNC_TEST_PASSWORD: process.env.VESYNC_TEST_PASSWORD ? '***' : undefined, VESYNC_API_URL: process.env.VESYNC_API_URL, }); } } // Helper to check if a string is not empty or commented out const isValidEnvVar = (value) => { return !!value && !value.startsWith('#'); }; // Set API URL if provided in environment variables const apiUrl = process.env.VESYNC_API_URL; if (process.env.DEBUG) { console.log('API URL from env:', apiUrl); } if (isValidEnvVar(apiUrl)) { if (process.env.DEBUG) { console.log('Setting API URL to:', apiUrl); } (0, helpers_1.setApiBaseUrl)(apiUrl); } exports.TEST_CONFIG = { username: isValidEnvVar(process.env.VESYNC_TEST_USERNAME) ? process.env.VESYNC_TEST_USERNAME : undefined, password: isValidEnvVar(process.env.VESYNC_TEST_PASSWORD) ? process.env.VESYNC_TEST_PASSWORD : undefined, apiUrl: isValidEnvVar(process.env.VESYNC_API_URL) ? process.env.VESYNC_API_URL : undefined, }; if (process.env.DEBUG) { console.log('Test config:', { hasUsername: !!exports.TEST_CONFIG.username, hasPassword: !!exports.TEST_CONFIG.password, apiUrl: exports.TEST_CONFIG.apiUrl, username: exports.TEST_CONFIG.username, password: exports.TEST_CONFIG.password ? '***' : undefined, }); } // Helper to check if we can run integration tests const canRunIntegrationTests = () => { const canRun = !!(exports.TEST_CONFIG.username && exports.TEST_CONFIG.password); if (process.env.DEBUG) { console.log('Can run integration tests:', canRun); } return canRun; }; exports.canRunIntegrationTests = canRunIntegrationTests; // Helper to skip tests that require real credentials const skipWithoutCredentials = () => { if (!(0, exports.canRunIntegrationTests)()) { return test.skip; } return test; }; exports.skipWithoutCredentials = skipWithoutCredentials; // Export a function to reset API URL for mocked tests const resetApiUrl = () => { if (process.env.DEBUG) { console.log('Resetting API URL to default'); } (0, helpers_1.setApiBaseUrl)('https://smartapi.vesync.com'); }; exports.resetApiUrl = resetApiUrl; //# sourceMappingURL=setup.js.map