[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

feat(browser): playwright provider doesn't allow resizing the browser viewport (#5984)

Co-authored-by: Vladimir Sheremet <sleuths.slews0s@icloud.com>

authored by

Joaquín Sánchez
Vladimir Sheremet
and committed by
GitHub
(Jul 1, 2024, 4:10 PM +0200) ff978e58 b1a27d40

+62 -7
+2 -2
test/browser/specs/runner.test.ts
··· 23 23 console.error(stderr) 24 24 }) 25 25 26 - expect(browserResultJson.testResults).toHaveLength(18) 27 - expect(passedTests).toHaveLength(16) 26 + expect(browserResultJson.testResults).toHaveLength(19) 27 + expect(passedTests).toHaveLength(17) 28 28 expect(failedTests).toHaveLength(2) 29 29 30 30 expect(stderr).not.toContain('has been externalized for browser compatibility')
+27
test/browser/test/viewport.test.ts
··· 1 + import { page, server } from '@vitest/browser/context' 2 + import { describe, expect, it } from 'vitest' 3 + 4 + describe.skipIf(server.provider === 'preview')('viewport window has been properly initialized', () => { 5 + it.skipIf(!page.config.browser.headless)('viewport has proper size', () => { 6 + const { width, height } = page.config.browser.viewport 7 + const { width: actualWidth, height: actualHeight } = window.document.documentElement.getBoundingClientRect() 8 + 9 + expect(actualWidth).toBe(width) 10 + expect(actualHeight).toBe(height) 11 + }) 12 + 13 + it.skipIf(page.config.browser.headless)('window has been maximized', () => { 14 + let topWindow = window 15 + while (topWindow.parent && topWindow !== topWindow.parent) { 16 + topWindow = topWindow.parent as unknown as any 17 + } 18 + 19 + // edge will show the Hub Apps right panel 20 + if (server.browser === 'edge') { 21 + expect(topWindow.visualViewport.width - topWindow.innerWidth === 0).toBe(true) 22 + } 23 + else { 24 + expect(screen.availWidth - topWindow.innerWidth === 0).toBe(true) 25 + } 26 + }) 27 + })
+20 -5
packages/browser/src/node/providers/playwright.ts
··· 1 1 import type { 2 2 Browser, 3 - 4 3 BrowserContext, 5 4 BrowserContextOptions, 6 5 Frame, ··· 67 66 68 67 const playwright = await import('playwright') 69 68 70 - const browser = await playwright[this.browserName].launch({ 69 + const launchOptions = { 71 70 ...this.options?.launch, 72 71 headless: options.headless, 73 - }) 72 + } satisfies LaunchOptions 73 + 74 + // start Vitest UI maximized only on supported browsers 75 + if (this.ctx.config.browser.ui && this.browserName === 'chromium') { 76 + if (!launchOptions.args) { 77 + launchOptions.args = [] 78 + } 79 + if (!launchOptions.args.includes('--start-maximized') && !launchOptions.args.includes('--start-fullscreen')) { 80 + launchOptions.args.push('--start-maximized') 81 + } 82 + } 83 + 84 + const browser = await playwright[this.browserName].launch(launchOptions) 74 85 this.browser = browser 75 86 this.browserPromise = null 76 87 return this.browser ··· 85 96 } 86 97 87 98 const browser = await this.openBrowser() 88 - const context = await browser.newContext({ 99 + const options = { 89 100 ...this.options?.context, 90 101 ignoreHTTPSErrors: true, 91 102 serviceWorkers: 'allow', 92 - }) 103 + } satisfies BrowserContextOptions 104 + if (this.ctx.config.browser.ui) { 105 + options.viewport = null 106 + } 107 + const context = await browser.newContext(options) 93 108 this.contexts.set(contextId, context) 94 109 return context 95 110 }
+13
packages/browser/src/node/providers/webdriver.ts
··· 104 104 capabilities[key] = { ...currentValues, args: newArgs as any } 105 105 } 106 106 107 + // start Vitest UI maximized only on supported browsers 108 + if (options.ui && (browser === 'chrome' || browser === 'edge')) { 109 + const key = browser === 'chrome' 110 + ? 'goog:chromeOptions' 111 + : 'ms:edgeOptions' 112 + const args = capabilities[key]?.args || [] 113 + if (!args.includes('--start-maximized') && !args.includes('--start-fullscreen')) { 114 + args.push('--start-maximized') 115 + } 116 + capabilities[key] ??= {} 117 + capabilities[key]!.args = args 118 + } 119 + 107 120 return capabilities 108 121 } 109 122