1
0
mirror of synced 2025-12-26 05:02:55 -05:00
Files
docs/tests/rendering/head.js
Peter Bengtsson 18504871b9 cache full rendering (#25424)
* cache full rendering

* still not working with gzip

* progress progress progress

* smaller

* hacky progress

* small fixes

* wip

* lock file

* wip

* wip

* package-lock updates

* wip

* search DOM in lowercase

* simplify

* with instrument

* improve test coverage

* mutateCheeriobodyByRequest

* fix

* remove renderContentCacheByContex

* disable render caching in sync-search

* diables things in github/github link checker

* gzip lru

* tidying up

* updated

* correct tests

* fix: move userLanguage to LanguagesContext

* Revert "fix: move userLanguage to LanguagesContext"

This reverts commit d7c05d958c71eaad496eb46764eb845d80b866ca.

* contexts ftw

* fixed rendering tests

* oops for got new file

* nits addressed

Co-authored-by: Mike Surowiec <mikesurowiec@users.noreply.github.com>
2022-05-23 12:12:09 +00:00

49 lines
2.1 KiB
JavaScript

import { getDOM } from '../helpers/e2etest.js'
import languages from '../../lib/languages.js'
import { jest } from '@jest/globals'
jest.useFakeTimers('legacy')
describe('<head>', () => {
jest.setTimeout(5 * 60 * 1000)
test('includes hreflangs (references to all language versions of the same page)', async () => {
const $ = await getDOM('/en')
const $hreflangs = $('link[rel="alternate"]')
expect($hreflangs.length).toEqual(Object.keys(languages).length)
expect($('link[href="https://docs.github.com/cn"]').length).toBe(1)
expect($('link[href="https://docs.github.com/ja"]').length).toBe(1)
// Due to a bug in either NextJS, JSX, or TypeScript,
// when put `<link hrefLang="xxx">` in a .tsx file, this incorrectly
// gets rendered out as `<link hrefLang="xxx">` in the final HTML.
// Note the uppercase L. It's supposed to become `<link hreflang="xxx">`.
// When cheerio serializes to HTML, it gets this right so it lowercases
// the attribute. So if this rendering in this jest test was the first
// ever cold hit, you might get the buggy HTML from React or you
// might get the correct HTML from cheerio's `.html()` serializer.
// This is why we're looking for either.
expect($('link[hreflang="en"]').length + $('link[hrefLang="en"]').length).toBe(1)
})
test('includes page intro in `description` meta tag', async () => {
const $ = await getDOM('/en/articles/about-ssh')
const $description = $('meta[name="description"]')
expect($description.attr('content').startsWith('Using the SSH protocol')).toBe(true)
})
test('renders `description` meta tag in plaintext (no HTML)', async () => {
const $ = await getDOM('/en/articles/about-pull-request-merges')
const $description = $('meta[name="description"]')
// plain text intro
expect(
$description.attr('content').startsWith('You can merge pull requests by retaining')
).toBe(true)
// HTML intro
expect(
$('[data-testid="lead"]')
.html()
.startsWith('<p>You can <a href="/articles/merging-a-pull-request">merge pull requests</a>')
)
})
})