Skip to content

Commit

Permalink
tests: run code coverage in github actions (#11770)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored and paulirish committed Mar 23, 2021
1 parent fb41e60 commit f5ed5ff
Show file tree
Hide file tree
Showing 24 changed files with 276 additions and 441 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ jobs:
if: matrix.os == 'ubuntu-latest'

- name: yarn unit
run: xvfb-run --auto-servernum yarn unit
run: xvfb-run --auto-servernum yarn unit:cicoverage
if: matrix.os == 'ubuntu-latest'
- name: Upload test coverage to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@6004246
with:
flags: unit
file: ./unit-coverage.lcov

# For windows, just test the potentially platform-specific code.
- name: yarn unit-cli
Expand Down Expand Up @@ -164,7 +170,14 @@ jobs:

- run: sudo apt-get install xvfb
- name: Run smoke tests
run: xvfb-run --auto-servernum yarn smoke --debug -j=1 --retries=2 --invert-match ${{ matrix.smoke-test-invert }} $SMOKE_GROUP_1
run: xvfb-run --auto-servernum yarn smoke:cicoverage --debug -j=1 --retries=2 --invert-match ${{ matrix.smoke-test-invert }} $SMOKE_GROUP_1

- name: Upload test coverage to Codecov
if: matrix.chrome-channel == 'ToT'
uses: codecov/codecov-action@6004246
with:
flags: smoke
file: ./smoke-coverage.lcov

# Fail if any changes were written to source files.
- run: git diff --exit-code
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Fetcher {
/**
* @param {string} src
*/
/* istanbul ignore next */
/* c8 ignore start */
function injectIframe(src) {
/** @type {HTMLIFrameElement} */
const iframe = document.createElement('iframe');
Expand All @@ -161,6 +161,7 @@ class Fetcher {
};
document.body.appendChild(iframe);
}
/* c8 ignore stop */

/** @type {NodeJS.Timeout} */
let timeoutHandle;
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const pageFunctions = require('../../lib/page-functions.js');
* containing any violations.
* @return {Promise<LH.Artifacts.Accessibility>}
*/
/* istanbul ignore next */
/* c8 ignore start */
async function runA11yChecks() {
/** @type {import('axe-core/axe')} */
// @ts-expect-error axe defined by axeLibSource
Expand Down Expand Up @@ -96,6 +96,7 @@ async function runA11yChecks() {
version: axeResults.testEngine.version,
};
}
/* c8 ignore stop */

/**
* @implements {LH.Gatherer.GathererInstance}
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/anchor-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const pageFunctions = require('../../lib/page-functions.js');
*
* @return {LH.Artifacts['AnchorElements']}
*/
/* istanbul ignore next */
/* c8 ignore start */
function collectAnchorElements() {
/** @param {string} url */
const resolveURLOrEmpty = url => {
Expand Down Expand Up @@ -71,6 +71,7 @@ function collectAnchorElements() {
};
});
}
/* c8 ignore stop */

/**
* @param {LH.Gatherer.PassContext['driver']} driver
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/cache-contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Gatherer = require('./gatherer.js');
* This is run in the page, not Lighthouse itself.
* @return {Promise<Array<string>>}
*/
/* istanbul ignore next */
/* c8 ignore start */
function getCacheContents() {
// Get every cache by name.
return caches.keys()
Expand All @@ -36,6 +36,7 @@ function getCacheContents() {
});
});
}
/* c8 ignore stop */

