/
page-map.test.ts
65 lines (58 loc) · 1.7 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
56
57
58
59
60
61
62
63
64
65
import { describe, it, expect, beforeAll } from 'vitest'
import path from 'node:path'
import { getPageMap } from '../src/page-map'
import { collectFiles } from '../src/plugin'
import { FileMap, PageMapItem } from '../src/types'
import { CWD } from '../src/constants'
const PAGES_DIR = path.join(CWD, '..', '..', 'examples', 'swr-site', 'pages')
const filePath = (name: string) => path.join(PAGES_DIR, name)
const defaultLocale = 'en-US'
describe('Page Process', () => {
let pageMap: PageMapItem[]
let fileMap: FileMap
beforeAll(async () => {
const { items, fileMap: data } = await collectFiles(PAGES_DIR)
pageMap = items
fileMap = data
})
it('pageMap en-US', async () => {
const indexData = await getPageMap({
filePath: filePath('docs/data-fetching.en-US.mdx'),
pageMap,
fileMap,
defaultLocale
})
expect([
indexData.pageMap,
indexData.route,
indexData.title
]).toMatchSnapshot()
const gettingStartData = await getPageMap({
filePath: filePath('docs/getting-started.en-US.mdx'),
pageMap,
fileMap,
defaultLocale
})
expect(gettingStartData.pageMap).toEqual(indexData.pageMap)
})
it('pageMap zh-CN', async () => {
const indexData = await getPageMap({
filePath: filePath('docs/data-fetching.zh-CN.mdx'),
pageMap,
fileMap,
defaultLocale
})
expect([
indexData.pageMap,
indexData.route,
indexData.title
]).toMatchSnapshot()
const gettingStartData = await getPageMap({
filePath: filePath('docs/getting-started.zh-CN.mdx'),
pageMap,
fileMap,
defaultLocale
})
expect(gettingStartData.pageMap).toEqual(indexData.pageMap)
})
})