-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(stream-ssr): Move wait for all ready to fix bot rendering (#9389)
- Loading branch information
Showing
3 changed files
with
76 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 28 additions & 21 deletions
49
tasks/smoke-tests/streaming-ssr-prod/tests/botRendering.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,49 @@ | ||
import type { Page } from '@playwright/test' | ||
import { test } from '@playwright/test' | ||
|
||
import { checkDelayedPageRendering } from '../../shared/delayedPage' | ||
import { checkHomePageCellRender } from '../../shared/homePage' | ||
|
||
let botPageNoJs: Page | ||
// UA taken from https://developers.google.com/search/docs/crawling-indexing/overview-google-crawlers | ||
const BOT_USERAGENT = | ||
'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36' | ||
|
||
test.beforeAll(async ({ browser }) => { | ||
// UA taken from https://developers.google.com/search/docs/crawling-indexing/overview-google-crawlers | ||
test('Check that homepage has content fully rendered from the server, without JS', async ({ | ||
browser, | ||
}) => { | ||
const botContext = await browser.newContext({ | ||
userAgent: | ||
'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36', | ||
// @@MARK TODO awaiting react team feedback. I dont understand why React is still injecting JS instead of giving us | ||
// a fully formed HTML page | ||
// javaScriptEnabled: false, | ||
userAgent: BOT_USERAGENT, | ||
// Even without JS, this should be a fully rendered page | ||
javaScriptEnabled: false, | ||
}) | ||
|
||
const botPage = await botContext.newPage() | ||
await botPage.route('**/*.*.{js,tsx,ts,jsx}', (route) => route.abort()) | ||
const botPageNoJs = await botContext.newPage() | ||
|
||
botPageNoJs = botPage | ||
}) | ||
|
||
test.afterAll(() => { | ||
botPageNoJs.close() | ||
}) | ||
|
||
test('Check that homepage has content rendered from the server', async () => { | ||
await botPageNoJs.goto('/') | ||
|
||
// Appears when Cell is successfully rendered | ||
await botPageNoJs.waitForSelector('article') | ||
|
||
await checkHomePageCellRender(botPageNoJs) | ||
|
||
await botPageNoJs.close() | ||
}) | ||
|
||
test('Check delayed page is NOT progressively rendered', async () => { | ||
await checkDelayedPageRendering(botPageNoJs, { | ||
test('Check delayed page is NOT progressively rendered', async ({ | ||
browser, | ||
}) => { | ||
// For this test we need to enable JS, but block all client side scripts | ||
// So that we can check that expected delay is 0 | ||
const botContext = await browser.newContext({ | ||
userAgent: BOT_USERAGENT, | ||
}) | ||
|
||
const botPageNoBundle = await botContext.newPage() | ||
|
||
await botPageNoBundle.route('**/*.*.{js,tsx,ts,jsx}', (route) => | ||
route.abort() | ||
) | ||
|
||
await checkDelayedPageRendering(botPageNoBundle, { | ||
expectedDelay: 0, | ||
}) | ||
}) |