Skip to content

Commit 705e2aa

Browse files
authored
test: add example fixture with @nuxt/content (#631)
1 parent 404af27 commit 705e2aa

File tree

8 files changed

+1665
-293
lines changed

8 files changed

+1665
-293
lines changed

examples/content/app.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>Index page</div>
3+
<div>title: {{ posts[0].title }}</div>
4+
</template>
5+
6+
<script setup lang="ts">
7+
definePageMeta({
8+
value: 'set in index'
9+
})
10+
const posts = await queryContent('/').limit(1).find()
11+
</script>

examples/content/content/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Nuxt Content
2+
3+
This page corresponds to the `/` route of your website. You can delete it or create another file in the `content/` directory.
4+
5+
Try to navigate to [/about](/about). These 2 pages are rendered by the `pages/[...slug].vue` component.
6+
7+
---
8+
9+
Look at the [Content documentation](https://content.nuxtjs.org/) to learn more.

examples/content/nuxt.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
export default defineNuxtConfig({
3+
modules: ['@nuxt/content']
4+
})

examples/content/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"private": true,
3+
"type": "module",
4+
"scripts": {
5+
"build": "nuxt build",
6+
"dev": "nuxt dev",
7+
"dev:prepare": "nuxt prepare",
8+
"generate": "nuxt generate",
9+
"test": "vitest",
10+
"preview": "nuxt preview"
11+
},
12+
"devDependencies": {
13+
"@nuxt/content": "^2.9.0",
14+
"@nuxt/test-utils": "latest",
15+
"nuxt": "^3.8.2",
16+
"vitest": "1.0.1"
17+
}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime'
3+
4+
import App from '~/app.vue'
5+
6+
// Example usage: queryContent('/').limit(1).find()
7+
mockNuxtImport('queryContent', () => (_id: string) => ({
8+
limit: (_limit: number) => ({
9+
find: () => [{
10+
title: 'My page'
11+
}]
12+
})
13+
}))
14+
15+
describe('test utils', () => {
16+
it('can mount components within nuxt suspense', async () => {
17+
const component = await mountSuspended(App)
18+
expect(component.html()).toMatchInlineSnapshot(`
19+
"<div>Index page</div>
20+
<div>title: My page</div>"
21+
`)
22+
})
23+
})

examples/content/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
// https://v3.nuxtjs.org/concepts/typescript
3+
"extends": "./.nuxt/tsconfig.json"
4+
}

examples/content/vitest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineVitestConfig } from '@nuxt/test-utils/config'
2+
3+
export default defineVitestConfig({
4+
test: {
5+
environment: 'nuxt'
6+
},
7+
})

0 commit comments

Comments
 (0)