From 6f5805327f3ef6ee38b72686c14591b6b64ec8ec Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Thu, 1 Sep 2022 08:42:27 -0700 Subject: [PATCH] Promote the new --devtools command line argument and link to debugging online documentation --- src/extension-runners/firefox-desktop.js | 1 + src/firefox/index.js | 12 ++++++-- tests/functional/fake-firefox-binary.js | 1 + tests/unit/test-firefox/test.firefox.js | 39 +++++++++++++++++++++++- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/extension-runners/firefox-desktop.js b/src/extension-runners/firefox-desktop.js index e722999fb6..eab86d0419 100644 --- a/src/extension-runners/firefox-desktop.js +++ b/src/extension-runners/firefox-desktop.js @@ -243,6 +243,7 @@ export class FirefoxDesktopExtensionRunner { firefoxBinary, binaryArgs, extensions, + devtools, }); this.runningInfo.firefox.on('close', () => { diff --git a/src/firefox/index.js b/src/firefox/index.js index 8a4e35aa66..d3079da8f0 100644 --- a/src/firefox/index.js +++ b/src/firefox/index.js @@ -90,6 +90,7 @@ export type FirefoxRunOptions = { binaryArgs?: Array, args?: Array, extensions: Array, + devtools: boolean, }; /* @@ -103,6 +104,7 @@ export async function run( firefoxBinary, binaryArgs, extensions, + devtools, }: FirefoxRunOptions = {} ): Promise { @@ -164,9 +166,13 @@ export async function run( throw error; }); - log.info( - 'Use --verbose or open Tools > Web Developer > Browser Console ' + - 'to see logging'); + if (!devtools) { + log.info('Use --verbose or --devtools to see logging'); + } + if (devtools) { + log.info('More info about WebExtensions debugging:'); + log.info('https://extensionworkshop.com/documentation/develop/debugging/'); + } firefox.stderr.on('data', (data) => { log.debug(`Firefox stderr: ${data.toString().trim()}`); diff --git a/tests/functional/fake-firefox-binary.js b/tests/functional/fake-firefox-binary.js index 2f8690258d..00ffb3fe2e 100755 --- a/tests/functional/fake-firefox-binary.js +++ b/tests/functional/fake-firefox-binary.js @@ -9,6 +9,7 @@ const REQUEST_INSTALL_ADDON = { to: 'fakeAddonsActor', type: 'installTemporaryAddon', addonPath: process.env.addonPath, + openDevTools: false, // Introduced in Firefox 106 (Bug 1787409 / Bug 1789245) }; const REPLY_INSTALL_ADDON = { from: 'fakeAddonsActor', diff --git a/tests/unit/test-firefox/test.firefox.js b/tests/unit/test-firefox/test.firefox.js index c518df91cf..db70520a37 100644 --- a/tests/unit/test-firefox/test.firefox.js +++ b/tests/unit/test-firefox/test.firefox.js @@ -11,6 +11,9 @@ import {fs} from 'mz'; import * as firefox from '../../../src/firefox/index.js'; import {onlyInstancesOf, UsageError, WebExtError} from '../../../src/errors.js'; import {withTempDir} from '../../../src/util/temp-dir.js'; +import { + consoleStream, // instance is imported to inspect logged messages +} from '../../../src/util/logger.js'; import { basicManifest, fixturePath, @@ -240,6 +243,41 @@ describe('firefox', () => { }); }); + it('logs link to debugging docs', async () => { + const runner = createFakeFxRunner(); + consoleStream.flushCapturedLogs(); + consoleStream.startCapturing(); + + const expectedMessage = 'More info about WebExtensions debugging:'; + const expectedURLToDocs = + 'https://extensionworkshop.com/documentation/develop/debugging/'; + await runFirefox({fxRunner: runner, devtools: false}); + assert.notOk(consoleStream.capturedMessages.find( + (msg) => msg.includes(expectedMessage) + )); + assert.notOk(consoleStream.capturedMessages.find( + (msg) => msg.includes(expectedURLToDocs) + )); + + consoleStream.flushCapturedLogs(); + + await runFirefox({fxRunner: runner, devtools: true}); + const foundMessage = consoleStream.capturedMessages.find( + (msg) => msg.includes(expectedMessage) + ); + const foundDocURL = consoleStream.capturedMessages.find( + (msg) => msg.includes(expectedURLToDocs) + ); + + // Expect the logs to be found. + assert.ok(foundMessage); + assert.ok(foundDocURL); + + // Expected to be emitted as info level logs. + assert.ok(foundMessage?.includes('[info]')); + assert.ok(foundDocURL?.includes('[info]')); + }); + }); describe('copyProfile', () => { @@ -1003,7 +1041,6 @@ describe('firefox', () => { sinon.assert.calledOnce(fakeAsyncFsStat); } )); - }); });