forked from jantimon/iconfont-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(icons-to-woff.js): enforce deterministic output
Ensure builds with the same set of inputs results in an identical font hash for deterministic builds. re jantimon#53
- Loading branch information
1 parent
0de5bd2
commit ad9e583
Showing
3 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
/* eslint max-len: off, quotes:off, arrow-parens:off */ | ||
import createIconFont from '../lib/icons-to-woff.js'; | ||
import fs from 'fs'; | ||
import test from 'ava'; | ||
|
||
test('should throw an error when an svg cannot be found', async (t) => { | ||
let error; | ||
try { | ||
await createIconFont(fs, [ | ||
'./test/fixtures/does-not-exist.svg' | ||
], { | ||
name: 'test' | ||
}); | ||
} catch (e) { | ||
error = e.message; | ||
} | ||
|
||
t.is(error.substring(0, 33), 'ENOENT: no such file or directory'); | ||
t.pass(); | ||
}); | ||
|
||
test('should throw an error when a malformed svg is provided', async (t) => { | ||
let error; | ||
try { | ||
await createIconFont(fs, [ | ||
'./test/fixtures/malformed.svg' | ||
], { | ||
name: 'test' | ||
}); | ||
} catch (e) { | ||
error = e.message; | ||
} | ||
|
||
t.is(error.substring(0, 32), 'Non-whitespace before first tag.'); | ||
t.pass(); | ||
}); | ||
|
||
test('should produce the same output when receiving the same input and configuration', async (t) => { | ||
const svgs = [ | ||
'./test/fixtures/account-494x512.svg', | ||
'./test/fixtures/account-986x1024.svg' | ||
]; | ||
|
||
const test1 = await createIconFont(fs, svgs, { | ||
name: 'test' | ||
}); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
const test2 = await createIconFont(fs, svgs, { | ||
name: 'test' | ||
}); | ||
|
||
t.is(test1, test2); | ||
t.pass(); | ||
}); | ||
|
||
test('should produce different output when receiving the same input but different fontHeight', async (t) => { | ||
const svgs = [ | ||
'./test/fixtures/account-494x512.svg', | ||
'./test/fixtures/account-986x1024.svg' | ||
]; | ||
|
||
const test1 = await createIconFont(fs, svgs, { | ||
enforcedSvgHeight: 32 | ||
}); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
const test2 = await createIconFont(fs, svgs, { | ||
enforcedSvgHeight: 16 | ||
}); | ||
|
||
t.not(test1, test2); | ||
t.pass(); | ||
}); |