<commit_before>import path from 'path'
import fs from 'fs-extra'
import webdriver from 'next-webdriver'
import { renderViaHTTP, fetchViaHTTP, check } from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import cheerio from 'cheerio'

function getNodeBySelector(html, selector) {
  const $ = cheerio.load(html)
  return $(selector)
}

async function resolveStreamResponse(response: any, onData?: any) {
  let result = ''
  onData = onData || (() => {})
  await new Promise((resolve) => {
    response.body.on('data', (chunk) => {
      result += chunk.toString()
      onData(chunk.toString(), result)
    })

    response.body.on('end', resolve)
  })
  return result
}

describe('app dir - react server components', () => {
  let next: NextInstance
  let distDir: string

  beforeAll(async () => {
    const appDir = path.join(__dirname, './rsc-basic')
    next = await createNext({
      files: {
        node_modules: new FileRef(path.join(appDir, 'node_modules')),
        pages: new FileRef(path.join(appDir, 'pages')),
        public: new FileRef(path.join(appDir, 'public')),
        components: new FileRef(path.join(appDir, 'components')),
        app: new FileRef(path.join(appDir, 'app')),
        'next.config.js': new FileRef(path.join(appDir, 'next.config.js')),
      },
      dependencies: {
        react: 'experimental',
        'react-dom': 'experimental',
      },
    })
    distDir = path.join(next.testDir, '.next')
  })
  afterAll(() => next.destroy())

  const { isNextDeploy, isNextDev } = global as any
  if (isNextDeploy) {
    return
  }

  // TODO: support RSC index route
  it('should render server components correctly', async () => {
    const homeHTML = await renderViaHTTP(next.url, '/', null, {
      headers: {
        'x-next-test-client': 'test-util',
      },<commit_msg>Fix rsc test during deploy testing (#38517)<commit_after>import path from 'path'
import fs from 'fs-extra'
import webdriver from 'next-webdriver'
import { renderViaHTTP, fetchViaHTTP, check } from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import cheerio from 'cheerio'

function getNodeBySelector(html, selector) {
  const $ = cheerio.load(html)
  return $(selector)
}

async function resolveStreamResponse(response: any, onData?: any) {
  let result = ''
  onData = onData || (() => {})
  await new Promise((resolve) => {
    response.body.on('data', (chunk) => {
      result += chunk.toString()
      onData(chunk.toString(), result)
    })

    response.body.on('end', resolve)
  })
  return result
}

describe('app dir - react server components', () => {
  let next: NextInstance
  let distDir: string

  beforeAll(async () => {
    const appDir = path.join(__dirname, './rsc-basic')
    next = await createNext({
      files: {
        node_modules: new FileRef(path.join(appDir, 'node_modules')),
        pages: new FileRef(path.join(appDir, 'pages')),
        public: new FileRef(path.join(appDir, 'public')),
        components: new FileRef(path.join(appDir, 'components')),
        app: new FileRef(path.join(appDir, 'app')),
        'next.config.js': new FileRef(path.join(appDir, 'next.config.js')),
      },
      dependencies: {
        react: 'experimental',
        'react-dom': 'experimental',
      },
    })
    distDir = path.join(next.testDir, '.next')
  })
  afterAll(() => next.destroy())

  const { isNextDeploy, isNextDev } = global as any
  if (isNextDeploy) {
    it('should skip tests for next-deploy', () => {})
    return
  }

  // TODO: support RSC index route
  it('should render server components correctly', async () => {
    const homeHTML = await renderViaHTTP(next.url, '/', null, {
      headers: {
        'x-next-test-client': 'test-util',
      },
{'fraction_non_alphanumeric': 0.15498442367601245, 'fraction_numerical': 0.0018172377985462098, 'mean_word_length': 3.281111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6594265', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1223, 'n_words': 297}