Skip to content

Commit

Permalink
feat: Introduce webext run --devtools to open DevTools for the instal…
Browse files Browse the repository at this point in the history
…led add-on right away.

This depends on bug 1787409.
  • Loading branch information
ochameau committed Aug 30, 2022
1 parent c932666 commit 94989fa
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/cmd/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const log = createLogger(import.meta.url);
export type CmdRunParams = {|
artifactsDir: string,
browserConsole: boolean,
devtools: boolean,
pref?: FirefoxPreferences,
firefox: string,
firefoxProfile?: string,
Expand Down Expand Up @@ -75,6 +76,7 @@ export default async function run(
{
artifactsDir,
browserConsole = false,
devtools = false,
pref,
firefox,
firefoxProfile,
Expand Down Expand Up @@ -174,6 +176,7 @@ export default async function run(
profilePath: firefoxProfile,
customPrefs,
browserConsole,
devtools,
preInstall,

// Firefox runner injected dependencies.
Expand Down
4 changes: 3 additions & 1 deletion src/extension-runners/firefox-desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {FirefoxInfo} from '../firefox/index'; // eslint-disable-line import
type FirefoxDesktopSpecificRunnerParams = {|
customPrefs?: FirefoxPreferences,
browserConsole: boolean,
devtools: boolean,
firefoxBinary: string,
preInstall: boolean,

Expand Down Expand Up @@ -212,6 +213,7 @@ export class FirefoxDesktopExtensionRunner {
async startFirefoxInstance() {
const {
browserConsole,
devtools,
extensions,
firefoxBinary,
preInstall,
Expand Down Expand Up @@ -262,7 +264,7 @@ export class FirefoxDesktopExtensionRunner {
for (const extension of extensions) {
try {
const addonId = await (
remoteFirefox.installTemporaryAddon(extension.sourceDir)
remoteFirefox.installTemporaryAddon(extension.sourceDir, devtools)
.then((installResult: FirefoxRDPResponseAddon) => {
return installResult.addon.id;
})
Expand Down
4 changes: 3 additions & 1 deletion src/firefox/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export class RemoteFirefox {
}

async installTemporaryAddon(
addonPath: string
addonPath: string,
openDevTools?: boolean
): Promise<FirefoxRDPResponseAddon> {
const addonsActor = await this.getAddonsActor();

Expand All @@ -140,6 +141,7 @@ export class RemoteFirefox {
to: addonsActor,
type: 'installTemporaryAddon',
addonPath,
openDevTools,
});
log.debug(`installTemporaryAddon: ${JSON.stringify(response)}`);
log.info(`Installed ${addonPath} as a temporary add-on`);
Expand Down
6 changes: 6 additions & 0 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,12 @@ Example: $0 --help run.
demandOption: false,
type: 'array',
},
'devtools': {
describe: 'Open the DevTools for the installed add-on ' +
'(Firefox 106 and later)',
demandOption: false,
type: 'boolean',
},
'browser-console': {
alias: ['bc'],
describe: 'Open the DevTools Browser Console.',
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test-firefox/test.remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ describe('firefox.remote', () => {
const addonsActor = 'addons1.actor.conn';
const addonPath = '/path/to/addon';

client.request.withArgs({
client.request.withArgs(sinon.match({
type: 'installTemporaryAddon',
to: addonsActor,
addonPath,
}).resolves({
})).resolves({
addon: {id: 'abc123@temporary-addon'},
});

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 @@ -552,6 +552,21 @@ describe('program.main', () => {
});
});

it('opens devtools when --devtools is specified', () => {
const fakeCommands = fake(commands, {
run: () => Promise.resolve(),
});
return execProgram(
['run', '--devtools'],
{commands: fakeCommands})
.then(() => {
sinon.assert.calledWithMatch(
fakeCommands.run,
{devtools: true}
);
});
});

async function testWatchFileOption(watchFile) {
const fakeCommands = fake(commands, {
run: () => Promise.resolve(),
Expand Down

0 comments on commit 94989fa

Please sign in to comment.