UNPKG

html-reporter

Version:

Html-reporter and GUI for viewing and managing results of a tests run. Currently supports Testplane and Hermione.

71 lines 2.27 kB
"use strict"; /** * The following is modified based on source found in * https://github.com/vitejs/vite and https://github.com/facebook/create-react-app * * MIT Licensed * Copyright (c) 2015-present, Facebook, Inc. * * Modified for use in html-reporter. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.openBrowser = void 0; const node_path_1 = __importDefault(require("node:path")); const node_child_process_1 = require("node:child_process"); const open_1 = __importDefault(require("open")); const supportedChromiumBrowsers = [ 'Google Chrome Canary', 'Google Chrome Dev', 'Google Chrome Beta', 'Google Chrome', 'Microsoft Edge', 'Brave Browser', 'Vivaldi', 'Chromium', 'Yandex' ]; async function openBrowser(url) { // If we're on macOS, we can try opening a Chromium browser with JXA. // This lets us reuse an existing tab when possible instead of creating a new one. if (process.platform === 'darwin') { try { const ps = await execAsync('ps cax'); const openedBrowser = supportedChromiumBrowsers.find((b) => ps.includes(b)); if (openedBrowser) { // Try our best to reuse existing tab with JXA await execAsync(`osascript openChrome.js "${url}" "${openedBrowser}"`, { cwd: node_path_1.default.join(__dirname) }); return true; } } catch { // Ignore errors, fall through to regular open } } // Fallback to open (will always open new tab) try { await (0, open_1.default)(url); return true; } catch { return false; } } exports.openBrowser = openBrowser; function execAsync(command, options) { return new Promise((resolve, reject) => { (0, node_child_process_1.exec)(command, options, (error, stdout) => { if (error) { reject(error); } else { resolve(stdout.toString()); } }); }); } //# sourceMappingURL=open-browser.js.map