Skip to content

Commit 3351489

Browse files
committed
rework
1 parent 3b21906 commit 3351489

File tree

2 files changed

+13
-50
lines changed

2 files changed

+13
-50
lines changed

packages/server/lib/browsers/browser-cri-client.ts

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type BrowserCriClientOptions = {
2626
browserName: string
2727
onAsynchronousError: (err: CypressError) => void
2828
protocolManager?: ProtocolManagerShape
29-
cyPromptManager?: CyPromptManagerShape
3029
fullyManageTabs?: boolean
3130
onServiceWorkerClientEvent: ServiceWorkerEventHandler
3231
}
@@ -211,7 +210,6 @@ export class BrowserCriClient {
211210
this.browserName = options.browserName
212211
this.onAsynchronousError = options.onAsynchronousError
213212
this.protocolManager = options.protocolManager
214-
this.cyPromptManager = options.cyPromptManager
215213
this.fullyManageTabs = options.fullyManageTabs
216214
this.onServiceWorkerClientEvent = options.onServiceWorkerClientEvent
217215
}
@@ -228,7 +226,6 @@ export class BrowserCriClient {
228226
* @param options.onReconnect callback for when the browser cri client reconnects to the browser
229227
* @param options.port the port to which to connect
230228
* @param options.protocolManager the protocol manager to use with the browser cri client
231-
* @param options.cyPromptManager the cy.prompt() manager to use with the browser cri client
232229
* @param options.onServiceWorkerClientEvent callback for when a service worker fetch event is received
233230
* @returns a wrapper around the chrome remote interface that is connected to the browser target
234231
*/
@@ -241,7 +238,6 @@ export class BrowserCriClient {
241238
onReconnect,
242239
port,
243240
protocolManager,
244-
cyPromptManager,
245241
onServiceWorkerClientEvent,
246242
} = options
247243

@@ -266,7 +262,6 @@ export class BrowserCriClient {
266262
browserName,
267263
onAsynchronousError,
268264
protocolManager,
269-
cyPromptManager,
270265
fullyManageTabs,
271266
onServiceWorkerClientEvent,
272267
})
@@ -569,32 +564,14 @@ export class BrowserCriClient {
569564
browserClient: this.browserClient,
570565
})
571566

572-
const currentTarget = this.currentlyAttachedTarget
573-
574-
const createProtocolTarget = async () => {
575-
// Clone the target here so that we separate the protocol client and the main client.
576-
// This allows us to close the protocol client independently of the main client
577-
// which we do when we exit out of studio in open mode.
578-
if (!this.currentlyAttachedProtocolTarget) {
579-
this.currentlyAttachedProtocolTarget = await currentTarget.clone()
580-
}
581-
582-
await this.protocolManager?.connectToBrowser(this.currentlyAttachedProtocolTarget)
567+
// Clone the target here so that we separate the protocol client and the main client.
568+
// This allows us to close the protocol client independently of the main client
569+
// which we do when we exit out of studio in open mode.
570+
if (!this.currentlyAttachedProtocolTarget) {
571+
this.currentlyAttachedProtocolTarget = await this.currentlyAttachedTarget.clone()
583572
}
584573

585-
const createCyPromptTarget = async () => {
586-
// Clone the cy.prompt() target here so that we separate the cy.prompt() client and the main client.
587-
if (!this.currentlyAttachedCyPromptTarget) {
588-
this.currentlyAttachedCyPromptTarget = await currentTarget.clone()
589-
}
590-
591-
await this.cyPromptManager?.connectToBrowser(this.currentlyAttachedCyPromptTarget)
592-
}
593-
594-
await Promise.all([
595-
createProtocolTarget(),
596-
createCyPromptTarget(),
597-
])
574+
await this.protocolManager?.connectToBrowser(this.currentlyAttachedProtocolTarget)
598575

599576
return this.currentlyAttachedTarget
600577
}, this.browserName, this.port)

packages/server/test/unit/browsers/browser-cri-client_spec.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ describe('lib/browsers/browser-cri-client', function () {
6060
'chrome-remote-interface': criImport,
6161
})
6262

63-
getClient = ({ protocolManager, cyPromptManager, fullyManageTabs } = {}) => {
63+
getClient = ({ protocolManager, fullyManageTabs } = {}) => {
6464
criClientCreateStub = criClientCreateStub.withArgs({ target: 'http://web/socket/url', onAsynchronousError: onError, onReconnect: undefined, protocolManager, fullyManageTabs }).resolves({
6565
send,
6666
on,
6767
close,
6868
})
6969

70-
return browserCriClient.BrowserCriClient.create({ hosts: ['127.0.0.1'], port: PORT, browserName: 'Chrome', onAsynchronousError: onError, protocolManager, cyPromptManager, fullyManageTabs, onServiceWorkerClientEvent })
70+
return browserCriClient.BrowserCriClient.create({ hosts: ['127.0.0.1'], port: PORT, browserName: 'Chrome', onAsynchronousError: onError, protocolManager, fullyManageTabs, onServiceWorkerClientEvent })
7171
}
7272
})
7373

