Skip to content

Commit

Permalink
feat: introduce a --firefox-preview flag for 'web-ext run'
Browse files Browse the repository at this point in the history
This flag allows to enable the [Firefox Dev Preview for Manifest V3][get-involved]

[get-involved]: https://blog.mozilla.org/addons/2022/06/08/manifest-v3-firefox-developer-preview-how-to-get-involved/
  • Loading branch information
willdurand committed Jun 13, 2022
1 parent 8e91380 commit b6db36a
Show file tree
Hide file tree
Showing 4 changed files with 42 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 @@ -43,6 +43,7 @@ export type CmdRunParams = {|
startUrl?: Array<string>,
target?: Array<string>,
args?: Array<string>,
firefoxPreview: Array<string>,

// Android CLI options.
adbBin?: string,
Expand Down Expand Up @@ -89,6 +90,7 @@ export default async function run(
startUrl,
target,
args,
firefoxPreview = [],
// Android CLI options.
adbBin,
adbHost,
Expand Down Expand Up @@ -126,7 +128,12 @@ export default async function run(

// Create an alias for --pref since it has been transformed into an
// object containing one or more preferences.
const customPrefs = pref;
const customPrefs: FirefoxPreferences = {...pref};
if (firefoxPreview.includes('mv3')) {
log.info('Configuring Firefox preferences for Manifest V3');
customPrefs['extensions.manifestV3.enabled'] = true;
}

const manifestData = await getValidatedManifest(sourceDir);

const profileDir = firefoxProfile || chromiumProfile;
Expand Down
6 changes: 6 additions & 0 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,12 @@ Example: $0 --help run.
demandOption: false,
type: 'array',
},
'firefox-preview': {
describe: 'Turn on developer preview features in Firefox',
demandOption: false,
default: ['mv3'],
type: 'array',
},
// Firefox for Android CLI options.
'adb-bin': {
describe: 'Specify a custom path to the adb binary',
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test-cmd/test.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,22 @@ describe('run', () => {
);
});
});

describe('firefox-preview', () => {
it('supports the MV3 preview', async () => {
const cmd = await prepareRun();
const runOptions = {
firefoxPreview: ['mv3'],
};

await cmd.run(runOptions);

sinon.assert.calledOnce(desktopRunnerStub);
const runnerParams = desktopRunnerStub.firstCall.args[0];

assert.deepEqual(runnerParams.customPrefs, {
'extensions.manifestV3.enabled': true,
});
});
});
});
10 changes: 10 additions & 0 deletions tests/unit/test.program.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,16 @@ describe('program.main', () => {
}
});

it('sets the default firefox preview to "mv3"', async () => {
const fakeCommands = fake(commands, {
run: () => Promise.resolve(),
});

await execProgram(['run', '--firefox-preview'], {commands: fakeCommands});

const {firefoxPreview} = fakeCommands.run.firstCall.args[0];
assert.deepEqual(firefoxPreview, ['mv3']);
});
});

describe('program.defaultVersionGetter', () => {
Expand Down

0 comments on commit b6db36a

Please sign in to comment.