Skip to content

Commit

Permalink
Allow verbose logging for VSCode extension host (#8)
Browse files Browse the repository at this point in the history
* debug caps

* test for notification

* fix assertion

* enable verbose logging

* elliminate dashes

* set extensions-dir

* don't disable extensions

* skip test on windows due to #4
  • Loading branch information
christian-bromann authored Mar 29, 2022
1 parent 18f697e commit 2b19533
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 151 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"wdio-chromedriver-service": "^7.3.2"
},
"peerDependencies": {
"webdriverio": "^7.19.1"
"webdriverio": "^7.19.2"
},
"peerDependenciesMeta": {
"webdriverio": {
Expand Down
6 changes: 5 additions & 1 deletion src/pageobjects/workbench/Notification.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ChainablePromiseElement } from 'webdriverio'
import { BasePage, IPluginDecorator, VSCodeLocatorMap } from '../utils'
import {
BasePage, IPluginDecorator, PluginDecorator, VSCodeLocatorMap
} from '../utils'
import { Notification as NotificationLocators } from '../../locators/1.61.0'

/**
Expand Down Expand Up @@ -145,6 +147,7 @@ export abstract class Notification extends BasePage<typeof NotificationLocators>
*
* @category Workbench
*/
@PluginDecorator(NotificationLocators)
export class StandaloneNotification extends Notification {
/**
* @private
Expand All @@ -164,6 +167,7 @@ export class StandaloneNotification extends Notification {
*
* @category Workbench
*/
@PluginDecorator(NotificationLocators)
export class CenterNotification extends Notification {
/**
* @private
Expand Down
28 changes: 16 additions & 12 deletions src/pageobjects/workbench/Workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,26 @@ export class Workbench extends BasePage<typeof WorkbenchLocators> {
*/
async getNotifications (): Promise<Notification[]> {
const notifications: Notification[] = []
const container = await this.notificationContainer$
const containers = await this.notificationContainer$$

if (!await container.isExisting()) {
if (containers.length === 0) {
return []
}
const elements = await container.$$(this.locators.notificationItem)

for (const element of elements) {
notifications.push(
await new StandaloneNotification(
this.locatorMap,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
element as any
).wait()
)

for (const container of containers) {
const elements = await container.$$(this.locators.notificationItem)

for (const element of elements) {
notifications.push(
await new StandaloneNotification(
this.locatorMap,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
element as any
).wait()
)
}
}

return notifications
}

Expand Down
38 changes: 34 additions & 4 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { SevereServiceError } from 'webdriverio'
import { Workbench } from './pageobjects'
import { getLocators } from './utils'
import { VSCODE_APPLICATION_ARGS, DEFAULT_VSCODE_SETTINGS } from './constants'
import type { ServiceOptions, ServiceCapabilities } from './types'
import type { ServiceOptions, ServiceCapabilities, WDIOLogs } from './types'

const log = logger('wdio-vscode-service')

export default class VSCodeWorkerService implements Services.ServiceInstance {
private _browser?: WebdriverIO.Browser

constructor (private _options: ServiceOptions) {}

async beforeSession (_: Options.Testrunner, capabilities: ServiceCapabilities) {
Expand Down Expand Up @@ -43,13 +45,18 @@ export default class VSCodeWorkerService implements Services.ServiceInstance {
customArgs.push(`--file-uri=${this._options.filePath}`)
}

if (this._options.verboseLogging) {
customArgs.push('--verbose', '--logExtensionHostCommunication')
}

capabilities.browserName = 'chrome'
capabilities['goog:chromeOptions'] = {
binary: capabilities['wdio:vscodeService'].vscode.path,
args: [
...VSCODE_APPLICATION_ARGS,
`--extensionDevelopmentPath=${this._options.extensionPath}`,
`--user-data-dir=${path.join(storagePath.path, 'settings')}`,
`--extensions-dir=${path.join(storagePath.path, 'extensions')}`,
...customArgs,
...(this._options.args || [])
].filter(Boolean),
Expand All @@ -58,15 +65,38 @@ export default class VSCodeWorkerService implements Services.ServiceInstance {
}

async before (capabilities: ServiceCapabilities, __: never, browser: WebdriverIO.Browser) {
this._browser = browser
const locators = await getLocators(capabilities['wdio:vscodeService'].vscode.version)
const workbenchPO = new Workbench(locators)
browser.addCommand('getWorkbench', () => workbenchPO.wait())
browser.addCommand('getVSCodeVersion', () => capabilities['wdio:vscodeService'].vscode.version)
browser.addCommand('getVSCodeChannel', () => (
this._browser.addCommand('getWorkbench', () => workbenchPO.wait())
this._browser.addCommand('getVSCodeVersion', () => capabilities['wdio:vscodeService'].vscode.version)
this._browser.addCommand('getVSCodeChannel', () => (
capabilities['wdio:vscodeService'].vscode.version === 'insiders' ? 'insiders' : 'vscode'
))
return workbenchPO.elem.waitForExist()
}

async after () {
if (!this._browser || !this._options.verboseLogging) {
return
}

const logs = await this._browser.getLogs('browser').then(
(res) => res as WDIOLogs[],
(err) => err as Error
)

if (logs instanceof Error) {
return
}

for (const l of logs) {
log.info(
`[${(new Date(l.timestamp)).toISOString()}]`
+ ` - ${l.source} - ${l.message}`
)
}
}
}

declare global {
Expand Down
14 changes: 14 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export interface ServiceOptions extends ChromedriverServiceOptions {
* Additional start-up arguments
*/
args?: string[]
/**
* If set to true, service logs VSCode output from the extension host
* and console API
*
* @default `true`
*/
verboseLogging?: boolean
}

export interface BundleInformation {
Expand All @@ -55,3 +62,10 @@ export interface ServiceCapability {
export interface ServiceCapabilities extends Capabilities.Capabilities {
'wdio:vscodeService': ServiceCapability
}

export interface WDIOLogs {
level: string
message: string
source: string
timestamp: number
}
16 changes: 14 additions & 2 deletions test/specs/basic.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
/// <reference path="../../dist/service.d.ts" />

import {
PluginDecorator, IPluginDecorator, BasePage, BottomBarPanel,
ExtensionsViewSection
PluginDecorator, IPluginDecorator, BasePage, BottomBarPanel
} from '../..'

const skipWindows = process.platform === 'win32' ? it.skip : it

const locators = {
marquee: {
elem: 'ul[aria-label="Active View Switcher"]',
Expand Down Expand Up @@ -47,6 +48,17 @@ describe('WDIO VSCode Service', () => {
expect(title).toContain('wdio-vscode-service')
})

skipWindows('is able to read guinea pig notification', async () => {
const workbench = await browser.getWorkbench()
await browser.waitUntil(async () => {
const notifs = await workbench.getNotifications()
const messages = await Promise.all(notifs.map((n) => n.getMessage()))
return messages.includes('Hello World!')
}, {
timeoutMsg: 'Could not find test extension notification'
})
})

describe('activity bar', () => {
it('should show all activity bar items', async () => {
const workbench = await browser.getWorkbench()
Expand Down
Loading

0 comments on commit 2b19533

Please sign in to comment.