Skip to content

Commit d9648e1

Browse files
committed
generateFsPathFromId tests
1 parent 616cf13 commit d9648e1

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

src/module/test/utils/collection.test.ts

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from 'vitest'
2-
import { getCollectionByFilePath, generateIdFromFsPath } from '../../src/runtime/utils/collection'
3-
import type { CollectionInfo } from '@nuxt/content'
2+
import { getCollectionByFilePath, generateIdFromFsPath, generateFsPathFromId } from '../../src/runtime/utils/collection'
3+
import type { CollectionInfo, ResolvedCollectionSource } from '@nuxt/content'
44
import { collections } from '../mocks/collection'
55

66
describe('getCollectionByFilePath', () => {
@@ -43,55 +43,55 @@ describe('getCollectionByFilePath', () => {
4343
})
4444
})
4545

46-
// describe('generateFsPathFromId', () => {
47-
// it('One file included', () => {
48-
// const id = 'landing/index.md'
49-
// const source = {
50-
// prefix: '/',
51-
// include: 'index.md',
52-
// } as ResolvedCollectionSource
53-
// const result = generateFsPathFromId(id, source)
54-
// expect(result).toBe('index.md')
55-
// })
56-
57-
// it('Global pattern included', () => {
58-
// const id = 'docs/1.getting-started/2.introduction.md'
59-
// const source = {
60-
// prefix: '/',
61-
// include: '**',
62-
// exclude: ['index.md'],
63-
// } as ResolvedCollectionSource
64-
// const result = generateFsPathFromId(id, source)
65-
// expect(result).toBe('1.getting-started/2.introduction.md')
66-
// })
67-
68-
// it('Custom pattern with prefix', () => {
69-
// const id = 'docs_en/en/1.getting-started/2.introduction.md'
70-
// const source = {
71-
// prefix: '/en',
72-
// include: 'en/**/*',
73-
// exclude: [
74-
// 'en/index.md',
75-
// ],
76-
// } as ResolvedCollectionSource
77-
78-
// const result = generateFsPathFromId(id, source)
79-
// expect(result).toBe('en/1.getting-started/2.introduction.md')
80-
// })
81-
82-
// it('Custom pattern with root prefix and fixed part', () => {
83-
// const id = 'pages/about.md'
84-
// const source: ResolvedCollectionSource = {
85-
// prefix: '/',
86-
// include: 'pages/**/*',
87-
// cwd: '',
88-
// _resolved: true,
89-
// }
90-
91-
// const result = generateFsPathFromId(id, source)
92-
// expect(result).toBe('pages/about.md')
93-
// })
94-
// })
46+
describe('generateFsPathFromId', () => {
47+
it('One file included', () => {
48+
const id = 'landing/index.md'
49+
const source = {
50+
prefix: '/',
51+
include: 'index.md',
52+
} as ResolvedCollectionSource
53+
const result = generateFsPathFromId(id, source)
54+
expect(result).toBe('index.md')
55+
})
56+
57+
it('Global pattern included', () => {
58+
const id = 'docs/1.getting-started/2.introduction.md'
59+
const source = {
60+
prefix: '/',
61+
include: '**',
62+
exclude: ['index.md'],
63+
} as ResolvedCollectionSource
64+
const result = generateFsPathFromId(id, source)
65+
expect(result).toBe('1.getting-started/2.introduction.md')
66+
})
67+
68+
it('Custom pattern with prefix', () => {
69+
const id = 'docs_en/en/1.getting-started/2.introduction.md'
70+
const source = {
71+
prefix: '/en',
72+
include: 'en/**/*',
73+
exclude: [
74+
'en/index.md',
75+
],
76+
} as ResolvedCollectionSource
77+
78+
const result = generateFsPathFromId(id, source)
79+
expect(result).toBe('en/1.getting-started/2.introduction.md')
80+
})
81+
82+
it('Custom pattern with root prefix and fixed part', () => {
83+
const id = 'pages/about.md'
84+
const source: ResolvedCollectionSource = {
85+
prefix: '/',
86+
include: 'pages/**/*',
87+
cwd: '',
88+
_resolved: true,
89+
}
90+
91+
const result = generateFsPathFromId(id, source)
92+
expect(result).toBe('pages/about.md')
93+
})
94+
})
9595

9696
describe('generateIdFromFsPath', () => {
9797
it('should generate id for single file with no prefix', () => {

0 commit comments

Comments
 (0)