|
| 1 | +'use strict'; |
| 2 | +/* eslint max-len: off, quotes:off, arrow-parens:off */ |
| 3 | +import createIconFont from '../lib/icons-to-woff.js'; |
| 4 | +import fs from 'fs'; |
| 5 | +import test from 'ava'; |
| 6 | + |
| 7 | +test('should throw an error when an svg cannot be found', async (t) => { |
| 8 | + let error; |
| 9 | + try { |
| 10 | + await createIconFont(fs, [ |
| 11 | + './test/fixtures/does-not-exist.svg' |
| 12 | + ], { |
| 13 | + name: 'test' |
| 14 | + }); |
| 15 | + } catch (e) { |
| 16 | + error = e.message; |
| 17 | + } |
| 18 | + |
| 19 | + t.is(error.substring(0, 33), 'ENOENT: no such file or directory'); |
| 20 | + t.pass(); |
| 21 | +}); |
| 22 | + |
| 23 | +test('should throw an error when no glyph name is provided', async (t) => { |
| 24 | + let error; |
| 25 | + try { |
| 26 | + await createIconFont(fs, [ |
| 27 | + './test/fixtures/malformed.svg' |
| 28 | + ], { |
| 29 | + name: 'test' |
| 30 | + }); |
| 31 | + } catch (e) { |
| 32 | + error = e.message; |
| 33 | + } |
| 34 | + |
| 35 | + t.is(error.substring(0, 32), 'Non-whitespace before first tag.'); |
| 36 | + t.pass(); |
| 37 | +}); |
| 38 | + |
| 39 | +test('should produce the same output when receiving the same input and configuration', async (t) => { |
| 40 | + const svgs = [ |
| 41 | + './test/fixtures/account-494x512.svg', |
| 42 | + './test/fixtures/account-986x1024.svg' |
| 43 | + ]; |
| 44 | + |
| 45 | + const test1 = await createIconFont(fs, svgs, { |
| 46 | + name: 'test' |
| 47 | + }); |
| 48 | + |
| 49 | + await new Promise((resolve) => setTimeout(resolve, 1000)); |
| 50 | + |
| 51 | + const test2 = await createIconFont(fs, svgs, { |
| 52 | + name: 'test' |
| 53 | + }); |
| 54 | + |
| 55 | + t.is(test1, test2); |
| 56 | + t.pass(); |
| 57 | +}); |
| 58 | + |
| 59 | +test('should produce different output when receiving the same input but different fontHeight', async (t) => { |
| 60 | + const svgs = [ |
| 61 | + './test/fixtures/account-494x512.svg', |
| 62 | + './test/fixtures/account-986x1024.svg' |
| 63 | + ]; |
| 64 | + |
| 65 | + const test1 = await createIconFont(fs, svgs, { |
| 66 | + enforcedSvgHeight: 32 |
| 67 | + }); |
| 68 | + |
| 69 | + await new Promise((resolve) => setTimeout(resolve, 1000)); |
| 70 | + |
| 71 | + const test2 = await createIconFont(fs, svgs, { |
| 72 | + enforcedSvgHeight: 16 |
| 73 | + }); |
| 74 | + |
| 75 | + t.not(test1, test2); |
| 76 | + t.pass(); |
| 77 | +}); |
0 commit comments