Skip to content

Commit

Permalink
feat: Merge pull request #114 from tancredi/predictable-font-builds
Browse files Browse the repository at this point in the history
Predictable builds
  • Loading branch information
tancredi committed Feb 8, 2021
2 parents a6c5b91 + ea4ad73 commit 8aca974
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/generators/asset-types/__tests__/ttf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ describe('`TTF` font generator', () => {
const result = await ttfGen.generate(mockOptions(), svg);

expect(svg2ttf).toHaveBeenCalledTimes(1);
expect(svg2ttf).toHaveBeenCalledWith(svg, { __mock: 'options__' });
expect(svg2ttf).toHaveBeenCalledWith(svg, {
ts: 0,
__mock: 'options__'
});
expect(result).toEqual(Buffer.from(`::ttf(${svg})::`));
});

test('passes correctly format options to `svg2ttf`', async () => {
test('passes correctly format options to `svg2ttf` and sets `ts` (timestamp) to `0` by default to avoid generating unnecessary diffs', async () => {
const formatOptions = { foo: 'bar' };
await ttfGen.generate(mockOptions(formatOptions), svg);

expect(svg2ttf).toHaveBeenCalledTimes(1);
expect(svg2ttf.mock.calls[0][1]).toEqual(formatOptions);
expect(svg2ttf.mock.calls[0][1]).toEqual({ ts: 0, ...formatOptions });
});
});
2 changes: 1 addition & 1 deletion src/generators/asset-types/ttf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const generator: FontGenerator<string> = {
dependsOn: FontAssetType.SVG,

async generate({ formatOptions }, svg) {
const font = svg2ttf(svg, formatOptions?.ttf);
const font = svg2ttf(svg, { ts: 0, ...(formatOptions?.ttf || {}) });
return Buffer.from(font.buffer);
}
};
Expand Down

0 comments on commit 8aca974

Please sign in to comment.