Skip to content

Commit

Permalink
fix(module): do not add vue files to ignore list (#1476)
Browse files Browse the repository at this point in the history
* fix(module): do not add vue files to ignore list

* test: add tests
  • Loading branch information
farnabaz committed Aug 31, 2022
1 parent ce5397d commit ec3c61f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,14 @@ export default defineNuxtModule<ModuleOptions>({
for (const source of Object.values(sources)) {
// Only targets directories inside the srcDir
if (source.driver === 'fs' && source.base.includes(nuxt.options.srcDir)) {
const wildcard = join(source.base, '**/*').replace(withTrailingSlash(nuxt.options.srcDir), '')
nuxt.options.ignore.push(
// Remove `srcDir` from the path
join(source.base, '**/*').replace(withTrailingSlash(nuxt.options.srcDir), '')
wildcard,
`!${wildcard}.vue`
)
}
}

nitroConfig.bundledStorage = nitroConfig.bundledStorage || []
nitroConfig.bundledStorage.push('/cache/content')

Expand Down
5 changes: 5 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { testContentQuery } from './features/content-query'
import { testHighlighter } from './features/highlighter'
import { testMarkdownRenderer } from './features/renderer-markdown'
import { testParserOptions } from './features/parser-options'
import { testComponents } from './features/components'

const spyConsoleWarn = vi.spyOn(global.console, 'warn')

Expand Down Expand Up @@ -99,6 +100,7 @@ describe('Basic usage', async () => {
expect(html).contains('<meta property="og:image" content="https://picsum.photos/200/300">')
expect(html).contains('<meta name="description" content="Description overwritten"><meta property="og:image" content="https://picsum.photos/200/300">')
})

test('<ContentDoc> head management (not same path)', async () => {
const html = await $fetch('/bypass-head')
expect(html).not.contains('<title>Head overwritten</title>')
Expand All @@ -122,11 +124,14 @@ describe('Basic usage', async () => {
expect(spyConsoleWarn).toHaveBeenCalledWith('Ignoring [content:with-\'invalid\'-char.md]. File name should not contain any of the following characters: \', ", ?, #, /')
})

testComponents()

testContentQuery()

testNavigation()

testMarkdownParser()

testMarkdownRenderer()

testMarkdownParserExcerpt()
Expand Down
12 changes: 12 additions & 0 deletions test/features/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, test, expect } from 'vitest'
import { $fetch } from '@nuxt/test-utils'

export const testComponents = () => {
describe('components', () => {
test('from content directory', async () => {
const index = await $fetch('/components/from-content')

expect(index).toContain('Lorem ipsum dolor sit, amet consectetur adipisicing elit.')
})
})
}
5 changes: 5 additions & 0 deletions test/fixtures/basic/content/LoremIpsum.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Asperiores tempore totam cum rerum natus aliquid cumque enim accusamus, dicta eveniet illum alias similique facilis blanditiis. Totam architecto a ratione earum.
</p>
</template>
4 changes: 4 additions & 0 deletions test/fixtures/basic/content/components/from-content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Components inside content

::lorem-ipsum
::
7 changes: 7 additions & 0 deletions test/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export default defineNuxtConfig({
{
path: resolve(__dirname, './components'),
global: true
},
{
path: resolve(__dirname, './content'),
global: true,
pathPrefix: false,
prefix: ''
}
]
},
Expand All @@ -27,6 +33,7 @@ export default defineNuxtConfig({
base: resolve(__dirname, 'content-fa')
}
],
ignores: ['.*\\.vue'],
navigation: {
fields: ['icon']
},
Expand Down

0 comments on commit ec3c61f

Please sign in to comment.