Skip to content

Commit

Permalink
Add CLI flag and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Oct 15, 2023
1 parent 4dffb2d commit 9d0512a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cmd/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default async function run(
firefoxApkComponent,
// Chromium CLI options.
chromiumBinary,
chromiumPref,
chromiumProfile,
},
{
Expand Down Expand Up @@ -86,6 +87,10 @@ export default async function run(
customPrefs['extensions.manifestV3.enabled'] = true;
}

// Create an alias for --chromium-pref since it has been transformed into an
// object containing one or more preferences.
const customChromiumPrefs = { ...chromiumPref };

const manifestData = await getValidatedManifest(sourceDir);

const profileDir = firefoxProfile || chromiumProfile;
Expand Down Expand Up @@ -193,6 +198,7 @@ export default async function run(
...commonRunnerParams,
chromiumBinary,
chromiumProfile,
customChromiumPrefs,
};

const chromiumRunner = await createExtensionRunner({
Expand Down
12 changes: 12 additions & 0 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,18 @@ Example: $0 --help run.
demandOption: false,
type: 'string',
},
'chromium-pref': {
describe:
'Launch chromium with a custom preference ' +
'(example: --chromium-pref=browser.theme.follows_system_colors=false). ' +
'You can repeat this option to set more than one ' +
'preference.',
demandOption: false,
requiresArg: true,
type: 'array',
coerce: (arg) =>
arg != null ? coerceCLICustomPreference(arg) : undefined,
},
'chromium-profile': {
describe: 'Path to a custom Chromium profile',
demandOption: false,
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test.program.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,21 @@ describe('program.main', () => {
});
});

it('converts custom chromium preferences into an object', () => {
const fakeCommands = fake(commands, {
run: () => Promise.resolve(),
});
return execProgram(
['run', '--chromium-pref', 'prop=true', '--chromium-pref', 'prop2=value2'],
{ commands: fakeCommands },
).then(() => {
const { chromiumPref } = fakeCommands.run.firstCall.args[0];
assert.isObject(chromiumPref);
assert.equal(chromiumPref.prop, true);
assert.equal(chromiumPref.prop2, 'value2');
});
});

it('passes shouldExitProgram option to commands', () => {
const fakeCommands = fake(commands, {
lint: () => Promise.resolve(),
Expand Down

0 comments on commit 9d0512a

Please sign in to comment.