@@ -455,9 +455,8 @@ describe('lib/browsers/browser-cri-client', function () {
455455
context('#attachToTargetUrl', function () {
456456
it('creates a page client when the passed in url is found', async function () {
457457
const mockProtocolClient = {}
458-
const mockCyPromptClient = {}
459458
const mockPageClient = {
460-
clone: sinon.stub().onFirstCall().returns(mockProtocolClient).onSecondCall().returns(mockCyPromptClient),
459+
clone: sinon.stub().onFirstCall().returns(mockProtocolClient),
461460
}
462461

463462
send.withArgs('Target.getTargets').resolves({ targetInfos: [{ targetId: '1', url: 'http://foo.com' }, { targetId: '2', url: 'http://bar.com' }] })
@@ -469,50 +468,39 @@ describe('lib/browsers/browser-cri-client', function () {
469468

470469
expect(client).to.be.equal(mockPageClient)
471470
expect(browserClient.currentlyAttachedProtocolTarget).to.be.equal(mockProtocolClient)
472-
expect(browserClient.currentlyAttachedCyPromptTarget).to.be.equal(mockCyPromptClient)
473471
})
474472

475473
it('creates a page client when the passed in url is found and notifies the protocol manager and fully managed tabs', async function () {
476474
const mockProtocolClient = {}
477-
const mockCyPromptClient = {}
478475
const mockPageClient = {
479-
clone: sinon.stub().onFirstCall().returns(mockProtocolClient).onSecondCall().returns(mockCyPromptClient),
476+
clone: sinon.stub().onFirstCall().returns(mockProtocolClient),
480477
}
481478
const protocolManager: any = {
482479
connectToBrowser: sinon.stub().resolves(),
483480
}
484-
const cyPromptManager: any = {
485-
connectToBrowser: sinon.stub().resolves(),
486-
}
487481

488482
send.withArgs('Target.getTargets').resolves({ targetInfos: [{ targetId: '1', url: 'http://foo.com' }, { targetId: '2', url: 'http://bar.com' }] })
489483
send.withArgs('Target.setDiscoverTargets', { discover: true })
490484
on.withArgs('Target.targetDestroyed', sinon.match.func)
491485
criClientCreateStub.withArgs({ target: '1', onAsynchronousError: onError, host: HOST, port: PORT, protocolManager, fullyManageTabs: true, browserClient: { on, send, close } }).resolves(mockPageClient)
492486

493-
const browserClient = await getClient({ protocolManager, cyPromptManager, fullyManageTabs: true })
487+
const browserClient = await getClient({ protocolManager, fullyManageTabs: true })
494488

495489
const client = await browserClient.attachToTargetUrl('http://foo.com')
496490

497491
expect(client).to.be.equal(mockPageClient)
498492
expect(browserClient.currentlyAttachedProtocolTarget).to.be.equal(mockProtocolClient)
499-
expect(browserClient.currentlyAttachedCyPromptTarget).to.be.equal(mockCyPromptClient)
500493
expect(protocolManager.connectToBrowser).to.be.calledWith(browserClient.currentlyAttachedProtocolTarget)
501-
expect(cyPromptManager.connectToBrowser).to.be.calledWith(browserClient.currentlyAttachedCyPromptTarget)
502494
})
503495

504496
it('creates a page client when the passed in url is found and notifies the protocol manager and fully managed tabs and attaching to target throws', async function () {
505497
const mockProtocolClient = {}
506-
const mockCyPromptClient = {}
507498
const mockPageClient = {
508-
clone: sinon.stub().onFirstCall().returns(mockProtocolClient).onSecondCall().returns(mockCyPromptClient),
499+
clone: sinon.stub().onFirstCall().returns(mockProtocolClient),
509500
}
510501
const protocolManager: any = {
511502
connectToBrowser: sinon.stub().resolves(),
512503
}
513-
const cyPromptManager: any = {
514-
connectToBrowser: sinon.stub().resolves(),
515-
}
516504

517505
send.withArgs('Target.getTargets').resolves({ targetInfos: [{ targetId: '1', url: 'http://foo.com' }, { targetId: '2', url: 'http://bar.com' }] })
518506
send.withArgs('Target.setDiscoverTargets', { discover: true })
@@ -522,15 +510,13 @@ describe('lib/browsers/browser-cri-client', function () {
522510

523511
criClientCreateStub.withArgs({ target: '1', onAsynchronousError: onError, host: HOST, port: PORT, protocolManager, fullyManageTabs: true, browserClient: { on, send, close } }).resolves(mockPageClient)
524512

525-
const browserClient = await getClient({ protocolManager, cyPromptManager, fullyManageTabs: true })
513+
const browserClient = await getClient({ protocolManager, fullyManageTabs: true })
526514

527515
const client = await browserClient.attachToTargetUrl('http://foo.com')
528516

529517
expect(client).to.be.equal(mockPageClient)
530518
expect(browserClient.currentlyAttachedProtocolTarget).to.be.equal(mockProtocolClient)
531-
expect(browserClient.currentlyAttachedCyPromptTarget).to.be.equal(mockCyPromptClient)
532519
expect(protocolManager.connectToBrowser).to.be.calledWith(browserClient.currentlyAttachedProtocolTarget)
533-
expect(cyPromptManager.connectToBrowser).to.be.calledWith(browserClient.currentlyAttachedCyPromptTarget)
534520

535521
// This would throw if the error was not caught
536522
await on.withArgs('Target.attachedToTarget').args[0][1]({ targetInfo: { type: 'worker' } })

0 commit comments

Comments
 (0)