Skip to content

Commit fbb6ed9

Browse files
committed
test(desktop): cover the process-wide user agent from the first launched request
1 parent a40d6c2 commit fbb6ed9

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎apps/desktop/e2e/smoke.spec.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ const PAGES: Record<string, string> = {
2121
'/login': '<!doctype html><html><body><h1 id="login">fixture-login</h1></body></html>',
2222
}
2323

24+
/** `User-Agent` of every request the fixture origin has served, in arrival order. */
25+
const requestUserAgents: string[] = []
26+
2427
function startFixtureServer(): Promise<{ server: Server; origin: string }> {
2528
return new Promise((resolvePromise) => {
2629
const server = createServer((request, response) => {
30+
requestUserAgents.push(request.headers['user-agent'] ?? '')
2731
const path = new URL(request.url ?? '/', 'http://127.0.0.1').pathname
2832
const sessionCookie = request.headers.cookie
2933
?.split(';')
@@ -85,6 +89,21 @@ test.describe('desktop shell smoke', () => {
8589
expect(window.url()).toBe(`${origin}/home`)
8690
})
8791

92+
test('presents one stock Chrome user agent on every request from the first load', async () => {
93+
requestUserAgents.length = 0
94+
app = await launchApp(origin)
95+
const window = await app.firstWindow()
96+
await expect(window.locator('#app')).toHaveText('fixture-app')
97+
await window.evaluate(() => fetch('/home').then((response) => response.text()))
98+
99+
const pageUserAgent = await window.evaluate(() => navigator.userAgent)
100+
expect(pageUserAgent).toMatch(
101+
/^Mozilla\/5\.0 \(.+\) AppleWebKit\/537\.36 \(KHTML, like Gecko\) Chrome\/\d+\.0\.0\.0 Safari\/537\.36$/
102+
)
103+
expect(requestUserAgents.length).toBeGreaterThanOrEqual(2)
104+
expect(new Set(requestUserAgents)).toEqual(new Set([pageUserAgent]))
105+
})
106+
88107
test('internal window.open creates an independent full Sim window', async () => {
89108
app = await launchApp(origin)
90109
const window = await app.firstWindow()

0 commit comments

Comments
 (0)