Repository: vitejs/vite
File: playground/ssr/__tests__/ssr.spec.ts (TypeScript)

Code before:

test(`deadlock doesn't happen for static imports`, async () => {
  await page.goto(`${url}/forked-deadlock-static-imports`)

  expect(await page.textContent('.forked-deadlock-static-imports')).toMatch(
    'rendered',
  )
})

test(`deadlock doesn't happen for dynamic imports`, async () => {
  await page.goto(`${url}/forked-deadlock-dynamic-imports`)

  expect(await page.textContent('.forked-deadlock-dynamic-imports')).toMatch(
    'rendered',
  )
})

test(`import.meta.resolve is supported`, async () => {
  await page.goto(`${url}/import-meta`)

  const metaUrl = await page.textContent('.import-meta-url')
  expect(metaUrl).not.toBe('')
  expect(await page.textContent('.import-meta-resolve')).toBe(metaUrl)
})

test(`import.meta.main is false in Node.js environment`, async () => {
  await page.goto(`${url}/import-meta`)

  expect(await page.textContent('.import-meta-main')).toBe('false')
})

test.runIf(isServe)('html proxy is encoded', async () => {
  await page.goto(
    `${url}?%22%3E%3C/script%3E%3Cscript%3Econsole.log(%27html%20proxy%20is%20not%20encoded%27)%3C/script%3E`,
  )

  expect(browserLogs).not.toContain('html proxy is not encoded')
})

// run this at the end to reduce flakiness
test.runIf(isServe)('should restart ssr', async () => {
  editFile('./vite.config.ts', (content) => content)
  await expect
    .poll(() => {
      expect(serverLogs).toEqual(
        expect.arrayContaining([expect.stringMatching('server restarted')]),
      )
      expect(serverLogs).not.toEqual(
        expect.arrayContaining([expect.stringMatching('error')]),
      )
    })

Review comment (suggestion):
```suggestion
test(`import.meta.main is supported`, async () => {
```

Code after:

test(`deadlock doesn't happen for static imports`, async () => {
  await page.goto(`${url}/forked-deadlock-static-imports`)

  expect(await page.textContent('.forked-deadlock-static-imports')).toMatch(
    'rendered',
  )
})

test(`deadlock doesn't happen for dynamic imports`, async () => {
  await page.goto(`${url}/forked-deadlock-dynamic-imports`)

  expect(await page.textContent('.forked-deadlock-dynamic-imports')).toMatch(
    'rendered',
  )
})

test(`import.meta.resolve is supported`, async () => {
  await page.goto(`${url}/import-meta`)

  const metaUrl = await page.textContent('.import-meta-url')
  expect(metaUrl).not.toBe('')
  expect(await page.textContent('.import-meta-resolve')).toBe(metaUrl)
})

test(`import.meta.main is supported`, async () => {
  await page.goto(`${url}/import-meta`)

  expect(await page.textContent('.import-meta-main')).toBe('false')
})

test.runIf(isServe)('html proxy is encoded', async () => {
  await page.goto(
    `${url}?%22%3E%3C/script%3E%3Cscript%3Econsole.log(%27html%20proxy%20is%20not%20encoded%27)%3C/script%3E`,
  )

  expect(browserLogs).not.toContain('html proxy is not encoded')
})

// run this at the end to reduce flakiness
test.runIf(isServe)('should restart ssr', async () => {
  editFile('./vite.config.ts', (content) => content)
  await expect
    .poll(() => {
      expect(serverLogs).toEqual(
        expect.arrayContaining([expect.stringMatching('server restarted')]),
      )
      expect(serverLogs).not.toEqual(
        expect.arrayContaining([expect.stringMatching('error')]),
      )
    })