Skip to content

Commit 64178b6

Browse files
committed
test: add universal routing tests + clean up output
1 parent b3acf0c commit 64178b6

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test:fixtures": "pnpm test:prepare && vitest run --project fixtures",
3030
"test:fixtures:dev": "TEST_ENV=dev pnpm test:fixtures",
3131
"test:fixtures:webpack": "TEST_BUILDER=webpack pnpm test:fixtures",
32-
"test:runtime": "vitest run --project nuxt",
32+
"test:runtime": "vitest run --project nuxt --project nuxt-universal",
3333
"test:types": "pnpm --filter './test/fixtures/**' test:types",
3434
"test:unit": "vitest run --project unit",
3535
"test:attw": "pnpm --filter './packages/**' test:attw",

test/nuxt/client-only.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ describe('client pages', () => {
2525
`)
2626
})
2727

28-
it('createClient should retrieve attributes with useAttrs()', async () => {
29-
const wrapper = await mountSuspended(createClientOnly(Client as ComponentOptions), {
28+
it('createClient should retrieve attributes with useAttrs()', () => {
29+
const wrapper = mount(createClientOnly(Client as ComponentOptions), {
3030
attrs: {
3131
id: 'client',
3232
},

test/nuxt/composables.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ describe('useAsyncData', () => {
374374
it('should be refreshable with force and cache', async () => {
375375
await useAsyncData(uniqueKey, () => Promise.resolve('test'), {
376376
getCachedData: (key, nuxtApp, ctx) => {
377-
console.log(key, ctx.cause)
378377
return ctx.cause
379378
},
380379
})
@@ -652,7 +651,6 @@ describe('useAsyncData', () => {
652651
it('duplicate calls are not made after first call has finished', async () => {
653652
const handler = vi.fn(() => Promise.resolve('hello'))
654653
const getCachedData = vi.fn((key: string, nuxtApp: NuxtApp) => {
655-
console.log(nuxtApp.payload.data[key] ? 'has data' : 'does not have data')
656654
return nuxtApp.payload.data[key]
657655
})
658656

test/nuxt/error-boundary.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference path="../fixtures/basic/.nuxt/nuxt.d.ts" />
22

3-
import { describe, expect, it } from 'vitest'
3+
import { describe, expect, it, vi } from 'vitest'
44

55
import { mount } from '@vue/test-utils'
66
import { NuxtErrorBoundary } from '#components'
@@ -21,6 +21,8 @@ describe('NuxtErrorBoundary', () => {
2121

2222
it('should handle error state', async () => {
2323
let thrown = false
24+
// suppress Vue warning: [Vue warn]: Component is missing template or render function:
25+
vi.spyOn(console, 'warn').mockImplementation(() => {})
2426
const el = mount({
2527
setup () {
2628
return () => h('div', {}, h(NuxtErrorBoundary, {}, {
@@ -44,5 +46,6 @@ describe('NuxtErrorBoundary', () => {
4446
await el.find('button').trigger('click')
4547
expect(el.html()).toMatchInlineSnapshot(`"<div><span>default</span></div>"`)
4648
el.unmount()
49+
vi.resetAllMocks()
4750
})
4851
})

test/nuxt/universal/router.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
describe('universal router', () => {
4+
it('should provide a route', () => {
5+
expect(useRoute()).toMatchObject({
6+
fullPath: '/',
7+
hash: '',
8+
matched: expect.arrayContaining([]),
9+
meta: {},
10+
params: {},
11+
path: '/',
12+
query: {},
13+
redirectedFrom: undefined,
14+
})
15+
})
16+
})

vitest.config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { resolve } from 'pathe'
22
import { defineVitestProject } from '@nuxt/test-utils/config'
3-
import { configDefaults, coverageConfigDefaults, defineConfig } from 'vitest/config'
3+
import { configDefaults, coverageConfigDefaults, defaultExclude, defineConfig } from 'vitest/config'
44
import { isCI, isWindows } from 'std-env'
55
import { getV8Flags } from '@codspeed/core'
66
import codspeedPlugin from '@codspeed/vitest-plugin'
@@ -54,10 +54,23 @@ export default defineConfig({
5454
exclude: [...configDefaults.exclude, 'test/e2e/**', 'e2e/**', 'nuxt/**', '**/test.ts', '**/this-should-not-load.spec.js'],
5555
},
5656
},
57+
await defineVitestProject({
58+
test: {
59+
name: 'nuxt-universal',
60+
dir: './test/nuxt/universal',
61+
environment: 'nuxt',
62+
environmentOptions: {
63+
nuxt: {
64+
overrides: { pages: false },
65+
},
66+
},
67+
},
68+
}),
5769
await defineVitestProject({
5870
test: {
5971
name: 'nuxt',
6072
dir: './test/nuxt',
73+
exclude: [...defaultExclude, '**/universal/**'],
6174
environment: 'nuxt',
6275
setupFiles: ['./test/setup-runtime.ts'],
6376
environmentOptions: {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy