diff --git a/jest.config.js b/jest.config.js index 5a24edef..89c35180 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,6 @@ module.exports = { moduleFileExtensions: ['js', 'mjs', 'ts'], - collectCoverageFrom: ['src/runtime/**/*.{js,ts}', '!src/**/*.d.ts'], + collectCoverageFrom: ['src/runtime/**/*.{js,ts}', '!src/**/*.d.ts', '!src/runtime/plugin.ts'], moduleNameMapper: { '^@/(.*)': '/$1', '#app': '/node_modules/nuxt/dist/app/index.mjs', diff --git a/src/runtime/plugin-impl.ts b/src/runtime/plugin-impl.ts new file mode 100644 index 00000000..e5a53daa --- /dev/null +++ b/src/runtime/plugin-impl.ts @@ -0,0 +1,27 @@ +import { computed } from 'vue'; +import { useHead } from '#head'; + +export default (nuxtApp) => { + const mixin = { + created() { + if (typeof this.$options?.jsonld !== 'function') { + return; + } + const jsonComputed = computed(() => this.$options.jsonld.call(this)); + useHead(() => ({ + script: [ + { + type: 'application/ld+json', + children: jsonComputed.value ? JSON.stringify(jsonComputed.value, null, '') : undefined, + }, + ], + })); + }, + }; + const plugin = { + install(Vue) { + Vue.mixin(mixin); + }, + }; + nuxtApp.vueApp.use(plugin); +}; diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index 1b0c7ca1..3257af67 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -1,28 +1,4 @@ -import { computed } from 'vue'; import { defineNuxtPlugin } from '#app'; -import { useHead } from '#head'; +import plugin from './plugin-impl'; -export default defineNuxtPlugin((nuxtApp) => { - const mixin = { - created() { - if (typeof this.$options?.jsonld !== 'function') { - return; - } - const jsonComputed = computed(() => this.$options.jsonld.call(this)); - useHead(() => ({ - script: [ - { - type: 'application/ld+json', - children: jsonComputed.value ? JSON.stringify(jsonComputed.value, null, '') : undefined, - }, - ], - })); - }, - }; - const plugin = { - install(Vue) { - Vue.mixin(mixin); - }, - }; - nuxtApp.vueApp.use(plugin); -}); +export default defineNuxtPlugin(plugin); diff --git a/test/plugin.spec.js b/test/plugin.spec.js index 3b11ad7d..77d03f66 100644 --- a/test/plugin.spec.js +++ b/test/plugin.spec.js @@ -1,4 +1,4 @@ -import plugin from '../src/runtime/plugin'; +import plugin from '../src/runtime/plugin-impl'; let useHeadArg = undefined; jest.mock('#head', () => ({