Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Feb 4, 2018
1 parent 9782386 commit 0d2f4a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lighthouse-core/audits/font-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FontDisplay extends Audit {
description: 'All text remains visible during webfont loads',
failureDescription: 'Avoid invisible text while webfonts are loading',
helpText: 'Leverage the font-display CSS feature to ensure text is user-visible while ' +
'webfonts are loading and avoid a FOIT.',
'webfonts are loading.',
requiredArtifacts: ['devtoolsLogs', 'Fonts'],
};
}
Expand Down
22 changes: 8 additions & 14 deletions lighthouse-core/gather/gatherers/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ const fontFaceDescriptors = [
];

/* eslint-env browser*/

/**
* Collect applied webfont data from `document.fonts`
* @param {string[]}
* @return {{}}
*/
function getAllLoadedFonts() {
/* istanbul ignore next */
function getAllLoadedFonts(descriptors) {
const getFont = fontFace => {
const fontRule = {};
fontFaceDescriptors.forEach(descriptor => {
descriptors.forEach(descriptor => {
fontRule[descriptor] = fontFace[descriptor];
});

Expand All @@ -43,6 +44,7 @@ function getAllLoadedFonts() {
* Collect authored webfont data from the `CSSFontFaceRule`s present in document.styleSheets
* @return {{}}
*/
/* istanbul ignore next */
function getFontFaceFromStylesheets() {
/**
* Get full data about each CSSFontFaceRule within a styleSheet object
Expand Down Expand Up @@ -126,12 +128,6 @@ function getFontFaceFromStylesheets() {
/* eslint-env node */

class Fonts extends Gatherer {
constructor() {
super();

this.stylesheetIds = [];
}

_findSameFontFamily(fontFace, fontFacesList) {
return fontFacesList.find(fontItem => {
return !fontFaceDescriptors.find(descriptor => {
Expand All @@ -144,11 +140,9 @@ class Fonts extends Gatherer {
return Promise.all(
[
driver.evaluateAsync(`(()=>{`
+ `const fontFaceDescriptors=JSON.parse('${JSON.stringify(fontFaceDescriptors)}');`
+ `return (${getAllLoadedFonts.toString()})();})()`),
driver.evaluateAsync(`(()=>{`
+ `const fontFaceDescriptors=JSON.parse('${JSON.stringify(fontFaceDescriptors)}');`
+ `return (${getFontFaceFromStylesheets.toString()})();})()`),
+ `const args = ${JSON.stringify(fontFaceDescriptors)};`
+ `return (${getAllLoadedFonts.toString()})(args);})()`),
driver.evaluateAsync(`(${getFontFaceFromStylesheets.toString()})()`),
]
).then(([loadedFonts, fontFaces]) => {
return loadedFonts.map(fontFace => {
Expand Down

0 comments on commit 0d2f4a3

Please sign in to comment.