forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-page.js
29 lines (24 loc) · 844 Bytes
/
find-page.js
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
import { jest } from '@jest/globals'
import { fileURLToPath } from 'url'
import path from 'path'
import Page from '../../lib/page.js'
import findPage from '../../lib/find-page.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
describe('find page', () => {
jest.setTimeout(1000 * 1000)
test('follows redirects', async () => {
const page = await Page.init({
relativePath: 'page-with-redirects.md',
basePath: path.join(__dirname, '../fixtures'),
languageCode: 'en',
})
const englishPermalink = page.permalinks[0].href
const redirectToFind = '/some-old-path'
// add named keys
const pageMap = {
[englishPermalink]: page,
}
const redirectedPage = findPage(redirectToFind, pageMap, page.buildRedirects())
expect(typeof redirectedPage.title).toBe('string')
})
})