|
| 1 | +let expect |
| 2 | +import('chai').then(chai => { |
| 3 | + expect = chai.expect |
| 4 | +}) |
| 5 | + |
| 6 | +const { parsePlaywrightBrowsers } = require('../../../lib/command/info') |
| 7 | + |
| 8 | +describe('info command', () => { |
| 9 | + describe('parsePlaywrightBrowsers', () => { |
| 10 | + describe('old format (Playwright < 1.58)', () => { |
| 11 | + const oldFormatOutput = `browser: chromium version 140.0.7339.186 |
| 12 | +browser: chromium-headless-shell version 140.0.7339.186 |
| 13 | +browser: firefox version 141.0 |
| 14 | +browser: webkit version 26.0` |
| 15 | + |
| 16 | + it('should parse chromium version', () => { |
| 17 | + const result = parsePlaywrightBrowsers(oldFormatOutput) |
| 18 | + expect(result).to.include('chromium: 140.0.7339.186') |
| 19 | + }) |
| 20 | + |
| 21 | + it('should parse firefox version', () => { |
| 22 | + const result = parsePlaywrightBrowsers(oldFormatOutput) |
| 23 | + expect(result).to.include('firefox: 141.0') |
| 24 | + }) |
| 25 | + |
| 26 | + it('should parse webkit version', () => { |
| 27 | + const result = parsePlaywrightBrowsers(oldFormatOutput) |
| 28 | + expect(result).to.include('webkit: 26.0') |
| 29 | + }) |
| 30 | + |
| 31 | + it('should exclude chromium-headless-shell', () => { |
| 32 | + const result = parsePlaywrightBrowsers(oldFormatOutput) |
| 33 | + expect(result).to.not.include('chromium-headless-shell') |
| 34 | + }) |
| 35 | + |
| 36 | + it('should return all three browsers', () => { |
| 37 | + const result = parsePlaywrightBrowsers(oldFormatOutput) |
| 38 | + expect(result).to.equal('chromium: 140.0.7339.186, firefox: 141.0, webkit: 26.0') |
| 39 | + }) |
| 40 | + }) |
| 41 | + |
| 42 | + describe('new format (Playwright 1.58+)', () => { |
| 43 | + const newFormatOutput = `Chrome for Testing 145.0.7632.6 (playwright chromium v1208) |
| 44 | +Chromium Headless Shell 145.0.7632.6 (playwright build v1208) |
| 45 | +Firefox 146.0.1 (playwright firefox v1509) |
| 46 | +Webkit 18.4 (playwright webkit v2140)` |
| 47 | + |
| 48 | + it('should parse chromium version', () => { |
| 49 | + const result = parsePlaywrightBrowsers(newFormatOutput) |
| 50 | + expect(result).to.include('chromium: 145.0.7632.6') |
| 51 | + }) |
| 52 | + |
| 53 | + it('should parse firefox version', () => { |
| 54 | + const result = parsePlaywrightBrowsers(newFormatOutput) |
| 55 | + expect(result).to.include('firefox: 146.0.1') |
| 56 | + }) |
| 57 | + |
| 58 | + it('should parse webkit version', () => { |
| 59 | + const result = parsePlaywrightBrowsers(newFormatOutput) |
| 60 | + expect(result).to.include('webkit: 18.4') |
| 61 | + }) |
| 62 | + |
| 63 | + it('should exclude Chromium Headless Shell', () => { |
| 64 | + const result = parsePlaywrightBrowsers(newFormatOutput) |
| 65 | + expect(result).to.not.include('Headless') |
| 66 | + }) |
| 67 | + |
| 68 | + it('should return all three browsers', () => { |
| 69 | + const result = parsePlaywrightBrowsers(newFormatOutput) |
| 70 | + expect(result).to.equal('chromium: 145.0.7632.6, firefox: 146.0.1, webkit: 18.4') |
| 71 | + }) |
| 72 | + }) |
| 73 | + |
| 74 | + describe('mixed/edge cases', () => { |
| 75 | + it('should handle empty input', () => { |
| 76 | + const result = parsePlaywrightBrowsers('') |
| 77 | + expect(result).to.equal('') |
| 78 | + }) |
| 79 | + |
| 80 | + it('should handle input with no matching browsers', () => { |
| 81 | + const result = parsePlaywrightBrowsers('some random text without browser info') |
| 82 | + expect(result).to.equal('') |
| 83 | + }) |
| 84 | + |
| 85 | + it('should handle case insensitivity for old format', () => { |
| 86 | + const input = 'browser: CHROMIUM version 100.0.0' |
| 87 | + const result = parsePlaywrightBrowsers(input) |
| 88 | + expect(result).to.equal('CHROMIUM: 100.0.0') |
| 89 | + }) |
| 90 | + |
| 91 | + it('should handle case insensitivity for new format', () => { |
| 92 | + const input = 'Chrome 100.0.0 (playwright CHROMIUM v1234)' |
| 93 | + const result = parsePlaywrightBrowsers(input) |
| 94 | + expect(result).to.equal('CHROMIUM: 100.0.0') |
| 95 | + }) |
| 96 | + }) |
| 97 | + }) |
| 98 | +}) |
0 commit comments