Skip to content

Commit

Permalink
test: add test/example for custom providers
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 20, 2024
1 parent 79f9c58 commit 3dc5f54
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export default defineNuxtConfig({
modules: ['@nuxt/fonts', '@nuxtjs/tailwindcss'],
fonts: {
providers: {
custom: '~/providers/custom'
},
families: [
{ name: 'Kode Mono', provider: 'none' },
{ name: 'MyCustom', src: '/font.woff2' },
Expand Down
11 changes: 11 additions & 0 deletions playground/pages/providers/custom.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>
Local font
</div>
</template>

<style scoped>
div {
font-family: 'SomeFontFromCustomProvider', sans-serif;
}
</style>
19 changes: 19 additions & 0 deletions playground/providers/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// TODO: expose types publicly
import type { FontProvider } from '../../src/types'

const resolvableFonts = new Set<string>()
export default {
async setup () {
// Do some stuff
resolvableFonts.add('SomeFontFromCustomProvider')
},
async resolveFontFaces (fontFamily, _defaults) {
if (!resolvableFonts.has(fontFamily)) { return }
return {
fonts: {
src: '/some-font.woff2'
}
}
},
} satisfies FontProvider

13 changes: 13 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ describe('providers', async () => {
const html = await $fetch('/providers/none')
expect(extractFontFaces('CustomFont', html)).toMatchInlineSnapshot(`[]`)
})

it('should allow defining custom providers', async () => {
const html = await $fetch('/providers/custom')
expect(extractFontFaces('SomeFontFromCustomProvider', html)).toMatchInlineSnapshot(`
[
"@font-face {
font-family: 'SomeFontFromCustomProvider';
src: url("/some-font.woff2") format(woff2);
font-display: swap;
}",
]
`)
})
})

describe('features', () => {
Expand Down

0 comments on commit 3dc5f54

Please sign in to comment.