Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jul 10, 2020
1 parent b4ab623 commit c00f6cd
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions packages/server/test/unit/browsers/firefox_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as firefox from '../../../lib/browsers/firefox'
import { EventEmitter } from 'events'
import Marionette from 'marionette-client'
import Foxdriver from '@benmalka/foxdriver'
import os from 'os'
const mockfs = require('mock-fs')
const FirefoxProfile = require('firefox-profile')
const utils = require('../../../lib/browsers/utils')
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('lib/browsers/firefox', () => {
const browser = {
listTabs: sinon.stub().resolves([foxdriverTab]),
request: sinon.stub().withArgs('listTabs').resolves({ tabs: [foxdriverTab] }),
on: sinon.stub(),
}

foxdriver = {
Expand Down Expand Up @@ -102,14 +104,18 @@ describe('lib/browsers/firefox', () => {
browser: this.browser,
}

this.browserInstance = {
// should be high enough to not kill any real PIDs
pid: Number.MAX_SAFE_INTEGER,
}

sinon.stub(process, 'pid').value(1111)

protocol.foo = 'bar'

sinon.stub(plugins, 'has')
sinon.stub(plugins, 'execute')
sinon.stub(utils, 'writeExtension').resolves('/path/to/ext')
this.browserInstance = {}
sinon.stub(utils, 'launch').resolves(this.browserInstance)
sinon.spy(FirefoxProfile.prototype, 'setPreference')
sinon.spy(FirefoxProfile.prototype, 'updatePreferences')
Expand Down Expand Up @@ -201,7 +207,7 @@ describe('lib/browsers/firefox', () => {

it('writes extension', function () {
return firefox.open(this.browser, 'http://', this.options).then(() => {
expect(utils.writeExtension).to.be.calledWith(this.options.browser, this.options.isTextTerminal, this.options.proxyUrl, this.options.socketIoRoute, this.options.onScreencastFrame)
expect(utils.writeExtension).to.be.calledWith(this.options.browser, this.options.isTextTerminal, this.options.proxyUrl, this.options.socketIoRoute)
})
})

Expand Down Expand Up @@ -322,6 +328,29 @@ describe('lib/browsers/firefox', () => {
expect(wrapperErr.message).to.include(err.message)
})
})

context('returns BrowserInstance', function () {
it('from browsers.launch', async function () {
const instance = await firefox.open(this.browser, 'http://', this.options)

expect(instance).to.eq(this.browserInstance)
})

// @see https://github.com/cypress-io/cypress/issues/6392
it('detached on Windows', async function () {
sinon.stub(os, 'platform').returns('win32')
const instance = await firefox.open(this.browser, 'http://', this.options)

expect(instance).to.not.eq(this.browserInstance)
expect(instance.pid).to.eq(this.browserInstance.pid)

await new Promise((resolve) => {
// ensure events are wired as expected
instance.on('exit', resolve)
instance.kill()
})
})
})
})

context('firefox-util', () => {
Expand Down

0 comments on commit c00f6cd

Please sign in to comment.