-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
53 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
This file was deleted.
Oops, something went wrong.
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,78 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { createUnifont, providers } from '../../src' | ||
import { pickUniqueBy } from '../utils' | ||
|
||
describe('adobe', () => { | ||
it('correctly types options for adobe provider', async () => { | ||
providers.adobe({ id: [] }) | ||
// @ts-expect-error options must be provided | ||
providers.adobe() | ||
|
||
expect(true).toBe(true) | ||
}) | ||
|
||
it('works', async () => { | ||
const unifont = await createUnifont([providers.adobe({ id: ['sij5ufr', 'grx7wdj'] })]) | ||
|
||
const { fonts: aleo } = await unifont.resolveFont('Aleo') | ||
const normalised = aleo.map(f => ({ | ||
...f, | ||
src: f.src.map(s => ({ ...s, url: 'url' in s ? s.url.replace(/https:\/\/use\.typekit\.net\/.*$/, '<some-font-url>') : undefined })), | ||
})) | ||
|
||
expect(normalised).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"display": "auto", | ||
"src": [ | ||
{ | ||
"format": "woff2", | ||
"url": "<some-font-url>", | ||
}, | ||
{ | ||
"format": "woff", | ||
"url": "<some-font-url>", | ||
}, | ||
{ | ||
"format": "opentype", | ||
"url": "<some-font-url>", | ||
}, | ||
], | ||
"style": "italic", | ||
"weight": 400, | ||
}, | ||
{ | ||
"display": "auto", | ||
"src": [ | ||
{ | ||
"format": "woff2", | ||
"url": "<some-font-url>", | ||
}, | ||
{ | ||
"format": "woff", | ||
"url": "<some-font-url>", | ||
}, | ||
{ | ||
"format": "opentype", | ||
"url": "<some-font-url>", | ||
}, | ||
], | ||
"style": "normal", | ||
"weight": 400, | ||
}, | ||
] | ||
`) | ||
|
||
const weights = ['400'] | ||
const styles = ['italic'] as Array<'italic'> | ||
|
||
const barlow = await unifont.resolveFont('Barlow Semi Condensed', { weights, styles, subsets: [] }).then(r => r.fonts) | ||
|
||
const resolvedStyles = pickUniqueBy(barlow, fnt => fnt.style) | ||
const resolvedWeights = pickUniqueBy(barlow, fnt => String(fnt.weight)) | ||
|
||
expect(barlow).toHaveLength(1) | ||
expect(resolvedStyles).toMatchObject(styles) | ||
expect(resolvedWeights).toMatchObject(weights) | ||
}) | ||
}) |
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,9 @@ | ||
// Quick and dirty way to pick into a new array, not needed if the test is un-necessary | ||
export function pickUniqueBy<T, K>(arr: T[], by: (arg: T) => K): K[] { | ||
return [...arr.reduce((acc, fnt) => { | ||
const prop = by(fnt) | ||
if (!acc.has(prop)) | ||
acc.add(prop) | ||
return acc | ||
}, new Set<K>())] | ||
} |