Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: run code coverage in github actions #11770

Merged
merged 27 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
56 changes: 56 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
sudo: required
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
language: node_js
branches:
only:
- master
matrix:
include:
- node_js: "12"
cache:
yarn: true
directories:
- node_modules
- lantern-data
- lighthouse-core/scripts/legacy-javascript/variants
- /home/travis/.rvm/gems/
install:
# Ensure we have the latest Chrome stable.
- google-chrome-stable --version
# We used to set PUPPETEER_SKIP_CHROMIUM_DOWNLOAD, but we don't want to anymore.
# Explicitly unset b/c environment variables seem to linger in travis.
# see https://github.com/GoogleChrome/lighthouse/pull/9877#discussion_r338389765
- unset PUPPETEER_SKIP_CHROMIUM_DOWNLOAD
- yarn --frozen-lockfile
before_script:
# see comment above about puppeteer
- export CHROME_PATH="$(which google-chrome-stable)"
# Print out the Chrome version so we know what we're working with
- google-chrome-stable --version
- yarn build-all
script:
- yarn diff:sample-json
- yarn lint
- yarn test-legacy-javascript
- yarn unit
- yarn type-check
- yarn smoke
- yarn test-clients
- yarn test-viewer
- yarn test-treemap
- yarn test-lantern
- yarn test-bundle
- yarn i18n:checks
- yarn dogfood-lhci
- yarn test-docs

# Fail if any changes were written to source files (ex, from: build/build-cdt-lib.js).
- git diff --exit-code
before_cache:
# nyc, jest and other projects store files in here. They mess up the travis build cache.
- rm -rf ./node_modules/.cache/
after_success:
- yarn coveralls
addons:
chrome: stable
services:
- xvfb
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
Loading