From c2a8065db26a9faf863816abb7a9d1eaa8f31409 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Thu, 13 Jul 2023 15:22:48 -0400 Subject: [PATCH] Test the proxied search in local dev (#39051) --- .github/actions-scripts/test-local-dev.js | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.github/actions-scripts/test-local-dev.js b/.github/actions-scripts/test-local-dev.js index e78cd455fc..d9435ff255 100755 --- a/.github/actions-scripts/test-local-dev.js +++ b/.github/actions-scripts/test-local-dev.js @@ -3,6 +3,7 @@ import assert from 'node:assert/strict' import fs from 'fs' +import cheerio from 'cheerio' import got from 'got' /** @@ -12,6 +13,12 @@ import got from 'got' * There are certain things that only work and happen when in * local dev, that don't make sense to test in regular end-to-end tests * such as `jest` rendering. + * + * For engineers to test this locally do the following: + * + * 1. Start `npm run dev` in one terminal + * 2. Run `./.github/actions-scripts/test-local-dev.js` in another terminal + * */ main() @@ -33,6 +40,10 @@ async function main() { // Only in local dev is the `?json=...` query string working await testJSONParameters() + + // In local development, it depends on proxying the search to prod + // because if you haven't set up ELASTICSEARCH_URL. + await testSiteSearch() } async function testEditingPage() { @@ -104,3 +115,21 @@ async function testJSONParameters() { assert(links[0].page) } } + +async function testSiteSearch() { + // Find something on free-pro-team@latest + { + const res = await get('/en/search?query=github') + const $ = cheerio.load(res.body) + // The [\d,]+ is because we use thousands separators in the number + assert(/[\d,]+ Search results for "github"/.test($('h1').text())) + assert($('[data-testid="search-result"]').length > 0) + } + // Find 0 things on enterprise-server@latest + { + const res = await get('/en/enterprise-server@latest/search?query=gobligook') + const $ = cheerio.load(res.body) + assert(/0 Search results for "gobligook"/.test($('h1').text())) + assert($('[data-testid="search-result"]').length === 0) + } +}