|
1 | 1 | import { fs, path } from '@vuepress/utils'
|
2 | 2 | import { expect, it } from 'vitest'
|
3 |
| -import { resolvePageFileContent } from '../../src/index.js' |
| 3 | +import { resolvePageContent } from '../../src/index.js' |
4 | 4 |
|
5 | 5 | it('should resolve file content correctly from file path', async () => {
|
6 | 6 | const filePath = path.resolve(__dirname, '../__fixtures__/pages/foo.md')
|
7 |
| - const resolved = await resolvePageFileContent({ filePath, options: {} }) |
| 7 | + const resolved = await resolvePageContent({ filePath, options: {} }) |
8 | 8 |
|
9 | 9 | const expected = (await fs.readFile(filePath)).toString()
|
10 | 10 | expect(resolved).toBe(expected)
|
11 | 11 | })
|
12 | 12 |
|
13 | 13 | it('should use content from page options', async () => {
|
14 | 14 | const content = 'foobar'
|
15 |
| - const resolved = await resolvePageFileContent({ |
| 15 | + const resolved = await resolvePageContent({ |
16 | 16 | filePath: null,
|
17 | 17 | options: { content },
|
18 | 18 | })
|
19 |
| - expect(resolved).toBe(resolved) |
| 19 | + |
| 20 | + const expected = content |
| 21 | + expect(resolved).toBe(expected) |
20 | 22 | })
|
21 | 23 |
|
22 | 24 | it('should return empty string if nothing provided', async () => {
|
23 |
| - const resolved = await resolvePageFileContent({ |
| 25 | + const resolved = await resolvePageContent({ |
24 | 26 | filePath: null,
|
25 | 27 | options: {},
|
26 | 28 | })
|
27 |
| - expect(resolved).toBe('') |
| 29 | + |
| 30 | + const expected = '' |
| 31 | + expect(resolved).toBe(expected) |
| 32 | +}) |
| 33 | + |
| 34 | +it('should use content from page options and ignore file path', async () => { |
| 35 | + const filePath = path.resolve(__dirname, '../__fixtures__/pages/foo.md') |
| 36 | + const content = 'foobar' |
| 37 | + const resolved = await resolvePageContent({ |
| 38 | + filePath, |
| 39 | + options: { content }, |
| 40 | + }) |
| 41 | + |
| 42 | + const expected = content |
| 43 | + expect(resolved).toBe(expected) |
28 | 44 | })
|
29 | 45 |
|
30 | 46 | it('should throw error if the file does not exist', async () => {
|
31 | 47 | try {
|
32 |
| - await resolvePageFileContent({ |
| 48 | + await resolvePageContent({ |
33 | 49 | filePath: '404',
|
34 | 50 | options: {},
|
35 | 51 | })
|
|
0 commit comments