Skip to content

Commit 98adfee

Browse files
cli: improve get info (#4890)
* improve get info * Update lib/command/info.js Co-authored-by: Michael Bodnarchuk <[email protected]> * improve code * fix: wrong func name --------- Co-authored-by: Michael Bodnarchuk <[email protected]>
1 parent fe767d8 commit 98adfee

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

lib/command/info.js

+41-5
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,58 @@ const envinfo = require('envinfo')
33
const { getConfig, getTestRoot } = require('./utils')
44
const Codecept = require('../codecept')
55
const output = require('../output')
6+
const { execSync } = require('child_process')
7+
8+
async function getPlaywrightBrowsers() {
9+
try {
10+
const regex = /(chromium|firefox|webkit)\s+version\s+([\d.]+)/gi
11+
let versions = []
12+
13+
const info = execSync('npx playwright install --dry-run').toString().trim()
14+
15+
const matches = [...info.matchAll(regex)]
16+
17+
matches.forEach(match => {
18+
const browser = match[1]
19+
const version = match[2]
20+
versions.push(`${browser}: ${version}`)
21+
})
22+
23+
return versions.join(', ')
24+
} catch (err) {
25+
return 'Playwright not installed'
26+
}
27+
}
28+
29+
async function getOsBrowsers() {
30+
const chromeInfo = await envinfo.helpers.getChromeInfo()
31+
const edgeInfo = await envinfo.helpers.getEdgeInfo()
32+
const firefoxInfo = await envinfo.helpers.getFirefoxInfo()
33+
const safariInfo = await envinfo.helpers.getSafariInfo()
34+
35+
return [
36+
`chrome: ${chromeInfo ? chromeInfo[1] : 'not installed'}`,
37+
`edge: ${edgeInfo ? edgeInfo[1] : 'not installed'}`,
38+
`firefox: ${firefoxInfo ? firefoxInfo[1] : 'not installed'}`,
39+
`safari: ${safariInfo ? safariInfo[1] : 'not installed'}`,
40+
].join(', ')
41+
}
642

743
module.exports = async function (path) {
844
const testsPath = getTestRoot(path)
945
const config = getConfig(testsPath)
1046
const codecept = new Codecept(config, {})
1147
codecept.init(testsPath)
1248

13-
output.print('\n Environment information:-\n')
49+
output.print('\n Environment information: \n')
1450
const info = {}
1551
info.codeceptVersion = Codecept.version()
1652
info.nodeInfo = await envinfo.helpers.getNodeInfo()
1753
info.osInfo = await envinfo.helpers.getOSInfo()
1854
info.cpuInfo = await envinfo.helpers.getCPUInfo()
19-
info.chromeInfo = await envinfo.helpers.getChromeInfo()
20-
info.edgeInfo = await envinfo.helpers.getEdgeInfo()
21-
info.firefoxInfo = await envinfo.helpers.getFirefoxInfo()
22-
info.safariInfo = await envinfo.helpers.getSafariInfo()
55+
info.osBrowsers = await getOsBrowsers()
56+
info.playwrightBrowsers = await getPlaywrightBrowsers()
57+
2358
const { helpers, plugins } = config
2459
info.helpers = helpers || "You don't use any helpers"
2560
info.plugins = plugins || "You don't have any enabled plugins"
@@ -47,6 +82,7 @@ module.exports.getMachineInfo = async () => {
4782
edgeInfo: await envinfo.helpers.getEdgeInfo(),
4883
firefoxInfo: await envinfo.helpers.getFirefoxInfo(),
4984
safariInfo: await envinfo.helpers.getSafariInfo(),
85+
playwrightBrowsers: await getPlaywrightBrowsers(),
5086
}
5187

5288
output.print('***************************************')

0 commit comments

Comments
 (0)