From 19f17bab1a21c57da9265e2bbde678127cd41c81 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Thu, 6 Mar 2025 11:06:57 +0100 Subject: [PATCH 1/4] improve get info --- lib/command/info.js | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/command/info.js b/lib/command/info.js index e0abe2433..769bb5166 100644 --- a/lib/command/info.js +++ b/lib/command/info.js @@ -4,22 +4,56 @@ const { getConfig, getTestRoot } = require('./utils') const Codecept = require('../codecept') const output = require('../output') +async function getInstalledBrowsers() { + try { + const playwright = require('playwright') + const browsers = await Promise.all( + ['chromium', 'firefox', 'webkit'].map(async browser => { + try { + const browserInstance = await playwright[browser].launch() + const version = await browserInstance.version() + await browserInstance.close() + return `${browser}: ${version}` + } catch (err) { + return `${browser}: not installed` + } + }), + ) + return browsers.join(`, `) + } catch (err) { + return 'Playwright not installed' + } +} + +async function getOsBrowsers() { + const chromeInfo = await envinfo.helpers.getChromeInfo() + const edgeInfo = await envinfo.helpers.getEdgeInfo() + const firefoxInfo = await envinfo.helpers.getFirefoxInfo() + const safariInfo = await envinfo.helpers.getSafariInfo() + + return [ + `chrome: ${chromeInfo ? chromeInfo[1] : 'not installed'}`, + `edge: ${edgeInfo ? edgeInfo[1] : 'not installed'}`, + `firefox: ${firefoxInfo ? firefoxInfo[1] : 'not installed'}`, + `safari: ${safariInfo ? safariInfo[1] : 'not installed'}`, + ].join(', ') +} + module.exports = async function (path) { const testsPath = getTestRoot(path) const config = getConfig(testsPath) const codecept = new Codecept(config, {}) codecept.init(testsPath) - output.print('\n Environment information:-\n') + output.print('\n Environment information: \n') const info = {} info.codeceptVersion = Codecept.version() info.nodeInfo = await envinfo.helpers.getNodeInfo() info.osInfo = await envinfo.helpers.getOSInfo() info.cpuInfo = await envinfo.helpers.getCPUInfo() - info.chromeInfo = await envinfo.helpers.getChromeInfo() - info.edgeInfo = await envinfo.helpers.getEdgeInfo() - info.firefoxInfo = await envinfo.helpers.getFirefoxInfo() - info.safariInfo = await envinfo.helpers.getSafariInfo() + info.osBrowsers = await getOsBrowsers() + info.playwrightBrowsers = await getInstalledBrowsers() + const { helpers, plugins } = config info.helpers = helpers || "You don't use any helpers" info.plugins = plugins || "You don't have any enabled plugins" @@ -47,6 +81,7 @@ module.exports.getMachineInfo = async () => { edgeInfo: await envinfo.helpers.getEdgeInfo(), firefoxInfo: await envinfo.helpers.getFirefoxInfo(), safariInfo: await envinfo.helpers.getSafariInfo(), + playwrightBrowsers: await getInstalledBrowsers(), } output.print('***************************************') From b77cb82bf603d2f50aacb9e53eb5acb38f5fd90b Mon Sep 17 00:00:00 2001 From: kobenguyent <7845001+kobenguyent@users.noreply.github.com> Date: Thu, 6 Mar 2025 11:13:58 +0100 Subject: [PATCH 2/4] Update lib/command/info.js Co-authored-by: Michael Bodnarchuk --- lib/command/info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command/info.js b/lib/command/info.js index 769bb5166..bc5848b27 100644 --- a/lib/command/info.js +++ b/lib/command/info.js @@ -4,7 +4,7 @@ const { getConfig, getTestRoot } = require('./utils') const Codecept = require('../codecept') const output = require('../output') -async function getInstalledBrowsers() { +async function getPlaywrightBrowsers() { try { const playwright = require('playwright') const browsers = await Promise.all( From d3d245dbdce49a7ceede143901c7b396189a25e2 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Tue, 11 Mar 2025 06:02:38 +0100 Subject: [PATCH 3/4] improve code --- lib/command/info.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/command/info.js b/lib/command/info.js index 769bb5166..368682d19 100644 --- a/lib/command/info.js +++ b/lib/command/info.js @@ -3,23 +3,24 @@ const envinfo = require('envinfo') const { getConfig, getTestRoot } = require('./utils') const Codecept = require('../codecept') const output = require('../output') +const { execSync } = require('child_process') async function getInstalledBrowsers() { try { - const playwright = require('playwright') - const browsers = await Promise.all( - ['chromium', 'firefox', 'webkit'].map(async browser => { - try { - const browserInstance = await playwright[browser].launch() - const version = await browserInstance.version() - await browserInstance.close() - return `${browser}: ${version}` - } catch (err) { - return `${browser}: not installed` - } - }), - ) - return browsers.join(`, `) + const regex = /(chromium|firefox|webkit)\s+version\s+([\d.]+)/gi + let versions = [] + + const info = execSync('npx playwright install --dry-run').toString().trim() + + const matches = [...info.matchAll(regex)] + + matches.forEach(match => { + const browser = match[1] + const version = match[2] + versions.push(`${browser}: ${version}`) + }) + + return versions.join(', ') } catch (err) { return 'Playwright not installed' } From a41ddbd8f18c3db2b02337b67dada3e9dfb42f73 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Tue, 11 Mar 2025 06:05:34 +0100 Subject: [PATCH 4/4] fix: wrong func name --- lib/command/info.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/command/info.js b/lib/command/info.js index c9ca2cc3e..05dff5bf9 100644 --- a/lib/command/info.js +++ b/lib/command/info.js @@ -53,7 +53,7 @@ module.exports = async function (path) { info.osInfo = await envinfo.helpers.getOSInfo() info.cpuInfo = await envinfo.helpers.getCPUInfo() info.osBrowsers = await getOsBrowsers() - info.playwrightBrowsers = await getInstalledBrowsers() + info.playwrightBrowsers = await getPlaywrightBrowsers() const { helpers, plugins } = config info.helpers = helpers || "You don't use any helpers" @@ -82,7 +82,7 @@ module.exports.getMachineInfo = async () => { edgeInfo: await envinfo.helpers.getEdgeInfo(), firefoxInfo: await envinfo.helpers.getFirefoxInfo(), safariInfo: await envinfo.helpers.getSafariInfo(), - playwrightBrowsers: await getInstalledBrowsers(), + playwrightBrowsers: await getPlaywrightBrowsers(), } output.print('***************************************')