diff --git a/src/chrome-launcher.ts b/src/chrome-launcher.ts index 5d53a65f3..7b769b77b 100644 --- a/src/chrome-launcher.ts +++ b/src/chrome-launcher.ts @@ -230,7 +230,12 @@ class Launcher { return; } - const preferenceFile = `${this.userDataDir}/Preferences`; + const profileDir = `${this.userDataDir}/Default`; + if (!this.fs.existsSync(profileDir)) { + this.fs.mkdirSync(profileDir, {recursive: true}); + } + + const preferenceFile = `${profileDir}/Preferences`; try { if (this.fs.existsSync(preferenceFile)) { // overwrite existing file diff --git a/test/chrome-launcher-test.ts b/test/chrome-launcher-test.ts index 44b2b49d9..c343f502f 100644 --- a/test/chrome-launcher-test.ts +++ b/test/chrome-launcher-test.ts @@ -74,7 +74,8 @@ describe('Launcher', () => { const existStub = stub().returns(true) const readFileStub = stub().returns(JSON.stringify({ some: 'prefs' })) const writeFileStub = stub() - const fs = {...fsMock, rmdirSync: spy(), readFileSync: readFileStub, writeFileSync: writeFileStub, existsSync: existStub }; + const mkdirStub = stub() + const fs = {...fsMock, rmdir: spy(), readFileSync: readFileStub, writeFileSync: writeFileStub, existsSync: existStub, mkdirSync: mkdirStub }; const chromeInstance = new Launcher({prefs: {'download.default_directory': '/some/dir'}}, {fs: fs as any}); @@ -89,7 +90,8 @@ describe('Launcher', () => { const existStub = stub().returns(false) const readFileStub = stub().returns(Buffer.from(JSON.stringify({ some: 'prefs' }))) const writeFileStub = stub() - const fs = {...fsMock, rmdirSync: spy(), readFileSync: readFileStub, writeFileSync: writeFileStub, existsSync: existStub }; + const mkdirStub = stub() + const fs = {...fsMock, rmdir: spy(), readFileSync: readFileStub, writeFileSync: writeFileStub, existsSync: existStub, mkdirSync: mkdirStub }; const chromeInstance = new Launcher({prefs: {'download.default_directory': '/some/dir'}}, {fs: fs as any});