@web/test-runner-playwright
Advanced tools
Comparing version 0.4.16 to 0.4.17
# @web/test-runner-playwright | ||
## 0.4.17 | ||
### Patch Changes | ||
- 432f090: expose browser name from BrowserLauncher | ||
- 5b36825: prevent debug sessions from interferring with regular test sessions | ||
- Updated dependencies [432f090] | ||
- Updated dependencies [5b36825] | ||
- @web/test-runner-core@0.6.19 | ||
## 0.4.16 | ||
@@ -4,0 +14,0 @@ |
import { Browser, Page, LaunchOptions } from 'playwright'; | ||
import { BrowserLauncher, TestRunnerCoreConfig, TestSession, Viewport } from '@web/test-runner-core'; | ||
import { BrowserLauncher, TestRunnerCoreConfig, Viewport } from '@web/test-runner-core'; | ||
import { PlaywrightLauncherPage } from './PlaywrightLauncherPage'; | ||
@@ -13,2 +13,3 @@ export declare type ProductType = 'chromium' | 'firefox' | 'webkit'; | ||
private createPageFunction?; | ||
name: string; | ||
private config?; | ||
@@ -23,11 +24,11 @@ private testFiles?; | ||
constructor(product: ProductType, launchOptions: LaunchOptions, createPageFunction?: CreatePageFunction | undefined); | ||
start(config: TestRunnerCoreConfig, testFiles: string[]): Promise<string>; | ||
start(config: TestRunnerCoreConfig, testFiles: string[]): Promise<void>; | ||
stop(): Promise<void>; | ||
startSession(session: TestSession, url: string): Promise<void>; | ||
isActive(session: TestSession): boolean; | ||
startDebugSession(session: TestSession, url: string): Promise<void>; | ||
startSession(sessionId: string, url: string): Promise<void>; | ||
isActive(sessionId: string): boolean; | ||
startDebugSession(sessionId: string, url: string): Promise<void>; | ||
createNewPage(browser: Browser): Promise<PlaywrightLauncherPage>; | ||
stopSession(session: TestSession): Promise<import("@web/test-runner-core").SessionResult>; | ||
setViewport(session: TestSession, viewport: Viewport): Promise<void>; | ||
stopSession(sessionId: string): Promise<import("@web/test-runner-core").SessionResult>; | ||
setViewport(sessionId: string, viewport: Viewport): Promise<void>; | ||
} | ||
//# sourceMappingURL=PlaywrightLauncher.d.ts.map |
@@ -9,2 +9,5 @@ "use strict"; | ||
const PlaywrightLauncherPage_1 = require("./PlaywrightLauncherPage"); | ||
function capitalize(str) { | ||
return `${str[0].toUpperCase()}${str.substring(1)}`; | ||
} | ||
class PlaywrightLauncher { | ||
@@ -18,3 +21,4 @@ constructor(product, launchOptions, createPageFunction) { | ||
this.inactivePages = []; | ||
this.testCoveragePerSession = new WeakMap(); | ||
this.testCoveragePerSession = new Map(); | ||
this.name = capitalize(product); | ||
} | ||
@@ -25,3 +29,2 @@ async start(config, testFiles) { | ||
this.browser = await playwright_1.default[this.product].launch(this.launchOptions); | ||
return `${this.product[0].toUpperCase()}${this.product.substring(1)}`; | ||
} | ||
@@ -37,3 +40,3 @@ async stop() { | ||
} | ||
async startSession(session, url) { | ||
async startSession(sessionId, url) { | ||
var _a, _b; | ||
@@ -50,10 +53,10 @@ if (!((_a = this.browser) === null || _a === void 0 ? void 0 : _a.isConnected())) { | ||
} | ||
this.activePages.set(session.id, page); | ||
this.testCoveragePerSession.delete(session); | ||
this.activePages.set(sessionId, page); | ||
this.testCoveragePerSession.delete(sessionId); | ||
await page.runSession(url, !!((_b = this.config) === null || _b === void 0 ? void 0 : _b.coverage)); | ||
} | ||
isActive(session) { | ||
return this.activePages.has(session.id); | ||
isActive(sessionId) { | ||
return this.activePages.has(sessionId); | ||
} | ||
async startDebugSession(session, url) { | ||
async startDebugSession(sessionId, url) { | ||
if (!this.debugBrowser) { | ||
@@ -65,5 +68,5 @@ this.debugBrowser = await playwright_1.default[this.product].launch(Object.assign(Object.assign({}, this.launchOptions), { | ||
const page = await this.createNewPage(this.debugBrowser); | ||
this.activeDebugPages.set(session.id, page); | ||
this.activeDebugPages.set(sessionId, page); | ||
page.playwrightPage.on('close', () => { | ||
this.activeDebugPages.delete(session.id); | ||
this.activeDebugPages.delete(sessionId); | ||
}); | ||
@@ -78,7 +81,7 @@ await page.runSession(url, false); | ||
} | ||
async stopSession(session) { | ||
const page = this.activePages.get(session.id); | ||
async stopSession(sessionId) { | ||
const page = this.activePages.get(sessionId); | ||
if (page) { | ||
const result = await page.stopSession(); | ||
this.activePages.delete(session.id); | ||
this.activePages.delete(sessionId); | ||
this.inactivePages.push(page); | ||
@@ -88,10 +91,10 @@ return result; | ||
else { | ||
throw new Error(`No page for session ${session.id}`); | ||
throw new Error(`No page for session ${sessionId}`); | ||
} | ||
} | ||
setViewport(session, viewport) { | ||
const page = this.activePages.get(session.id); | ||
const debugPage = this.activeDebugPages.get(session.id); | ||
setViewport(sessionId, viewport) { | ||
const page = this.activePages.get(sessionId); | ||
const debugPage = this.activeDebugPages.get(sessionId); | ||
if (!page && !debugPage) { | ||
throw new Error(`Cannot set viewport for inactive session: ${session.id}`); | ||
throw new Error(`Cannot set viewport for inactive session: ${sessionId}`); | ||
} | ||
@@ -98,0 +101,0 @@ return (page || debugPage).playwrightPage.setViewportSize(viewport); |
{ | ||
"name": "@web/test-runner-playwright", | ||
"version": "0.4.16", | ||
"version": "0.4.17", | ||
"publishConfig": { | ||
@@ -40,3 +40,3 @@ "access": "public" | ||
"@web/browser-logs": "^0.0.1", | ||
"@web/test-runner-core": "^0.6.18", | ||
"@web/test-runner-core": "^0.6.19", | ||
"@web/test-runner-coverage-v8": "^0.0.4", | ||
@@ -47,5 +47,5 @@ "playwright": "^1.2.1" | ||
"@web/test-runner-mocha": "^0.2.9", | ||
"@web/test-runner-server": "^0.5.12", | ||
"@web/test-runner-server": "^0.5.13", | ||
"portfinder": "^1.0.26" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27342
238