Skip to content

Commit

Permalink
Added tests for defaultCreateProfileFinder()
Browse files Browse the repository at this point in the history
  • Loading branch information
harikishen committed Jun 22, 2017
1 parent fdff679 commit bfb1703
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,18 @@ export type UseProfileParams = {
createProfileFinder?: typeof defaultCreateProfileFinder,
};

export function defaultCreateProfileFinder(userDirectoryPath: string = '') {
export function defaultCreateProfileFinder(userDirectoryPath?: string) {
const finder = new FirefoxProfile.Finder(userDirectoryPath);
const readProfiles = promisify(finder.readProfiles, finder);
return {
getPath: promisify(finder.getPath, finder),
hasProfileName: async (profileName: string) => {
try {
await fs.stat(path.join(FirefoxProfile.Finder.locateUserDirectory(),
'profiles.ini'));
const profilesIniPath = path.join(
userDirectoryPath || FirefoxProfile.Finder.locateUserDirectory(),
'profiles.ini');

await fs.stat(profilesIniPath);
await readProfiles();
return finder.profiles.filter(
(profileDef) => profileDef.Name === profileName).length !== 0;
Expand Down
21 changes: 19 additions & 2 deletions tests/unit/test-firefox/test.firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ describe('firefox', () => {
});

describe('defaultCreateProfileFinder', () => {

it('gives a warning if no firefox profiles exist', () => withTempDir(
async (tmpDir) => {
try {
Expand All @@ -797,6 +796,24 @@ describe('firefox', () => {
}
}
));

it('gives a warning if no firefox profiles exist', () => withTempDir(
async (tmpDir) => {
try {
const profilesPath = tmpDir.path();
const profileFinder = firefox.defaultCreateProfileFinder(
profilesPath);
const profilesIniPath = path.join(profilesPath, 'profiles.ini');
const profileContents = `[Profile0]
Name=test
IsRelative=1
Path=fake-profile.test`;
await fs.writeFile(profilesIniPath, profileContents);
const profileExists = await profileFinder.hasProfileName('test');
assert.equal(profileExists, true);
} catch (e) {
throw e;
}
}
));
});
});

0 comments on commit bfb1703

Please sign in to comment.