Skip to content

Commit

Permalink
test: add additional provider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 8, 2024
1 parent 45c0e53 commit af07431
Show file tree
Hide file tree
Showing 5 changed files with 1,100 additions and 12 deletions.
20 changes: 8 additions & 12 deletions test/providers/adobe.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { createUnifont, providers } from '../../src'
import { pickUniqueBy } from '../utils'
import { pickUniqueBy, sanitizeFontSource } from '../utils'

describe('adobe', () => {
it('correctly types options for adobe provider', async () => {
Expand All @@ -15,27 +15,23 @@ describe('adobe', () => {
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(`
expect(sanitizeFontSource(aleo)).toMatchInlineSnapshot(`
[
{
"display": "auto",
"src": [
{
"format": "woff2",
"url": "<some-font-url>",
"url": "https://use.typekit.net/font",
},
{
"format": "woff",
"url": "<some-font-url>",
"url": "https://use.typekit.net/font",
},
{
"format": "opentype",
"url": "<some-font-url>",
"url": "https://use.typekit.net/font",
},
],
"style": "italic",
Expand All @@ -46,15 +42,15 @@ describe('adobe', () => {
"src": [
{
"format": "woff2",
"url": "<some-font-url>",
"url": "https://use.typekit.net/font",
},
{
"format": "woff",
"url": "<some-font-url>",
"url": "https://use.typekit.net/font",
},
{
"format": "opentype",
"url": "<some-font-url>",
"url": "https://use.typekit.net/font",
},
],
"style": "normal",
Expand Down
33 changes: 33 additions & 0 deletions test/providers/fontshare.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it } from 'vitest'
import { createUnifont, providers } from '../../src'
import { sanitizeFontSource } from '../utils'

describe('fontshare', () => {
it('works', async () => {
const unifont = await createUnifont([providers.fontshare()])
const { fonts } = await unifont.resolveFont('Satoshi')
expect(sanitizeFontSource(fonts)).toMatchInlineSnapshot(`
[
{
"display": "swap",
"src": [
{
"format": "woff2",
"url": "//cdn.fontshare.com/font",
},
{
"format": "woff",
"url": "//cdn.fontshare.com/font",
},
{
"format": "truetype",
"url": "//cdn.fontshare.com/font",
},
],
"style": "normal",
"weight": 400,
},
]
`)
})
})
Loading

0 comments on commit af07431

Please sign in to comment.