Skip to content

Commit e5db06d

Browse files
authored
test: add tests to cover timezone/locale emulation in workers (#39132)
1 parent f41c4a5 commit e5db06d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

tests/library/browsercontext-locale.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,19 @@ it('should not change default locale in another context', async ({ browser }) =>
165165
}
166166
});
167167

168-
it('should format number in workers', async ({ browser, browserName, server }) => {
168+
it('should propagate locale to workers', async ({ browser, browserName, server }) => {
169169
it.fail(browserName === 'firefox', 'https://github.com/microsoft/playwright/issues/38919');
170170
const context = await browser.newContext({ locale: 'ru-RU' });
171171
const page = await context.newPage();
172172
await page.goto(server.EMPTY_PAGE);
173-
const [worker] = await Promise.all([
174-
page.waitForEvent('worker'),
175-
page.evaluate(() => new Worker(URL.createObjectURL(new Blob(['console.log(1)'], { type: 'application/javascript' })))),
173+
const [msg] = await Promise.all([
174+
page.waitForEvent('console'),
175+
page.evaluate(() => new Worker(URL.createObjectURL(new Blob(['console.log(Intl.NumberFormat().resolvedOptions().locale)'], { type: 'application/javascript' })))),
176176
]);
177-
expect(await worker.evaluate(() => (10000.20).toLocaleString())).toBe('10\u00A0000,2');
177+
if (browserName === 'webkit')
178+
expect(msg.text()).toContain('ru'); // Webkit on Ubuntu is "ru-RU", and on other platforms is "ru"
179+
else
180+
expect(msg.text()).toBe('ru-RU');
178181
await context.close();
179182
});
180183

tests/library/browsercontext-timezone-id.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,16 @@ it('should affect Intl.DateTimeFormat().resolvedOptions().timeZone', async ({ br
115115
expect(await page.evaluate(() => (new Intl.DateTimeFormat()).resolvedOptions().timeZone)).toBe('America/Jamaica');
116116
await context.close();
117117
});
118+
119+
it('should propagate timezone to workers', async ({ browser, browserName, server }) => {
120+
it.fail(browserName === 'firefox', 'https://github.com/microsoft/playwright/issues/38919');
121+
const context = await browser.newContext({ timezoneId: 'America/Jamaica' });
122+
const page = await context.newPage();
123+
await page.goto(server.EMPTY_PAGE);
124+
const [msg] = await Promise.all([
125+
page.waitForEvent('console'),
126+
page.evaluate(() => new Worker(URL.createObjectURL(new Blob(['console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)'], { type: 'application/javascript' })))),
127+
]);
128+
expect(msg.text()).toBe('America/Jamaica');
129+
await context.close();
130+
});

0 commit comments

Comments
 (0)