support-timezone.e2e.ts 1.0 KB

12345678910111213141516171819202122
  1. import { chromium } from 'playwright'
  2. import { expect, it } from 'vitest'
  3. import { newEnglishPage } from './support.ts'
  4. it.each(['UTC', 'America/Los_Angeles'])('isolates the recorded browser timezone from %s', async (hostTimeZone) => {
  5. const browser = await chromium.launch({ env: { ...process.env, TZ: hostTimeZone } })
  6. try {
  7. const ambientPage = await browser.newPage()
  8. expect(await ambientPage.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone)).toBe(hostTimeZone)
  9. const page = await newEnglishPage(browser)
  10. expect(await page.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone)).toBe('Asia/Shanghai')
  11. expect(await page.evaluate(() => navigator.language)).toBe('en-US')
  12. expect(await ambientPage.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone)).toBe(hostTimeZone)
  13. await page.close()
  14. const nextPage = await browser.newPage()
  15. expect(await nextPage.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone)).toBe(hostTimeZone)
  16. } finally {
  17. await browser.close()
  18. }
  19. })