UNPKG

@web/test-runner-browserstack

Version:
46 lines 1.96 kB
"use strict"; /** * Manages browserstack-local instance, making sure there is only one per * instance set up for all browser launchers. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.unregisterBrowserstackLocal = exports.registerBrowserstackLocal = exports.localId = void 0; const browserstack_local_1 = __importDefault(require("browserstack-local")); const util_1 = require("util"); const nanoid_1 = require("nanoid"); const launchers = new Set(); let connection = undefined; exports.localId = `web-test-runner-${(0, nanoid_1.nanoid)()}`; async function setupLocalConnection(password, options = {}) { process.on('SIGINT', closeLocalConnection); process.on('SIGTERM', closeLocalConnection); process.on('beforeExit', closeLocalConnection); process.on('exit', closeLocalConnection); connection = new browserstack_local_1.default.Local(); console.log('[Browserstack] Setting up Browserstack Local proxy...'); await (0, util_1.promisify)(connection.start).bind(connection)(Object.assign({ key: password, force: true, localIdentifier: exports.localId }, options)); } function closeLocalConnection() { if (connection && connection.pid != null) { process.kill(connection.pid); connection = undefined; } } async function registerBrowserstackLocal(launcher, password, options = {}) { launchers.add(launcher); if (!connection) { await setupLocalConnection(password, options); } } exports.registerBrowserstackLocal = registerBrowserstackLocal; function unregisterBrowserstackLocal(launcher) { launchers.delete(launcher); if (connection && launchers.size === 0) { closeLocalConnection(); } } exports.unregisterBrowserstackLocal = unregisterBrowserstackLocal; //# sourceMappingURL=browserstackManager.js.map