mirror of
https://github.com/supabase/supabase.git
synced 2026-05-12 13:19:37 +08:00
Before: There was a bug with middleware rewrites for reference pages without crawler versions (basically all references except the client SDKs). There was a branch that was not handled (the requesting user agent is a a bot, but the reference is not a client SDK), so it failed through to the base case of NextResponse.next(), which 404s as that page does not exist for a path like /reference/api/v1-deploy-a-function After: Fixed the branch. If all of the following are true: - Is a reference page - Requesting user agent is a bot - Reference is not a client SDK Then it should follow the same path as a non-bot request, because there is no bot-specific version. That means it should be rewritten to teh slugless page: /reference/api/v1-deploya-function => /reference/api
80 lines
2.9 KiB
TypeScript
80 lines
2.9 KiB
TypeScript
import { load } from 'cheerio'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
const REFERENCE_DOCS_URL = 'https://supabase.com/docs/reference'
|
|
// For dev testing: comment out above and uncomment below
|
|
// const REFERENCE_DOCS_URL = 'http://localhost:3001/docs/reference'
|
|
|
|
describe('prod smoke test: crawler pages return correct data', () => {
|
|
/**
|
|
* No special tricks required to spoof the user agent. Tests are correctly
|
|
* detected as coming from bots. If they ever aren't, the `h1` test will fail
|
|
* as a different `h1` is served to non-bots.
|
|
*/
|
|
|
|
it('metadata: title, description, canonical, image', async () => {
|
|
const result = await fetch(REFERENCE_DOCS_URL + '/javascript/rangelte')
|
|
const text = await result.text()
|
|
|
|
const $ = load(text)
|
|
const title = $('title').text()
|
|
expect(title).toBe('JavaScript: Less than or equal to a range | Supabase Docs')
|
|
|
|
const metaDescription = $('meta[name="description"]')
|
|
expect(metaDescription.attr('content')).toBe(
|
|
'Supabase API reference for JavaScript: Less than or equal to a range'
|
|
)
|
|
|
|
const canonical = $('link[rel="canonical"]')
|
|
expect(canonical.attr('href')).toBe('https://supabase.com/docs/reference/javascript/rangelte')
|
|
|
|
const ogImage = $('meta[name="og:image"]')
|
|
expect(ogImage.attr('content')).toBe('https://supabase.com/docs/img/supabase-og-image.png')
|
|
|
|
const twitterImage = $('meta[name="twitter:image"]')
|
|
expect(twitterImage.attr('content')).toBe('https://supabase.com/docs/img/supabase-og-image.png')
|
|
})
|
|
|
|
it('markdown pages', async () => {
|
|
const result = await fetch(REFERENCE_DOCS_URL + '/javascript/introduction')
|
|
const text = await result.text()
|
|
|
|
const $ = load(text)
|
|
const h1 = $('h1').text()
|
|
expect(h1).toBe('JavaScript: Introduction')
|
|
|
|
const firstPara = $('h1').next().text()
|
|
expect(/JavaScript library/.test(firstPara)).toBe(true)
|
|
expect(/supabase-js/.test(firstPara)).toBe(true)
|
|
})
|
|
|
|
it('function pages', async () => {
|
|
const result = await fetch(REFERENCE_DOCS_URL + '/javascript/rangelte')
|
|
const text = await result.text()
|
|
|
|
const $ = load(text)
|
|
const h1 = $('h1').text()
|
|
expect(h1).toBe('JavaScript: Less than or equal to a range')
|
|
|
|
const description = $('h1').next().text()
|
|
expect(description).toBe(
|
|
'Only relevant for range columns. Match only rows where every element in column is either contained in range or less than any element in range.'
|
|
)
|
|
|
|
const headings = [] as Array<string | undefined>
|
|
$('h2').map(function () {
|
|
headings.push($(this).attr('id'))
|
|
})
|
|
|
|
expect(headings.includes('parameters')).toBe(true)
|
|
expect(headings.includes('examples')).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('prod smoke test: ref pages without crawler versions', async () => {
|
|
it('returns 200', async () => {
|
|
const result = await fetch(REFERENCE_DOCS_URL + '/api/v1-deploy-a-function')
|
|
expect(result.status).toBe(200)
|
|
})
|
|
})
|