Skip to content

Commit ba85f61

Browse files
committed
chore: broken tests
1 parent 6361c68 commit ba85f61

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/templates.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { hash } from 'ohash'
22
import type { ModuleOptions } from './module'
33
import { logger } from './logger'
44
import type { RegistryScript } from '#nuxt-scripts/types'
5-
import { useNuxt } from '@nuxt/kit'
5+
import { tryUseNuxt } from '@nuxt/kit'
66
import { relative } from 'pathe'
77

88
export function templatePlugin(config: Partial<ModuleOptions>, registry: Required<RegistryScript>[]) {
@@ -11,7 +11,8 @@ export function templatePlugin(config: Partial<ModuleOptions>, registry: Require
1111
config.globals = Object.fromEntries(config.globals.map(i => [hash(i), i]))
1212
logger.warn('The `globals` array option is deprecated, please convert to an object.')
1313
}
14-
const nuxt = useNuxt()
14+
// handles tests
15+
const nuxt = tryUseNuxt() || { options: { buildDir: import.meta.dirname }}
1516
const buildDir = nuxt.options.buildDir
1617
const imports = []
1718
const inits = []

test/unit/templates.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ describe('template plugin file', () => {
99
registry: {},
1010
}, [])
1111
expect(res).toMatchInlineSnapshot(`
12-
"import { useScript, defineNuxtPlugin } from '#imports'
12+
"import { useScript } from '#nuxt-scripts/composables/useScript'
13+
import { defineNuxtPlugin } from 'nuxt/app'
1314
1415
export default defineNuxtPlugin({
1516
name: "scripts:init",
@@ -84,7 +85,8 @@ describe('template plugin file', () => {
8485
},
8586
}, [])
8687
expect(res).toMatchInlineSnapshot(`
87-
"import { useScript, defineNuxtPlugin } from '#imports'
88+
"import { useScript } from '#nuxt-scripts/composables/useScript'
89+
import { defineNuxtPlugin } from 'nuxt/app'
8890
8991
export default defineNuxtPlugin({
9092
name: "scripts:init",

0 commit comments

Comments
 (0)