From 94989fafc33e6d39a90418c2f55415ae88fc9c00 Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Fri, 26 Aug 2022 01:47:19 -0700 Subject: [PATCH] feat: Introduce webext run --devtools to open DevTools for the installed add-on right away. This depends on bug 1787409. --- src/cmd/run.js | 3 +++ src/extension-runners/firefox-desktop.js | 4 +++- src/firefox/remote.js | 4 +++- src/program.js | 6 ++++++ tests/unit/test-firefox/test.remote.js | 4 ++-- tests/unit/test.program.js | 15 +++++++++++++++ 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/cmd/run.js b/src/cmd/run.js index 47392ba7fb..7bab03927b 100644 --- a/src/cmd/run.js +++ b/src/cmd/run.js @@ -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, @@ -75,6 +76,7 @@ export default async function run( { artifactsDir, browserConsole = false, + devtools = false, pref, firefox, firefoxProfile, @@ -174,6 +176,7 @@ export default async function run( profilePath: firefoxProfile, customPrefs, browserConsole, + devtools, preInstall, // Firefox runner injected dependencies. diff --git a/src/extension-runners/firefox-desktop.js b/src/extension-runners/firefox-desktop.js index e9f67a36cf..e722999fb6 100644 --- a/src/extension-runners/firefox-desktop.js +++ b/src/extension-runners/firefox-desktop.js @@ -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, @@ -212,6 +213,7 @@ export class FirefoxDesktopExtensionRunner { async startFirefoxInstance() { const { browserConsole, + devtools, extensions, firefoxBinary, preInstall, @@ -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; }) diff --git a/src/firefox/remote.js b/src/firefox/remote.js index d5bcd03aac..6fe03858a6 100644 --- a/src/firefox/remote.js +++ b/src/firefox/remote.js @@ -131,7 +131,8 @@ export class RemoteFirefox { } async installTemporaryAddon( - addonPath: string + addonPath: string, + openDevTools?: boolean ): Promise { const addonsActor = await this.getAddonsActor(); @@ -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`); diff --git a/src/program.js b/src/program.js index 7ccb6367b8..67fd04c78a 100644 --- a/src/program.js +++ b/src/program.js @@ -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.', diff --git a/tests/unit/test-firefox/test.remote.js b/tests/unit/test-firefox/test.remote.js index 6213fba295..f607f18288 100644 --- a/tests/unit/test-firefox/test.remote.js +++ b/tests/unit/test-firefox/test.remote.js @@ -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'}, }); diff --git a/tests/unit/test.program.js b/tests/unit/test.program.js index 80e214c849..9376f080fb 100644 --- a/tests/unit/test.program.js +++ b/tests/unit/test.program.js @@ -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(),