class CacheContents extends Gatherer {
/**
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/dobetterweb/domstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const pageFunctions = require('../../../lib/page-functions.js');
* @param {boolean=} deep True to include shadow roots. Defaults to true.
* @return {LH.Artifacts.DOMStats}
*/
/* istanbul ignore next */
/* c8 ignore start */
function getDOMStats(element = document.body, deep = true) {
let deepestElement = null;
let maxDepth = -1;
Expand Down Expand Up @@ -74,6 +74,7 @@ function getDOMStats(element = document.body, deep = true) {
totalBodyElements: result.numElements,
};
}
/* c8 ignore stop */

class DOMStats extends Gatherer {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const pageFunctions = require('../../../lib/page-functions.js');
/**
* @return {LH.Artifacts['PasswordInputsWithPreventedPaste']}
*/
/* istanbul ignore next */
/* c8 ignore start */
function findPasswordInputsWithPreventedPaste() {
return Array.from(document.querySelectorAll('input[type="password"]'))
.filter(passwordInput =>
Expand All @@ -27,6 +27,7 @@ function findPasswordInputsWithPreventedPaste() {
node: getNodeDetails(passwordInput),
}));
}
/* c8 ignore stop */

class PasswordInputsWithPreventedPaste extends Gatherer {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Gatherer = require('../gatherer.js');
/** @typedef {{tagName: 'SCRIPT', url: string, src: string}} ScriptTag */
/** @typedef {import('../../driver.js')} Driver */

/* istanbul ignore next */
/* c8 ignore start */
function installMediaListener() {
// @ts-expect-error - inserted in page to track media changes.
window.___linkMediaChanges = [];
Expand All @@ -47,11 +47,12 @@ function installMediaListener() {
},
});
}
/* c8 ignore stop */

/**
* @return {Promise<Array<LinkTag | ScriptTag>>}
*/
/* istanbul ignore next */
/* c8 ignore start */
async function collectTagsThatBlockFirstPaint() {
/** @type {Array<MediaChange>} */
// @ts-expect-error - `___linkMediaChanges` created in `installMediaListener`.
Expand Down Expand Up @@ -112,6 +113,7 @@ async function collectTagsThatBlockFirstPaint() {
throw new Error(`${friendly}: ${e.message}`);
}
}
/* c8 ignore stop */

class TagsBlockingFirstPaint extends Gatherer {
/**
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/form-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const pageFunctions = require('../../lib/page-functions.js');
/**
* @return {LH.Artifacts['FormElements']}
*/
/* istanbul ignore next */
/* c8 ignore start */
function collectFormElements() {
// @ts-expect-error - put into scope via stringification
const formChildren = getElementsInDocument('textarea, input, label, select'); // eslint-disable-line no-undef
Expand Down Expand Up @@ -82,6 +82,7 @@ function collectFormElements() {
}
return [...forms.values()];
}
/* c8 ignore stop */

class FormElements extends Gatherer {
/**
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/iframe-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const pageFunctions = require('../../lib/page-functions.js');
/**
* @return {LH.Artifacts['IFrameElements']}
*/
/* istanbul ignore next */
/* c8 ignore start */
function collectIFrameElements() {
// @ts-expect-error - put into scope via stringification
const iFrameElements = getElementsInDocument('iframe'); // eslint-disable-line no-undef
Expand All @@ -33,6 +33,7 @@ function collectIFrameElements() {
};
});
}
/* c8 ignore stop */

