Skip to content

Commit 3dc5f54

Browse files
committed
test: add test/example for custom providers
1 parent 79f9c58 commit 3dc5f54

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

playground/nuxt.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
export default defineNuxtConfig({
22
modules: ['@nuxt/fonts', '@nuxtjs/tailwindcss'],
33
fonts: {
4+
providers: {
5+
custom: '~/providers/custom'
6+
},
47
families: [
58
{ name: 'Kode Mono', provider: 'none' },
69
{ name: 'MyCustom', src: '/font.woff2' },

playground/pages/providers/custom.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>
3+
Local font
4+
</div>
5+
</template>
6+
7+
<style scoped>
8+
div {
9+
font-family: 'SomeFontFromCustomProvider', sans-serif;
10+
}
11+
</style>

playground/providers/custom.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// TODO: expose types publicly
2+
import type { FontProvider } from '../../src/types'
3+
4+
const resolvableFonts = new Set<string>()
5+
export default {
6+
async setup () {
7+
// Do some stuff
8+
resolvableFonts.add('SomeFontFromCustomProvider')
9+
},
10+
async resolveFontFaces (fontFamily, _defaults) {
11+
if (!resolvableFonts.has(fontFamily)) { return }
12+
return {
13+
fonts: {
14+
src: '/some-font.woff2'
15+
}
16+
}
17+
},
18+
} satisfies FontProvider
19+

test/basic.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ describe('providers', async () => {
5353
const html = await $fetch('/providers/none')
5454
expect(extractFontFaces('CustomFont', html)).toMatchInlineSnapshot(`[]`)
5555
})
56+
57+
it('should allow defining custom providers', async () => {
58+
const html = await $fetch('/providers/custom')
59+
expect(extractFontFaces('SomeFontFromCustomProvider', html)).toMatchInlineSnapshot(`
60+
[
61+
"@font-face {
62+
font-family: 'SomeFontFromCustomProvider';
63+
src: url("/some-font.woff2") format(woff2);
64+
font-display: swap;
65+
}",
66+
]
67+
`)
68+
})
5669
})
5770

5871
describe('features', () => {

0 commit comments

Comments
 (0)