Skip to content

Commit

Permalink
Merge branch 'copy-connect-option' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
philnash committed Mar 5, 2022
2 parents 0979e0d + 349b346 commit 82f2c05
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@types/node": "^8.10.50",
"extract-zip": "^2.0.1",
"got": "^11.5.1",
"lodash.clonedeep": "^4.5.0",
"uuid": "^7.0.0 || ^8.0.0",
"yaml": "^1.10.0"
},
Expand Down
3 changes: 2 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const { homedir } = require("os");
const { join } = require("path");
const { parse } = require("yaml");
const { readFileSync } = require("fs");
const cloneDeep = require("lodash.clonedeep");

function defaultConfigPath() {
return join(homedir(), ".ngrok2", "ngrok.yml");
}

function defaults(opts) {
opts = opts || { proto: "http", addr: 80 };
opts = cloneDeep(opts) || { proto: "http", addr: 80 };
if (opts.name) {
const configPath = opts.configPath || defaultConfigPath();
const config = parse(readFileSync(configPath, "utf8"));
Expand Down
16 changes: 12 additions & 4 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ describe("utils", () => {
});
});

it("returns a copy of the argument", () => {
const opts = { addr: 8080, proto: "http" };
const result = defaults(opts);
// Expects that the contents of the result are the same as the original
// object
expect(result).to.eql(opts);
// Expects that the two objects are different, because result is a copy
expect(result).not.to.equal(opts);
});

it("loads the config from the config file if a name is passed", () => {
expect(
defaults({
Expand Down Expand Up @@ -140,8 +150,7 @@ describe("utils", () => {
},
body: {
details: {
err:
"a successful ngrok tunnel session has not yet been established",
err: "a successful ngrok tunnel session has not yet been established",
},
},
};
Expand All @@ -160,8 +169,7 @@ describe("utils", () => {
},
body: {
details: {
err:
"a successful ngrok tunnel session has not yet been established",
err: "a successful ngrok tunnel session has not yet been established",
},
},
};
Expand Down

0 comments on commit 82f2c05

Please sign in to comment.