Skip to content

Commit

Permalink
chore: disable module when head as function (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Jul 21, 2023
1 parent ed83ab8 commit 4630b75
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ export default defineNuxtModule<ModuleOptions>({
// @ts-ignore
const head = (nuxt.options.app.head || nuxt.options.head) as NuxtAppHead

// disable module when head is a function
if (typeof head === 'function') {
logger.warn('This module does not work with `head` as function.')

return
}

// merge fonts from valid head link
fontsParsed.push(...head.link
.filter(link => isValidURL(String(link.href)))
Expand Down
30 changes: 30 additions & 0 deletions test/disable.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, test, expect, vi, afterAll } from 'vitest'
import { setup } from '@nuxt/test-utils'

describe('disable', async () => {
const spyStderr = vi.spyOn(process.stderr, 'write').mockImplementation(() => undefined!)

afterAll(() => {
spyStderr.mockRestore()
})

await setup({
nuxtConfig: {
app: {
// @ts-ignore
head: () => {}
},
googleFonts: {
families: {
Roboto: true
}
}
}
})

test('should warn if head as function', () => {
expect(spyStderr).toBeCalledTimes(1)
const output = spyStderr.mock.calls[0][0].toString()
expect(output).contains('[warn] [nuxt:google-fonts] This module does not work with `head` as function.')
})
})

0 comments on commit 4630b75

Please sign in to comment.