/
page-map.test.ts
55 lines (51 loc) · 1.44 KB
/
page-map.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { describe, it, expect, beforeAll } from 'vitest'
import path from 'path'
import { getPageMap } from '../src/page-map'
import { collectFiles } from '../src/plugin'
const pagesDir = () => '../../examples/swr-site/pages'
const filePath = (name: string) => path.join(process.cwd(), pagesDir(), name)
const defaultLocale = 'en-US'
describe('Page Process', () => {
let pageMap: any = {}
let fileMap: any = {}
beforeAll(async () => {
const { items, fileMap: data } = await collectFiles(
path.join(process.cwd(), pagesDir()),
'/'
)
pageMap = items
fileMap = data
})
it('pageMap en-US', async () => {
const indexData = await getPageMap(
filePath('docs/data-fetching.en-US.mdx'),
pageMap,
fileMap,
defaultLocale
)
expect(indexData).toMatchSnapshot()
const gettingStartData = await getPageMap(
filePath('docs/getting-started.en-US.mdx'),
pageMap,
fileMap,
defaultLocale
)
expect(gettingStartData[0]).toEqual(indexData[0])
})
it('pageMap zh-CN', async () => {
const indexData = await getPageMap(
filePath('docs/data-fetching.zh-CN.mdx'),
pageMap,
fileMap,
defaultLocale
)
expect(indexData).toMatchSnapshot()
const gettingStartData = await getPageMap(
filePath('docs/getting-started.zh-CN.mdx'),
pageMap,
fileMap,
defaultLocale
)
expect(gettingStartData[0]).toEqual(indexData[0])
})
})