|
7 | 7 |
|
8 | 8 | /* eslint-env jest */
|
9 | 9 |
|
| 10 | +const os = require('os'); |
| 11 | +const fs = require('fs'); |
10 | 12 | const path = require('path');
|
| 13 | +const rimraf = require('rimraf'); |
11 | 14 | const {runCLI} = require('./test-utils.js');
|
12 | 15 |
|
13 | 16 | describe('Lighthouse CI healthcheck CLI', () => {
|
@@ -114,4 +117,70 @@ describe('Lighthouse CI healthcheck CLI', () => {
|
114 | 117 | expect(stderr).toMatchInlineSnapshot(`""`);
|
115 | 118 | });
|
116 | 119 | });
|
| 120 | + |
| 121 | + describe('chrome installation', () => { |
| 122 | + let fixtureDir; |
| 123 | + |
| 124 | + beforeEach(() => { |
| 125 | + fixtureDir = path.join(os.tmpdir(), fs.mkdtempSync('lhcihealthcheck')); |
| 126 | + fs.mkdirSync(fixtureDir, {recursive: true}); |
| 127 | + }); |
| 128 | + |
| 129 | + afterEach(() => { |
| 130 | + rimraf.sync(fixtureDir); |
| 131 | + }); |
| 132 | + |
| 133 | + it('should find a chrome installation installed on the system', () => { |
| 134 | + const {stdout, stderr, status} = runCLI(['healthcheck', '--fatal'], { |
| 135 | + cwd: fixtureDir, |
| 136 | + }); |
| 137 | + |
| 138 | + expect(stdout).toMatchInlineSnapshot(` |
| 139 | + "✅ .lighthouseci/ directory writable |
| 140 | + ⚠️ Configuration file not found |
| 141 | + ✅ Chrome installation found |
| 142 | + Healthcheck passed! |
| 143 | + " |
| 144 | + `); |
| 145 | + expect(stderr).toMatchInlineSnapshot(`""`); |
| 146 | + expect(status).toEqual(0); |
| 147 | + }); |
| 148 | + |
| 149 | + it('should not find a chrome installation when ignored', () => { |
| 150 | + const {stdout, stderr, status} = runCLI(['healthcheck', '--fatal'], { |
| 151 | + cwd: fixtureDir, |
| 152 | + env: {LHCITEST_IGNORE_CHROME_INSTALLATIONS: '1'}, |
| 153 | + }); |
| 154 | + |
| 155 | + expect(stdout).toMatchInlineSnapshot(` |
| 156 | + "✅ .lighthouseci/ directory writable |
| 157 | + ⚠️ Configuration file not found |
| 158 | + ❌ Chrome installation not found |
| 159 | + Healthcheck failed! |
| 160 | + " |
| 161 | + `); |
| 162 | + expect(stderr).toMatchInlineSnapshot(`""`); |
| 163 | + expect(status).toEqual(1); |
| 164 | + }); |
| 165 | + |
| 166 | + it('should find a chrome installation when ignored but passed explicitly via config', () => { |
| 167 | + const ci = {collect: {chromePath: fixtureDir}}; |
| 168 | + fs.writeFileSync(path.join(fixtureDir, '.lighthouserc.json'), JSON.stringify({ci})); |
| 169 | + |
| 170 | + const {stdout, stderr, status} = runCLI(['healthcheck', '--fatal'], { |
| 171 | + cwd: fixtureDir, |
| 172 | + env: {LHCI_NO_LIGHTHOUSERC: undefined, LHCITEST_IGNORE_CHROME_INSTALLATIONS: '1'}, |
| 173 | + }); |
| 174 | + |
| 175 | + expect(stdout).toMatchInlineSnapshot(` |
| 176 | + "✅ .lighthouseci/ directory writable |
| 177 | + ✅ Configuration file found |
| 178 | + ✅ Chrome installation found |
| 179 | + Healthcheck passed! |
| 180 | + " |
| 181 | + `); |
| 182 | + expect(stderr).toMatchInlineSnapshot(`""`); |
| 183 | + expect(status).toEqual(0); |
| 184 | + }); |
| 185 | + }); |
117 | 186 | });
|
0 commit comments