Adam Raine | bf8654c | 2022-09-13 13:24:07 -0700 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import {assert} from 'chai'; |
| 6 | |
| 7 | import {expectError} from '../../conductor/events.js'; |
| 8 | import {getBrowserAndPages} from '../../shared/helper.js'; |
| 9 | import {describe, it} from '../../shared/mocha-extensions.js'; |
| 10 | import { |
| 11 | clickStartButton, |
| 12 | getAuditsBreakdown, |
| 13 | navigateToLighthouseTab, |
| 14 | selectMode, |
| 15 | waitForResult, |
| 16 | } from '../helpers/lighthouse-helpers.js'; |
| 17 | |
| 18 | // This test will fail (by default) in headful mode, as the target page never gets painted. |
| 19 | // To resolve this when debugging, just make sure the target page is visible during the lighthouse run. |
| 20 | |
| 21 | describe('Snapshot', async function() { |
| 22 | // The tests in this suite are particularly slow |
| 23 | this.timeout(60_000); |
| 24 | |
| 25 | beforeEach(() => { |
| 26 | // https://bugs.chromium.org/p/chromium/issues/detail?id=1357791 |
| 27 | expectError(/Protocol Error: the message with wrong session id/); |
| 28 | expectError(/Protocol Error: the message with wrong session id/); |
| 29 | expectError(/Protocol Error: the message with wrong session id/); |
| 30 | expectError(/Protocol Error: the message with wrong session id/); |
| 31 | expectError(/Protocol Error: the message with wrong session id/); |
| 32 | }); |
| 33 | |
| 34 | it('successfully returns a Lighthouse report for the page state', async () => { |
| 35 | await navigateToLighthouseTab('lighthouse/hello.html'); |
| 36 | |
| 37 | const {target} = await getBrowserAndPages(); |
| 38 | await target.evaluate(() => { |
| 39 | const makeTextFieldBtn = document.querySelector('button'); |
| 40 | if (!makeTextFieldBtn) { |
| 41 | throw new Error('Button not found'); |
| 42 | } |
| 43 | makeTextFieldBtn.click(); |
| 44 | makeTextFieldBtn.click(); |
| 45 | makeTextFieldBtn.click(); |
| 46 | }); |
| 47 | |
| 48 | await selectMode('snapshot'); |
| 49 | await clickStartButton(); |
| 50 | |
| 51 | const {lhr, artifacts, reportEl} = await waitForResult(); |
| 52 | |
| 53 | assert.strictEqual(lhr.gatherMode, 'snapshot'); |
| 54 | |
Adam Raine | 4515db6 | 2022-09-28 16:37:20 -0700 | [diff] [blame^] | 55 | assert.deepStrictEqual(artifacts.ViewportDimensions, { |
| 56 | innerHeight: 640, |
| 57 | innerWidth: 360, |
| 58 | outerHeight: 640, |
| 59 | outerWidth: 360, |
| 60 | devicePixelRatio: 3, |
| 61 | }); |
Adam Raine | bf8654c | 2022-09-13 13:24:07 -0700 | [diff] [blame] | 62 | |
| 63 | const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr); |
| 64 | assert.strictEqual(auditResults.length, 73); |
| 65 | assert.strictEqual(erroredAudits.length, 0); |
| 66 | assert.deepStrictEqual(failedAudits.map(audit => audit.id), [ |
Adam Raine | bf8654c | 2022-09-13 13:24:07 -0700 | [diff] [blame] | 67 | 'document-title', |
| 68 | 'html-has-lang', |
| 69 | 'label', |
| 70 | 'meta-description', |
Adam Raine | bf8654c | 2022-09-13 13:24:07 -0700 | [diff] [blame] | 71 | 'tap-targets', |
| 72 | ]); |
| 73 | |
| 74 | // These a11y violations are not present on initial page load. |
| 75 | assert.strictEqual(lhr.audits['label'].details.items.length, 3); |
| 76 | |
| 77 | // No trace was collected in snapshot mode. |
| 78 | const viewTrace = await reportEl.$('.lh-button--trace'); |
| 79 | assert.strictEqual(viewTrace, null); |
| 80 | }); |
| 81 | }); |