Skip to content

Commit

Permalink
Fix missing font size difference calculation in console output. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed May 23, 2020
1 parent 442214c commit fb58286
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/subsetFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@ async function getSubsetsForFontUsage(
}

fontUsage.subsets[format] = fontAsset.rawSrc;
const size = fontAsset.rawSrc.length;
if (
!fontUsage.smallestSubsetSize ||
size < fontUsage.smallestSubsetSize
) {
fontUsage.smallestSubsetSize = size;
fontUsage.smallestSubsetFormat = format;
}
}
}
}
Expand Down
58 changes: 58 additions & 0 deletions test/subsetFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,64 @@ describe('subsetFonts', function() {
]);
});

it('should return relevant font subsetting information', async function() {
httpception(defaultGoogleFontSubsetMock);

const assetGraph = new AssetGraph({
root: pathModule.resolve(
__dirname,
'../testdata/subsetFonts/html-link/'
)
});
assetGraph.on('warn', warn =>
expect(warn, 'to satisfy', /Cannot find module/)
);
await assetGraph.loadAssets('index.html');
await assetGraph.populate({
followRelations: {
crossorigin: false
}
});
const result = await subsetFontsWithoutFontTools(assetGraph, {
inlineFonts: false
});

expect(result, 'to exhaustively satisfy', {
fontInfo: [
{
htmlAsset: 'testdata/subsetFonts/html-link/index.html',
fontUsages: [
{
smallestOriginalSize: 17704,
smallestOriginalFormat: 'woff',
smallestSubsetSize: 14048,
smallestSubsetFormat: 'woff2',
texts: ['Hello'],
pageText: 'Helo',
text: 'Helo',
props: {
'font-stretch': 'normal',
'font-weight': '400',
'font-style': 'normal',
'font-family': 'Open Sans',
src:
"local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFVZ0d.woff) format('woff')"
},
fontUrl:
'https://fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFVZ0d.woff',
fontFamilies: expect.it('to be a', Set),
codepoints: {
original: expect.it('to be an array'),
used: [101, 108, 111, 72],
unused: expect.it('to be an array')
}
}
]
}
]
});
});

describe('with `inlineCss: true`', function() {
it('should inline the font Css and change outgoing relations to rootRelative', async function() {
httpception(defaultGoogleFontSubsetMock);
Expand Down

0 comments on commit fb58286

Please sign in to comment.