[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-vitest. An vitest environment with support for testing code that needs a Nuxt runtime environment
nuxt nuxt-module testing unit-testing vitest
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: update

Anthony Fu (Jul 17, 2023, 3:18 PM +0200) f6e44d34 0059d348

+9 -1
+9 -1
packages/vitest-environment-nuxt/src/modules/mock.ts
··· 53 53 components = _ 54 54 }) 55 55 56 + // Polyfill Array.prototype.findLastIndex for legacy Node.js 57 + function findLastIndex<T>(arr: T[], predicate: (item: T) => boolean) { 58 + for (let i = arr.length - 1; i >= 0; i--) { 59 + if (predicate(arr[i])) return i 60 + } 61 + return -1 62 + } 63 + 56 64 addVitePlugin({ 57 65 name: PLUGIN_NAME, 58 66 enforce: 'post', ··· 61 69 const plugins = (config.plugins || []) as Plugin[] 62 70 // `vite:mocks` was a typo in Vitest before v0.34.0 63 71 const mockPluginIndex = plugins.findIndex(i => i.name === 'vite:mocks' || i.name === 'vitest:mocks') 64 - const lastNuxt = plugins.findLastIndex(i => i.name?.startsWith('nuxt:')) 72 + const lastNuxt = findLastIndex(plugins, i => i.name?.startsWith('nuxt:')) 65 73 if (mockPluginIndex !== -1 && lastNuxt !== -1) { 66 74 if (mockPluginIndex < lastNuxt) { 67 75 const [mockPlugin] = plugins.splice(mockPluginIndex, 1)