Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Apr 17, 2020
1 parent 58ca014 commit f2809ea
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe('Project Nav', function () {
const browserArg = this.ipc.launchBrowser.getCall(0).args[0].browser

expect(browserArg).to.have.keys([
'family', 'name', 'path', 'version', 'majorVersion', 'displayName', 'info', 'isChosen', 'custom', 'warning', 'channel',
'family', 'name', 'path', 'profilePath', 'version', 'majorVersion', 'displayName', 'info', 'isChosen', 'custom', 'warning', 'channel',
])

expect(browserArg.path).to.include('/')
Expand Down
4 changes: 2 additions & 2 deletions packages/launcher/lib/linux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function getLinuxBrowser (

const maybeSetSnapProfilePath = (versionString: string) => {
if (os.platform() === 'linux' && name === 'chromium' && versionString.endsWith('snap')) {
// when running as a snap, chromium can only write to one directory
// @see https://cs.chromium.org/chromium/src/chrome/installer/linux/snap/snapcraft.yaml.in?l=59-61&rcl=6fb05bb3738f37392dde9cd2783637f09d5aa3f4
// when running as a snap, chromium can only write to certain directories
// @see https://github.com/cypress-io/cypress/issues/7020
foundBrowser.profilePath = path.join(os.homedir(), 'snap', 'chromium', 'current')
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/launcher/test/unit/linux_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('linux browser detection', () => {
displayName: 'Chromium',
majorVersion: 1,
path: 'chromium',
profilePath: '/home/foo/.config/chromium',
profilePath: '/home/foo/snap/chromium/current',
version: '1.2.3',
})
}
Expand Down
12 changes: 6 additions & 6 deletions packages/server/lib/browsers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const extension = require('@packages/extension')
const appData = require('../util/app_data')
const profileCleaner = require('../util/profile_cleaner')

const PATH_TO_BROWSERS = appData.path('browsers')
const legacyPathToProfiles = path.join(PATH_TO_BROWSERS, '*')
const pathToBrowsers = appData.path('browsers')
const legacyProfilesWildcard = path.join(pathToBrowsers, '*')

const getAppDataPath = (browser) => {
if (!browser || !browser.profilePath) {
return PATH_TO_BROWSERS
return pathToBrowsers
}

return path.join(browser.profilePath, 'Cypress')
Expand Down Expand Up @@ -95,9 +95,9 @@ const ensureCleanCache = async function (browser, isTextTerminal) {
// we now store profiles inside the Cypress binary folder
// so we need to remove the legacy root profiles that existed before
function removeLegacyProfiles () {
return profileCleaner.removeRootProfile(legacyPathToProfiles, [
path.join(legacyPathToProfiles, 'run-*'),
path.join(legacyPathToProfiles, 'interactive'),
return profileCleaner.removeRootProfile(legacyProfilesWildcard, [
path.join(legacyProfilesWildcard, 'run-*'),
path.join(legacyProfilesWildcard, 'interactive'),
])
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/integration/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ describe('lib/cypress', () => {
osVersion: 'v1',
})

sinon.stub(browsers, 'ensureAndGetByNameOrPath').returns({
sinon.stub(browsers, 'ensureAndGetByNameOrPath').resolves({
version: '59.1.2.3',
displayName: 'Electron',
})
Expand Down
25 changes: 25 additions & 0 deletions packages/server/test/unit/browsers/chrome_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ describe "lib/browsers/chrome", ->
"--disk-cache-dir=/profile/dir/CypressCache"
])

it "uses a custom profilePath if supplied", ->
chrome._writeExtension.restore()
utils.getProfileDir.restore()

profilePath = '/home/foo/snap/chromium/current'
fullPath = "#{profilePath}/Cypress/chromium-stable/interactive"

@readJson.withArgs("#{fullPath}/Default/Preferences").rejects({ code: 'ENOENT' })
@readJson.withArgs("#{fullPath}/Default/Secure Preferences").rejects({ code: 'ENOENT' })
@readJson.withArgs("#{fullPath}/Local State").rejects({ code: 'ENOENT' })

chrome.open({
isHeadless: true,
isHeaded: false,
profilePath,
name: 'chromium',
channel: 'stable'
}, "http://", {}, @automation)
.then =>
args = utils.launch.firstCall.args[2]

expect(args).to.include.members([
"--user-data-dir=#{fullPath}"
])

it "DEPRECATED: normalizes --load-extension if provided in plugin", ->
plugins.register 'before:browser:launch', (browser, config) ->
return Promise.resolve(["--foo=bar", "--load-extension=/foo/bar/baz.js"])
Expand Down

0 comments on commit f2809ea

Please sign in to comment.