Skip to content

Commit

Permalink
feat: threw error if profile-create-new-if-missing used without profi…
Browse files Browse the repository at this point in the history
…le (#2073)
  • Loading branch information
akhilpanchal authored Nov 19, 2020
1 parent 4688bb7 commit 7e5ffcb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cmd/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../firefox/remote';
import {createLogger} from '../util/logger';
import defaultGetValidatedManifest from '../util/manifest';
import {UsageError} from '../../src/errors';
import {
createExtensionRunner,
defaultReloadStrategy,
Expand Down Expand Up @@ -123,7 +124,13 @@ export default async function run(

const profileDir = firefoxProfile || chromiumProfile;

if (profileCreateIfMissing && profileDir) {
if (profileCreateIfMissing) {
if (!profileDir) {
throw new UsageError(
'--profile-create-if-missing requires ' +
'--firefox-profile or --chromium-profile'
);
}
const isDir = fs.existsSync(profileDir);
if (isDir) {
log.info(`Profile directory ${profileDir} already exists`);
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test-cmd/test.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {assert} from 'chai';
import sinon from 'sinon';

import run from '../../../src/cmd/run';
import {UsageError} from '../../../src/errors';
import {
fixturePath,
FakeExtensionRunner,
Expand Down Expand Up @@ -406,5 +407,17 @@ describe('run', () => {
profileCreateIfMissing: true,
})
);

it('throws error when used without firefox-profile or chromium-profile',
async () => {
const cmd = prepareRun();
const promise = cmd.run({ profileCreateIfMissing: true });

await assert.isRejected(promise, UsageError);
await assert.isRejected(
promise,
/requires --firefox-profile or --chromium-profile/
);
});
});
});

0 comments on commit 7e5ffcb

Please sign in to comment.