From 80201b97587f81c27b477f3aa5c163456fe52b18 Mon Sep 17 00:00:00 2001 From: Federico Date: Mon, 5 Aug 2024 00:14:47 +0700 Subject: [PATCH 1/3] Bump commander from v2 to v12 --- bin/fx-runner | 4 ++-- package-lock.json | 14 +++----------- package.json | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/bin/fx-runner b/bin/fx-runner index a2340dc..0e8c3b5 100755 --- a/bin/fx-runner +++ b/bin/fx-runner @@ -1,7 +1,7 @@ #!/usr/bin/env node var VERSION = require("../package.json").version; -var program = require("commander"); +var { program } = require('commander'); var run = require("../lib/run"); program @@ -37,4 +37,4 @@ program }, console.exception); }); -program.parse(process.argv); +program.parse(); diff --git a/package-lock.json b/package-lock.json index 42871c2..1499e99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -189,12 +189,9 @@ "dev": true }, "commander": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", - "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=", - "requires": { - "graceful-readlink": ">= 1.0.0" - } + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", + "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==" }, "concat-map": { "version": "0.0.1", @@ -364,11 +361,6 @@ "is-glob": "^4.0.1" } }, - "graceful-readlink": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", - "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=" - }, "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", diff --git a/package.json b/package.json index a01cd3e..f292ac8 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "author": "Mozilla Add-ons Team", "license": "MPL-2.0", "dependencies": { - "commander": "2.9.0", + "commander": "^12.1.0", "shell-quote": "1.8.1", "spawn-sync": "1.0.15", "when": "3.7.8", From a565abf0c0d509bba7f0e2c472e0564808bbb67a Mon Sep 17 00:00:00 2001 From: Federico Date: Mon, 5 Aug 2024 00:29:12 +0700 Subject: [PATCH 2/3] Skip outdated tests --- bin/fx-runner | 27 +++++++++++++-------------- test/run/test.run.js | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/bin/fx-runner b/bin/fx-runner index 0e8c3b5..7799e68 100755 --- a/bin/fx-runner +++ b/bin/fx-runner @@ -1,11 +1,15 @@ #!/usr/bin/env node var VERSION = require("../package.json").version; -var { program } = require('commander'); +var { program } = require("commander"); var run = require("../lib/run"); program .version(VERSION) + +program + .command("start") + .description("Start Firefox") .option("-b, --binary ", "Path of Firefox binary to use.") .option("--binary-args ", "Pass additional arguments into Firefox.") .option("-p, --profile ", "Path or name of Firefox profile to use.") @@ -14,20 +18,15 @@ program .option("--no-remote", "Do not allow remote calls") .option("--foreground", "Bring Firefox to the foreground") .option("-l, --listen ", "Start the debugger server on a specific port.") - -program - .command("start") - .description("Start Firefox") - .action(function() { - console.log(Object.keys(program)) + .action(function(options) { run({ - binary: program.binary || process.env.JPM_FIREFOX_BINARY || "firefox", - profile: program.profile, - "new-instance": !!program.newInstance ? true : false, - "foreground": !!program.foreground ? true : false, - "no-remote": !program.remote ? true : false, - "binary-args": program.binaryArgs || "", - "listen": program.listen || 6000 + binary: options.binary || process.env.JPM_FIREFOX_BINARY || "firefox", + profile: options.profile, + "new-instance": !!options.newInstance ? true : false, + "foreground": !!options.foreground ? true : false, + "no-remote": !options.remote ? true : false, + "binary-args": options.binaryArgs || "", + "listen": options.listen || 6000 }) .then(function(results) { var firefox = results.process; diff --git a/test/run/test.run.js b/test/run/test.run.js index 4e4e6ec..156487f 100644 --- a/test/run/test.run.js +++ b/test/run/test.run.js @@ -18,7 +18,7 @@ var parse = require("shell-quote").parse; var fakeBinary = path.join(__dirname, "..", "utils", "dummybinary" + (isWindows ? ".bat" : ".sh")); -describe("fx-runner start", function () { +describe.skip("fx-runner start", function () { describe("-b/--binary ", function () { it("-p ", function (done) { var proc = exec("start -v -b " + fakeBinary + " -p foo", {}, function (err, stdout, stderr) { From 4ce588e2a7716605ccd4267bd387ae865f24cde3 Mon Sep 17 00:00:00 2001 From: Federico Date: Mon, 5 Aug 2024 00:43:08 +0700 Subject: [PATCH 3/3] Test CLI parsing without user noise --- bin/fx-runner | 12 +++-- test/run/test.run.js | 122 ++++++++++++++++++++++++++----------------- 2 files changed, 84 insertions(+), 50 deletions(-) diff --git a/bin/fx-runner b/bin/fx-runner index 7799e68..5c62928 100755 --- a/bin/fx-runner +++ b/bin/fx-runner @@ -17,9 +17,9 @@ program .option("--new-instance", "Use a new instance") .option("--no-remote", "Do not allow remote calls") .option("--foreground", "Bring Firefox to the foreground") - .option("-l, --listen ", "Start the debugger server on a specific port.") + .option("-l, --listen ", "Start the debugger server on a specific port.", parseInt) .action(function(options) { - run({ + const parsedOptions = { binary: options.binary || process.env.JPM_FIREFOX_BINARY || "firefox", profile: options.profile, "new-instance": !!options.newInstance ? true : false, @@ -27,7 +27,13 @@ program "no-remote": !options.remote ? true : false, "binary-args": options.binaryArgs || "", "listen": options.listen || 6000 - }) + }; + + if (process.env.TESTING_FX_RUNNER) { + console.log(JSON.stringify(parsedOptions)); + } + + run(parsedOptions) .then(function(results) { var firefox = results.process; if (program.verbose) { diff --git a/test/run/test.run.js b/test/run/test.run.js index 156487f..7227622 100644 --- a/test/run/test.run.js +++ b/test/run/test.run.js @@ -18,99 +18,127 @@ var parse = require("shell-quote").parse; var fakeBinary = path.join(__dirname, "..", "utils", "dummybinary" + (isWindows ? ".bat" : ".sh")); -describe.skip("fx-runner start", function () { +const ENV = { + env: { + TESTING_FX_RUNNER: true + } +}; + +describe("fx-runner start", function () { describe("-b/--binary ", function () { it("-p ", function (done) { - var proc = exec("start -v -b " + fakeBinary + " -p foo", {}, function (err, stdout, stderr) { + var proc = exec("start -v -b " + fakeBinary + " -p foo", ENV, function (err, stdout, stderr) { expect(err).to.not.be.ok; expect(stderr).to.not.be.ok; - expect(stdout).to.contain("-P foo"); - expect(stdout).to.not.contain("--P"); - expect(stdout).to.not.contain("-foreground"); - expect(stdout).to.not.contain("-no-remote"); - expect(stdout).to.not.contain("-new-instance"); + expect(JSON.parse(stdout)).to.contain({ + binary: fakeBinary, + profile: "foo", + "new-instance": false, + "foreground": false, + "no-remote": false, + "binary-args": "", + "listen": 6000 + }); done(); }); }); it("-p ", function (done) { - var proc = exec("start -v -b " + fakeBinary + " -p ./", {}, function (err, stdout, stderr) { + var proc = exec("start -v -b " + fakeBinary + " -p ./", ENV, function (err, stdout, stderr) { expect(err).to.not.be.ok; expect(stderr).to.not.be.ok; - expect(stdout).to.contain("-profile ./"); - expect(stdout).to.not.contain("--profile"); - expect(stdout).to.not.contain("--P"); - expect(stdout).to.not.contain("-foreground"); - expect(stdout).to.not.contain("-no-remote"); - expect(stdout).to.not.contain("-new-instance"); + + expect(JSON.parse(stdout)).to.contain({ + binary: fakeBinary, + profile: "./", + "new-instance": false, + "foreground": false, + "no-remote": false, + "binary-args": "", + "listen": 6000 + }); + done(); }); }); it("--binary-args ", function (done) { - var proc = exec("start -v -b " + fakeBinary + " --binary-args \"-test\" ./", {}, function (err, stdout, stderr) { + var proc = exec("start -v -b " + fakeBinary + " --binary-args \"-test\" ./", ENV, function (err, stdout, stderr) { expect(err).to.not.be.ok; expect(stderr).to.not.be.ok; - expect(stdout).to.contain("-test"); - expect(stdout).to.not.contain("--binary-args"); - expect(stdout).to.not.contain("--profile"); - expect(stdout).to.not.contain("--P"); - expect(stdout).to.not.contain("-foreground"); - expect(stdout).to.not.contain("-no-remote"); - expect(stdout).to.not.contain("-new-instance"); + + expect(JSON.parse(stdout)).to.contain({ + binary: fakeBinary, + "new-instance": false, + "foreground": false, + "no-remote": false, + "binary-args": "-test", + "listen": 6000 + }); done(); }); }); it("--foreground", function (done) { - var proc = exec("start -v -b " + fakeBinary + " --foreground", {}, function (err, stdout, stderr) { + var proc = exec("start -v -b " + fakeBinary + " --foreground", ENV, function (err, stdout, stderr) { expect(err).to.not.be.ok; expect(stderr).to.not.be.ok; - expect(stdout).to.contain("-foreground"); - expect(stdout).to.not.contain("--foreground"); - expect(stdout).to.not.contain("-P"); - expect(stdout).to.not.contain("-no-remote"); - expect(stdout).to.not.contain("-new-instance"); + expect(JSON.parse(stdout)).to.contain({ + binary: fakeBinary, + "new-instance": false, + "foreground": true, + "no-remote": false, + "binary-args": "", + "listen": 6000 + }); done(); }); }); it("--no-remote", function (done) { - var proc = exec("start -v -b " + fakeBinary + " --no-remote", {}, function (err, stdout, stderr) { + var proc = exec("start -v -b " + fakeBinary + " --no-remote", ENV, function (err, stdout, stderr) { expect(err).to.not.be.ok; expect(stderr).to.not.be.ok; - expect(stdout).to.contain("-no-remote"); - expect(stdout).to.not.contain("--no-remote"); - expect(stdout).to.not.contain("-P"); - expect(stdout).to.not.contain("-foreground"); - expect(stdout).to.not.contain("-new-instance"); + expect(JSON.parse(stdout)).to.contain({ + binary: fakeBinary, + "new-instance": false, + "foreground": false, + "no-remote": true, + "binary-args": "", + "listen": 6000 + }); done(); }); }); it("--new-instance", function (done) { - var proc = exec("start -v -b " + fakeBinary + " --new-instance", {}, function (err, stdout, stderr) { + var proc = exec("start -v -b " + fakeBinary + " --new-instance", ENV, function (err, stdout, stderr) { expect(err).to.not.be.ok; expect(stderr).to.not.be.ok; - expect(stdout).to.contain("-new-instance"); - expect(stdout).to.not.contain("--new-instance"); - expect(stdout).to.not.contain("-P"); - expect(stdout).to.not.contain("-foreground"); - expect(stdout).to.not.contain("-no-remote"); + expect(JSON.parse(stdout)).to.contain({ + binary: fakeBinary, + "new-instance": true, + "foreground": false, + "no-remote": false, + "binary-args": "", + "listen": 6000 + }); done(); }); }); it("--listen", function (done) { - var proc = exec("start -v -b " + fakeBinary + " --listen 6666", {}, function (err, stdout, stderr) { + var proc = exec("start -v -b " + fakeBinary + " --listen 6666", ENV, function (err, stdout, stderr) { expect(err).to.not.be.ok; expect(stderr).to.not.be.ok; - expect(stdout).to.contain("-start-debugger-server"); - expect(stdout).to.contain("6666"); - expect(stdout).to.not.contain("--listen"); - expect(stdout).to.not.contain("-P"); - expect(stdout).to.not.contain("-foreground"); - expect(stdout).to.not.contain("-no-remote"); + expect(JSON.parse(stdout)).to.contain({ + binary: fakeBinary, + "new-instance": false, + "foreground": false, + "no-remote": false, + "binary-args": "", + "listen": 6666 + }); done(); }); });