fix(test): isolate recorded Web browser timezone
This commit is contained in:
1 parent
237b3d5edf
commit
f5302b2b4d
2 files changed
+25
-2
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { chromium } from 'playwright'
|
||||
import { expect, it } from 'vitest'
|
||||
import { newEnglishPage } from './support.ts'
|
||||
|
||||
it.each(['UTC', 'America/Los_Angeles'])('isolates the recorded browser timezone from %s', async (hostTimeZone) => {
|
||||
const browser = await chromium.launch({ env: { ...process.env, TZ: hostTimeZone } })
|
||||
try {
|
||||
const ambientPage = await browser.newPage()
|
||||
expect(await ambientPage.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone)).toBe(hostTimeZone)
|
||||
|
||||
const page = await newEnglishPage(browser)
|
||||
expect(await page.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone)).toBe('Asia/Shanghai')
|
||||
expect(await page.evaluate(() => navigator.language)).toBe('en-US')
|
||||
expect(await ambientPage.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone)).toBe(hostTimeZone)
|
||||
|
||||
await page.close()
|
||||
const nextPage = await browser.newPage()
|
||||
expect(await nextPage.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone)).toBe(hostTimeZone)
|
||||
} finally {
|
||||
await browser.close()
|
||||
}
|
||||
})
|
||||
@@ -22,13 +22,14 @@ export const ZH_BROWSER_LOCALE = 'zh-CN'
|
||||
* This keeps role locators and goldens deterministic while leaving the Host
|
||||
* settings document free to override the provisional browser-derived locale;
|
||||
* scenarios asserting the Chinese surface advertise
|
||||
* {@link ZH_BROWSER_LOCALE} instead.
|
||||
* {@link ZH_BROWSER_LOCALE} instead. The context uses Asia/Shanghai to preserve
|
||||
* the recorded Web user-source timezone independently of the host timezone.
|
||||
* @param browser - Playwright browser owning the page.
|
||||
* @param height - Viewport height; width is fixed to the lane baseline.
|
||||
* @returns the initialized page.
|
||||
*/
|
||||
export async function newEnglishPage(browser: Browser, height = 1000): Promise<Page> {
|
||||
return await browser.newPage({ viewport: { width: 1680, height }, locale: 'en-US' })
|
||||
return await browser.newPage({ viewport: { width: 1680, height }, locale: 'en-US', timezoneId: 'Asia/Shanghai' })
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user