Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make executeWorkbench work after VSCode restarts #106

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export default class VSCodeWorkerService implements Services.ServiceInstance {
}
}

private _handleSocketClose (code: number, reason: Buffer) {
const msg = `Connection closed. Code: ${code}, reason: ${reason.toString()}`
this._promisedSocket = Promise.reject(new Error(msg))
this._pendingMessages.forEach((resolver) => resolver(msg, null))
}

async beforeSession (option: Options.Testrunner, capabilities: VSCodeCapabilities) {
this._isWebSession = capabilities.browserName !== 'vscode'

Expand Down Expand Up @@ -103,9 +109,11 @@ export default class VSCodeWorkerService implements Services.ServiceInstance {
)
wss.on('connection', (socket) => {
log.info('Connected with VSCode workbench')
this._promisedSocket = Promise.resolve(socket)
resolve(socket)
clearTimeout(socketTimeout)
socket.on('message', this._handleIncoming.bind(this))
socket.once('close', this._handleSocketClose.bind(this))
})
})
}
Expand Down
15 changes: 15 additions & 0 deletions test/specs/workbench.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../../dist/service.d.ts" />

import path from 'node:path'
import { browser, expect } from '@wdio/globals'
import { skip } from './utils.js'

Expand Down Expand Up @@ -85,6 +86,20 @@ describe('workbench', () => {
})
})

it('can access the VSCode API after a new folder is opened', async () => {
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved
const workspaceRoot = await browser.executeWorkbench<string | undefined>((vscode) => vscode.workspace.rootPath)
expect(workspaceRoot).not.toBe(undefined)
const newWorkspaceRoot = path.join(workspaceRoot!, 'test')
await browser.executeWorkbench((vscode, newRoot) => {
const uri = vscode.Uri.file(newRoot)
vscode.commands.executeCommand('vscode.openFolder', uri)
}, newWorkspaceRoot)
await browser.waitUntil(async () => {
const root = await browser.executeWorkbench((vscode) => vscode.workspace.rootPath)
return root === newWorkspaceRoot
})
})

it('can send parameters to VSCode API invocation @skipWeb', async () => {
const workbench = await browser.getWorkbench()
const message = 'I passed this message as a parameter!'
Expand Down
Loading