class IFrameElements extends Gatherer {
/**
Expand Down
18 changes: 12 additions & 6 deletions lighthouse-core/gather/gatherers/image-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const FontSize = require('./seo/font-size.js');
/* global window, getElementsInDocument, Image, getNodeDetails, ShadowRoot */

/** @param {Element} element */
/* istanbul ignore next */
/* c8 ignore start */
function getClientRect(element) {
const clientRect = element.getBoundingClientRect();
return {
Expand All @@ -28,27 +28,29 @@ function getClientRect(element) {
right: clientRect.right,
};
}
/* c8 ignore stop */

/**
* If an image is within `picture`, the `picture` element's css position
* is what we want to collect, since that position is relevant to CLS.
* @param {Element} element
* @param {CSSStyleDeclaration} computedStyle
*/
/* istanbul ignore next */
/* c8 ignore start */
function getPosition(element, computedStyle) {
if (element.parentElement && element.parentElement.tagName === 'PICTURE') {
const parentStyle = window.getComputedStyle(element.parentElement);
return parentStyle.getPropertyValue('position');
}
return computedStyle.getPropertyValue('position');
}
/* c8 ignore stop */

/**
* @param {Array<Element>} allElements
* @return {Array<LH.Artifacts.ImageElement>}
*/
/* istanbul ignore next */
/* c8 ignore start */
function getHTMLImages(allElements) {
const allImageElements = /** @type {Array<HTMLImageElement>} */ (allElements.filter(element => {
return element.localName === 'img';
Expand Down Expand Up @@ -84,12 +86,13 @@ function getHTMLImages(allElements) {
};
});
}
/* c8 ignore stop */

/**
* @param {Array<Element>} allElements
* @return {Array<LH.Artifacts.ImageElement>}
*/
/* istanbul ignore next */
/* c8 ignore start */
function getCSSImages(allElements) {
// Chrome normalizes background image style from getComputedStyle to be an absolute URL in quotes.
// Only match basic background-image: url("http://host/image.jpeg") declarations
Expand Down Expand Up @@ -130,21 +133,23 @@ function getCSSImages(allElements) {

return images;
}
/* c8 ignore stop */

/** @return {Array<LH.Artifacts.ImageElement>} */
/* istanbul ignore next */
/* c8 ignore start */
function collectImageElementInfo() {
/** @type {Array<Element>} */
// @ts-expect-error - added by getElementsInDocumentFnString
const allElements = getElementsInDocument();
return getHTMLImages(allElements).concat(getCSSImages(allElements));
}
/* c8 ignore stop */

/**
* @param {string} url
* @return {Promise<{naturalWidth: number, naturalHeight: number}>}
*/
/* istanbul ignore next */
/* c8 ignore start */
function determineNaturalSize(url) {
return new Promise((resolve, reject) => {
const img = new Image();
Expand All @@ -159,6 +164,7 @@ function determineNaturalSize(url) {
img.src = url;
});
}
/* c8 ignore stop */

/**
* @param {Partial<Pick<LH.Crdp.CSS.CSSStyle, 'cssProperties'>>|undefined} rule
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/link-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function getCrossoriginFromHeader(value) {
/**
* @return {LH.Artifacts['LinkElements']}
*/
/* istanbul ignore next */
/* c8 ignore start */
function getLinkElementsInDOM() {
/** @type {Array<HTMLOrSVGElement>} */
// @ts-expect-error - getElementsInDocument put into scope via stringification
Expand Down Expand Up @@ -77,6 +77,7 @@ function getLinkElementsInDOM() {

return linkElements;
}
/* c8 ignore stop */

class LinkElements extends Gatherer {
/**
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/meta-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const pageFunctions = require('../../lib/page-functions.js');

/* globals getElementsInDocument */

/* istanbul ignore next */
/* c8 ignore start */
function collectMetaElements() {
// @ts-expect-error - getElementsInDocument put into scope via stringification
const metas = /** @type {HTMLMetaElement[]} */ (getElementsInDocument('head meta'));
Expand All @@ -30,6 +30,7 @@ function collectMetaElements() {
};
});
}
/* c8 ignore stop */

class MetaElements extends Gatherer {
/**
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/script-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const pageFunctions = require('../../lib/page-functions.js');
/**
* @return {LH.Artifacts['ScriptElements']}
*/
/* istanbul ignore next */
/* c8 ignore start */
function collectAllScriptElements() {
/** @type {HTMLScriptElement[]} */
// @ts-expect-error - getElementsInDocument put into scope via stringification
Expand All @@ -36,6 +36,7 @@ function collectAllScriptElements() {
};
});
}
/* c8 ignore stop */

/**
* @template T, U
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gatherers/seo/robots-txt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Gatherer = require('../gatherer.js');
/* global fetch, URL, location */

/** @return {Promise<LH.Artifacts['RobotsTxt']>} */
/* istanbul ignore next */
/* c8 ignore start */
async function getRobotsTxtContent() {
try {
const response = await fetch(new URL('/robots.txt', location.href).href);
Expand All @@ -24,6 +24,7 @@ async function getRobotsTxtContent() {
return {status: null, content: null};
}
}
/* c8 ignore stop */


class RobotsTxt extends Gatherer {
Expand Down
Loading

0 comments on commit f5ed5ff

Please sign in to comment.