Repository: vercel/next.js
Pull request: test: ignore streaming metadata in toBeEmpty assertions

Some tests in `rsc-basic` asserts that certain nodes should be empty, but streaming metadata can get in there and break that expectation.

- i switched the test to use a full browser. this is better than checking the raw html, because then react gets rid of any `<template>` tags inside the div (which are used for streaming SSR things)
- we're also now only asserting that the inner text of the node should be empty, which avoids failures because of a `<div hidden>` inserted by streaming metadata. this is a slightly weaker assertion than "this node has no children at all" but it should be enough for our purposes here.

also reverts #78449 and  #78424, they were meant for debugging this issue

Changed files:
filename: test/e2e/app-dir/rsc-basic/rsc-basic.test.ts
patch: @@ -19,10 +19,6 @@ async function resolveStreamResponse(response: any, onData?: any) {
   return result
 }
 
-function stripHTMLComments(html: string): string {
-  return html.replace(/<!--[\s\S]*?-->/g, '')
-}
-
 describe('app dir - rsc basics', () => {
   const { next, isNextDev, isNextStart, isTurbopack } = nextTestSetup({
     files: __dirname,
@@ -74,52 +70,39 @@ describe('app dir - rsc basics', () => {
   })
 
   it('should correctly render page returning null', async () => {
-    const homeHTML = await next.render('/return-null/page')
-    const $ = cheerio.load(homeHTML)
-    expect(stripHTMLComments($('#return-null-layout').html())).toBeEmpty()
+    const browser = await next.browser('/return-null/page')
+    expect(await browser.elementByCss('#return-null-layout').text()).toBeEmpty()
   })
 
   it('should correctly render component returning null', async () => {
-    const homeHTML = await next.render('/return-null/component')
-    const $ = cheerio.load(homeHTML)
-    expect(stripHTMLComments($('#return-null-layout').html())).toBeEmpty()
+    const browser = await next.browser('/return-null/component')
+    expect(await browser.elementByCss('#return-null-layout').text()).toBeEmpty()
   })
 
   it('should correctly render layout returning null', async () => {
-    const homeHTML = await next.render('/return-null/layout')
-    const $ = cheerio.load(homeHTML)
-    expect($('#return-null-layout').html()).toBeEmpty()
+    const browser = await next.browser('/return-null/layout')
+    expect(await browser.elementByCss('#return-null-layout').text()).toBeEmpty()
   })
 
   it('should correctly render page returning undefined', async () => {
-    const homeHTML = await next.render('/return-undefined/page')
-    const $ = cheerio.load(homeHTML)
-    try {
-      expect(
-        stripHTMLComments($('#return-undefined-layout').html())
-      ).toBeEmpty()
-    } catch (err) {
-      const console = require('console')
-      const sep = '='.repeat(40) + ' PAGE HTML ' + '='.repeat(40)
-      console.log()
-      console.log(sep)
-      console.log($('html').html())
-      console.log(sep)
-      console.log()
-      throw err
-    }
+    const browser = await next.browser('/return-undefined/page')
+    expect(
+      await browser.elementByCss('#return-undefined-layout').text()
+    ).toBeEmpty()
   })
 
   it('should correctly render component returning undefined', async () => {
-    const homeHTML = await next.render('/return-undefined/component')
-    const $ = cheerio.load(homeHTML)
-    expect(stripHTMLComments($('#return-undefined-layout').html())).toBeEmpty()
+    const browser = await next.browser('/return-undefined/component')
+    expect(
+      await browser.elementByCss('#return-undefined-layout').text()
+    ).toBeEmpty()
   })
 
   it('should correctly render layout returning undefined', async () => {
-    const homeHTML = await next.render('/return-undefined/layout')
-    const $ = cheerio.load(homeHTML)
-    expect($('#return-undefined-layout').html()).toBeEmpty()
+    const browser = await next.browser('/return-undefined/layout')
+    expect(
+      await browser.elementByCss('#return-undefined-layout').text()
+    ).toBeEmpty()
   })
 
   it('should handle named client components imported as page', async () => {