Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/content/components/ComponentWithProse.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<ProseH3>{{ heading }}</ProseH3>
<ProseP>{{ content }}</ProseP>
</template>

<script lang="ts" setup>
defineProps<{
heading: string
content: string
}>()
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<h1>Use Runtime Config</h1>
<pre>{{ config }}</pre>
</template>

<script lang="ts" setup>
const config = useRuntimeConfig()
</script>
3 changes: 3 additions & 0 deletions examples/content/components/SomeComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>This is an auto-imported component</div>
</template>
9 changes: 7 additions & 2 deletions examples/content/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{
"name": "example-app-vitest-content",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"dev:prepare": "nuxt prepare",
"generate": "nuxt generate",
"test": "vitest run",
"test": "pnpm test:nuxt-environment && pnpm test:browser",
"test:browser": "VITEST_BROWSER_ENABLED=true vitest run",
"test:nuxt-environment": "vitest run",
"preview": "nuxt preview"
},
"devDependencies": {
"@nuxt/content": "3.5.1",
"@nuxt/test-utils": "latest",
"@vitest/browser": "3.1.3",
"nuxt": "3.17.3",
"vitest": "3.1.3"
"vitest": "3.1.3",
"vitest-browser-vue": "0.2.0"
}
}
30 changes: 30 additions & 0 deletions examples/content/tests/browser/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest'
import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime'
import { render } from 'vitest-browser-vue'
import App from '~/app.vue'

// Example usage: queryCollection(pages).path('/').first()
mockNuxtImport('queryCollection', () => (_id: string) => ({
path: (_path: string) => ({
first: () => ({
title: 'My page',
}),
}),
}))

describe('App', () => {
it('works with mountSuspended', async () => {
const component = await mountSuspended(App)
expect(component.html()).toMatchInlineSnapshot(`
"<div>Index page</div>
<div>title: My page</div>"
`)
})

// TODO: render does not currently support <Suspense>
it.skip('works with vitest-browser-vue', () => {
const { getByText } = render(App)
expect(getByText('Index page')).toBeInTheDocument()
expect(getByText('title: My page')).toBeInTheDocument()
})
})
31 changes: 31 additions & 0 deletions examples/content/tests/browser/mount.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect, it } from 'vitest'
import { render } from 'vitest-browser-vue'
import { SomeComponent, ProseH3, ProseP, ComponentWithUseRuntimeConfig, ComponentWithProse } from '#components'

it('should render any component', () => {
const { getByText } = render(SomeComponent)
expect(getByText('This is an auto-imported component')).toBeInTheDocument()
})

it('should render a ProseP component', () => {
const { getByText } = render(ProseP, { slots: { default: 'This is a Prose Paragraph component' } })
expect(getByText('This is a Prose Paragraph component')).toBeInTheDocument()
})

it('should render a ProseH3 component', () => {
const { getByText } = render(ProseH3, { slots: { default: 'This is a Prose heading component' } })
expect(getByText('This is a Prose heading component')).toBeInTheDocument()
})

it('should render a ComponentWithUseRuntimeConfig component', () => {
const { getByText } = render(ComponentWithUseRuntimeConfig)
expect(getByText('Use Runtime Config')).toBeInTheDocument()
})

it('should render a ComponentWithProse component', () => {
const headingText = 'Text rendered within ProseH3'
const paragraphText = 'Text rendered within paragraph'
const { getByText } = render(ComponentWithProse, { props: { heading: headingText, content: paragraphText } })
expect(getByText(headingText)).toBeInTheDocument()
expect(getByText(paragraphText)).toBeInTheDocument()
})
33 changes: 33 additions & 0 deletions examples/content/tests/mount.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect, it } from 'vitest'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { ComponentWithUseRuntimeConfig, ComponentWithProse, SomeComponent, ProseH3, ProseP } from '#components'

it('should render any component', async () => {
const component = await mountSuspended(SomeComponent)
expect(component.html()).toContain('This is an auto-imported component')
})

it('should render a ProseH3 component', async () => {
const headingText = 'This is a Prose Heading component'
const component = await mountSuspended(ProseH3, { slots: { default: headingText } })
expect(component.html()).toContain(headingText)
})

it('should render a ProseP component', async () => {
const paragraphText = 'This is a Prose Paragraph component'
const component = await mountSuspended(ProseP, { slots: { default: paragraphText } })
expect(component.html()).toContain(paragraphText)
})

it('should render a ComponentWithUseRuntimeConfig component', async () => {
const component = await mountSuspended(ComponentWithUseRuntimeConfig)
expect(component.html()).toContain('Use Runtime Config')
})

it('should render a ComponentWithProse component', async () => {
const headingText = 'Text rendered within ProseH3'
const paragraphText = 'Text rendered within p'
const component = await mountSuspended(ComponentWithProse, { props: { heading: headingText, content: paragraphText } })
expect(component.html()).toContain(headingText)
expect(component.html()).toContain(paragraphText)
})
20 changes: 17 additions & 3 deletions examples/content/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { defineVitestConfig } from '@nuxt/test-utils/config'

export default defineVitestConfig({
test: {
environment: 'nuxt',
const browserConfig = {
browser: {
enabled: true,
provider: 'playwright',
instances: [{ browser: 'chromium' }],
},
environment: 'nuxt',
include: ['tests/browser/**/*.spec.ts'],
setupFiles: ['vitest-browser-vue'],
}

const defaultConfig = {
environment: 'nuxt',
exclude: ['tests/browser/**/*.spec.ts', 'node_modules/**', 'dist/**', '.data/**'],
}

export default defineVitestConfig({
test: process.env.VITEST_BROWSER_ENABLED === 'true' ? browserConfig : defaultConfig,
})
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.