Skip to content

Commit

Permalink
fix(document-driven): throw 404 error when content is missing (#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Aug 2, 2022
1 parent f439178 commit 343db3e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 85 deletions.
4 changes: 2 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ done

if [[ $ARG1 ]]
then
echo "npx vitest run -t $ARG1"
(npx vitest run -t $ARG1.test)
echo "npx vitest run $ARG1"
(npx vitest run $ARG1.test)
else
echo "npx vitest run"
(npx vitest run)
Expand Down
9 changes: 9 additions & 0 deletions src/runtime/pages/document-driven.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<script setup lang="ts">
import { createError } from 'h3'
import { useContent, useContentHead } from '#imports'
const { page } = useContent()
// Page not found
if (!page.value) {
throw createError({
statusCode: 404,
statusMessage: `Page not found: ${useRoute().path}`
})
}
useContentHead(page)
</script>

Expand Down
11 changes: 10 additions & 1 deletion test/document-driven.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('fixtures:document-driven', async () => {
test('<title> from front-matter', async () => {
const html = await $fetch('/')

expect(html).contains('Home | Document Driven Fixture')
expect(html).contains('<title>Home</title>')
})

test('disabled document driven', async () => {
Expand Down Expand Up @@ -46,4 +46,13 @@ describe('fixtures:document-driven', async () => {
expect(html).contains('with previous link /layout')
expect(html).contains('with next link /no-surround')
})

test('404 page', async () => {
try {
await $fetch('/page-not-found')
} catch (e) {
expect(e.response.status).toBe(404)
expect(e.response.statusText).toBe('Page not found: /page-not-found')
}
})
})
82 changes: 0 additions & 82 deletions test/fixtures/document-driven/pages/[...slug].vue

This file was deleted.

0 comments on commit 343db3e

Please sign in to comment.