|
1 | 1 | 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' |
4 | 4 | import { collections } from '../mocks/collection' |
5 | 5 |
|
6 | 6 | describe('getCollectionByFilePath', () => { |
@@ -43,55 +43,55 @@ describe('getCollectionByFilePath', () => { |
43 | 43 | }) |
44 | 44 | }) |
45 | 45 |
|
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 | +}) |
95 | 95 |
|
96 | 96 | describe('generateIdFromFsPath', () => { |
97 | 97 | it('should generate id for single file with no prefix', () => { |
|
0 commit comments