Skip to content

Commit

Permalink
fix(desktop-gui): remember last browser used w/ non-default channel (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Aug 15, 2020
1 parent 42da359 commit 204cb01
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
3 changes: 3 additions & 0 deletions packages/desktop-gui/cypress/fixtures/browsers.json
Expand Up @@ -3,6 +3,7 @@
"name": "chrome",
"displayName": "Chrome",
"family": "chromium",
"channel": "stable",
"version": "50.0.2661.86",
"path": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"majorVersion": "50"
Expand All @@ -11,6 +12,7 @@
"name": "chromium",
"displayName": "Chromium",
"family": "chromium",
"channel": "stable",
"version": "49.0.2609.0",
"path": "/Users/bmann/Downloads/chrome-mac/Chromium.app/Contents/MacOS/Chromium",
"majorVersion": "49"
Expand All @@ -19,6 +21,7 @@
"name": "chrome",
"displayName": "Canary",
"family": "chromium",
"channel": "canary",
"version": "48.0",
"path": "/Users/bmann/Downloads/chrome-mac/Canary.app/Contents/MacOS/Canary",
"majorVersion": "48"
Expand Down
12 changes: 12 additions & 0 deletions packages/desktop-gui/cypress/fixtures/config.json
Expand Up @@ -7,6 +7,7 @@
"name": "chrome",
"displayName": "Chrome",
"family": "chromium",
"channel": "stable",
"version": "78.0.3904.108",
"path": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"majorVersion": "78"
Expand All @@ -15,6 +16,7 @@
"name": "chromium",
"displayName": "Chromium",
"family": "chromium",
"channel": "stable",
"version": "74.0.3729.0",
"path": "/Applications/Chromium.app/Contents/MacOS/Chromium",
"majorVersion": "74"
Expand All @@ -23,6 +25,7 @@
"name": "chrome",
"displayName": "Canary",
"family": "chromium",
"channel": "canary",
"version": "80.0.3977.4",
"path": "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
"majorVersion": "80"
Expand All @@ -31,6 +34,7 @@
"name": "edge",
"displayName": "Edge",
"family": "chromium",
"channel": "stable",
"version": "79.0.309.71",
"path": "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
"majorVersion": "79"
Expand All @@ -39,6 +43,7 @@
"name": "edge",
"displayName": "Edge Beta",
"family": "chromium",
"channel": "beta",
"version": "79.0.309.71",
"path": "/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta",
"majorVersion": "79"
Expand All @@ -47,6 +52,7 @@
"name": "edge",
"displayName": "Edge Canary",
"family": "chromium",
"channel": "canary",
"version": "79.0.309.71",
"path": "/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary",
"majorVersion": "79"
Expand All @@ -55,6 +61,7 @@
"name": "edge",
"displayName": "Edge Dev",
"family": "chromium",
"channel": "dev",
"version": "79.0.309.71",
"path": "/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev",
"majorVersion": "79"
Expand All @@ -63,6 +70,7 @@
"name": "electron",
"displayName": "Electron",
"family": "chromium",
"channel": "stable",
"version": "73.0.3683.121",
"path": "",
"majorVersion": "73",
Expand All @@ -72,13 +80,15 @@
"name": "firefox",
"displayName": "Firefox",
"family": "firefox",
"channel": "stable",
"version": "69.0.1",
"path": "/Applications/Firefox/Contents/MacOS/Firefox",
"majorVersion": "69"
},
{
"name": "firefox",
"displayName": "Firefox Developer Edition",
"channel": "dev",
"family": "firefox",
"version": "69.0.1",
"path": "/Applications/Firefox Developer/Contents/MacOS/Firefox Developer",
Expand All @@ -87,6 +97,7 @@
{
"name": "firefox",
"displayName": "Firefox Nightly",
"channel": "beta",
"family": "firefox",
"version": "69.0.1",
"path": "/Applications/Firefox Nightly/Contents/MacOS/Firefox Nightly",
Expand All @@ -96,6 +107,7 @@
{
"name": "custom",
"displayName": "Custom",
"channel": "dev",
"family": "custom",
"version": "4.3.2",
"path": "/Applications/Custom/Contents/MacOS/Custom",
Expand Down
41 changes: 29 additions & 12 deletions packages/desktop-gui/cypress/integration/project_nav_spec.js
Expand Up @@ -215,7 +215,7 @@ describe('Project Nav', function () {
})

it('saves chosen browser in local storage', () => {
expect(localStorage.getItem('chosenBrowser')).to.eq('chromium')
expect(localStorage.getItem('chosenBrowser')).to.eq(JSON.stringify({ name: 'chromium', channel: 'stable' }))
})
})

Expand Down Expand Up @@ -318,25 +318,42 @@ describe('Project Nav', function () {
})

describe('local storage saved browser', function () {
beforeEach(function () {
localStorage.setItem('chosenBrowser', 'chromium')
afterEach(() => {
cy.clearLocalStorage()
})

it('displays chosen browser in localStorage', function () {
// deliberately not the default 'chrome' browser
// @see https://github.com/cypress-io/cypress/issues/8281
localStorage.setItem('chosenBrowser', JSON.stringify({
name: 'chrome',
channel: 'canary',
}))

this.openProject.resolve(this.config)
})

afterEach(() => {
cy.clearLocalStorage()
cy.get('.browsers-list .dropdown-chosen')
.should('contain', 'Canary').and('not.contain', 'Edge')
.get('.dropdown-chosen .browser-icon')
.should('have.attr', 'src').and('include', './img/chrome-canary')
})

it('displays local storage browser name in chosen', () => {
it('displays chosen browser with old string-style id in localStorage', function () {
localStorage.setItem('chosenBrowser', 'chrome')

this.openProject.resolve(this.config)

cy.get('.browsers-list .dropdown-chosen')
.should('contain', 'Chromium')
.should('contain', 'Chrome')
})

it('displays local storage browser icon in chosen', () => {
cy.get('.browsers-list .dropdown-chosen .browser-icon')
.should('have.attr', 'src')
.and('include', './img/chromium')
it('displays default browser with null localStorage', function () {
localStorage.removeItem('chosenBrowser')

this.openProject.resolve(this.config)

cy.get('.browsers-list .dropdown-chosen')
.should('contain', this.config.browsers[0].displayName)
})
})

Expand Down
1 change: 0 additions & 1 deletion packages/desktop-gui/src/project-nav/browsers.jsx
Expand Up @@ -77,7 +77,6 @@ export default class Browsers extends Component {
{browser.family === 'firefox' && <span className='browser-beta'>beta</span>}
{this._info(browser)}
{this._warn(browser)}

</>
)
}
Expand Down
21 changes: 16 additions & 5 deletions packages/desktop-gui/src/project/project-model.js
Expand Up @@ -180,8 +180,10 @@ export default class Project {
return this.setChosenBrowser(customBrowser, { save: false })
}

if (localStorage.getItem('chosenBrowser')) {
return this.setChosenBrowserByName(localStorage.getItem('chosenBrowser'))
const ls = localStorage.getItem('chosenBrowser')

if (ls) {
return this.setChosenBrowserFromLocalStorage(ls)
}

return this.setChosenBrowser(this.defaultBrowser)
Expand All @@ -194,7 +196,7 @@ export default class Project {
})

if (save !== false) {
localStorage.setItem('chosenBrowser', browser.name)
localStorage.setItem('chosenBrowser', JSON.stringify(_.pick(browser, 'name', 'channel')))
}

browser.isChosen = true
Expand Down Expand Up @@ -250,8 +252,17 @@ export default class Project {
this.apiError = err
}

@action setChosenBrowserByName (name) {
const browser = _.find(this.browsers, { name }) || this.defaultBrowser
@action setChosenBrowserFromLocalStorage (ls) {
let filter = {}

try {
_.merge(filter, JSON.parse(ls))
} catch (err) {
// localStorage pre-dates JSON filter, assume "name"
filter.name = ls
}

const browser = _.find(this.browsers, filter) || this.defaultBrowser

this.setChosenBrowser(browser)
}
Expand Down

3 comments on commit 204cb01

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 204cb01 Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/linux-x64/circle-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-422930/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/circle-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-422918/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 204cb01 Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 204cb01 Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-204cb016ff4dac056d5d8f5231b6cbbbf9c8fa49-34675755/cypress.tgz

Please sign in to comment.