Skip to content

Commit

Permalink
fix: do not skip transforms on test files
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Dec 1, 2023
1 parent cbd5616 commit 3bbcc1e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions examples/app-vitest-full/tests/nuxt/mock-component-3.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, it } from 'vitest'
import { mockComponent, mountSuspended } from '@nuxt/test-utils/runtime-utils'
import { SomeComponent } from '#components'

mockComponent('SomeComponent', async () => {
const { h } = await import('vue')
return {
setup() {
return () => h('div', null, 'Mocked')
},
}
})

it('should mock', async () => {
const component = await mountSuspended(SomeComponent)
expect(component.html()).toMatchInlineSnapshot(`"<div>Mocked</div>"`)
})
10 changes: 9 additions & 1 deletion src/module/mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Unimport } from 'unimport'
import { addVitePlugin, useNuxt } from '@nuxt/kit'
import { addVitePlugin, isIgnored, resolveIgnorePatterns, useNuxt } from '@nuxt/kit'

Check failure on line 2 in src/module/mock.ts

View workflow job for this annotation

GitHub Actions / lint

'isIgnored' is defined but never used. Allowed unused vars must match /^_/u

import { createMockPlugin } from './plugins/mock'
import type { MockPluginContext } from './plugins/mock'
Expand Down Expand Up @@ -28,5 +28,13 @@ export function setupImportMocking () {
ctx.components = _
})

// We want to run Nuxt plugins on test files
nuxt.options.ignore = nuxt.options.ignore.filter(i => i !== '**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}')
if (nuxt._ignore) {
for (const pattern of resolveIgnorePatterns('**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}')) {
nuxt._ignore.add(`!${pattern}`)
}
}

addVitePlugin(createMockPlugin(ctx).vite())
}

0 comments on commit 3bbcc1e

Please sign in to comment.