Skip to content

Commit f2ce594

Browse files
update to async
1 parent ec55f05 commit f2ce594

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

packages/server/lib/browsers/chrome.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,13 @@ const _getChromePreferences = (userDir: string): Bluebird<ChromePreferences> =>
102102
}
103103

104104
// Reads raw preferences from disk and merges them with defaults
105-
const _getChromePreferencesWithDefaults = (userDir: string): Bluebird<ChromePreferences> => {
106-
return _getChromePreferences(userDir)
107-
.then((existingPrefs) => {
108-
// Merge default preferences with existing preferences
109-
const defaultPrefs = module.exports._getDefaultChromePreferences()
105+
const _getChromePreferencesWithDefaults = async (userDir: string): Promise<ChromePreferences> => {
106+
const existingPrefs = await _getChromePreferences(userDir)
110107

111-
return _mergeChromePreferences(defaultPrefs, existingPrefs)
112-
})
108+
// Merge default preferences with existing preferences
109+
const defaultPrefs = module.exports._getDefaultChromePreferences()
110+
111+
return _mergeChromePreferences(defaultPrefs, existingPrefs)
113112
}
114113

115114
const _mergeChromePreferences = (originalPrefs: ChromePreferences, newPrefs: ChromePreferences): ChromePreferences => {

packages/server/test/unit/browsers/chrome_spec.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ describe('lib/browsers/chrome', () => {
977977
})
978978
})
979979

980-
it('writes default preferences when they do not exist on disk', () => {
980+
it('writes default preferences when they do not exist on disk', async () => {
981981
const outputJson = sinon.stub(fs, 'outputJson')
982982
const defaultPrefs = outputJson.withArgs('/foo/Default/Preferences').resolves()
983983
const securePrefs = outputJson.withArgs('/foo/Default/Secure Preferences').resolves()
@@ -996,27 +996,25 @@ describe('lib/browsers/chrome', () => {
996996
// Get the default preferences that should be written
997997
const defaultChromePrefs = chrome._getDefaultChromePreferences()
998998

999-
expect(chrome._writeChromePreferences('/foo', originalPrefs, defaultChromePrefs)).to.eventually.equal()
1000-
.then(() => {
1001-
// Should write default preferences since they don't exist on disk
1002-
expect(defaultPrefs).to.be.calledWith('/foo/Default/Preferences', {
1003-
fake_preference: {
1004-
value: 'value',
1005-
},
1006-
})
999+
await chrome._writeChromePreferences('/foo', originalPrefs, defaultChromePrefs)
10071000

1008-
// defaultSecure is empty, so it should not be written
1009-
expect(securePrefs).to.not.be.called
1010-
1011-
expect(statePrefs).to.be.calledWith('/foo/Local State', {
1012-
fake_local_state: {
1013-
value: 'value',
1014-
},
1015-
})
1001+
// Should write default preferences since they don't exist on disk
1002+
expect(defaultPrefs).to.be.calledWith('/foo/Default/Preferences', {
1003+
fake_preference: {
1004+
value: 'value',
1005+
},
10161006
})
1017-
.finally(() => {
1018-
mockDefaultPrefs.restore()
1007+
1008+
// defaultSecure is empty, so it should not be written
1009+
expect(securePrefs).to.not.be.called
1010+
1011+
expect(statePrefs).to.be.calledWith('/foo/Local State', {
1012+
fake_local_state: {
1013+
value: 'value',
1014+
},
10191015
})
1016+
1017+
mockDefaultPrefs.restore()
10201018
})
10211019
})
10221020

0 commit comments

Comments
 (0)