Skip to content

Commit acc6c06

Browse files
committed
handle absolute path in filename
1 parent 4ce46e5 commit acc6c06

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

bin/commands/init.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ function get_path(args) {
2121
} else if (args.p) {
2222
return path.join(args.p, "browserstack.json");
2323
} else if (args._.length > 1) {
24+
let filename = args._[1];
25+
if (filename !== path.basename(filename)) {
26+
// filename is an absolute path
27+
return filename;
28+
}
2429
return path.join(process.cwd(), args._[1]);
2530
}
2631

test/unit/bin/commands/init.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const chai = require("chai"),
44
sinon = require("sinon"),
55
chaiAsPromised = require("chai-as-promised"),
66
rewire = require("rewire"),
7-
util = require("util");
7+
util = require("util"),
8+
path = require('path');
89

910
const Constants = require("../../../../bin/helpers/constants"),
1011
logger = require("../../../../bin/helpers/logger").winstonLogger,
@@ -44,7 +45,7 @@ describe("init", () => {
4445
$0: "browserstack-cypress",
4546
};
4647

47-
assert(get_path(args), '/sample-path/filename.json');
48+
expect(get_path(args)).to.be.eql('/sample-path/filename.json');
4849
});
4950

5051
it("filename passed, -path not passed", () => {
@@ -55,7 +56,15 @@ describe("init", () => {
5556
$0: "browserstack-cypress",
5657
};
5758

58-
assert(get_path(args), 'filename.json');
59+
let args2 = {
60+
_: ["init", "~/filename.json"],
61+
p: false,
62+
path: false,
63+
$0: "browserstack-cypress",
64+
};
65+
66+
expect(get_path(args)).to.be.eql(path.join(process.cwd(), 'filename.json'));
67+
expect(get_path(args2)).to.be.eql('~/filename.json');
5968
});
6069

6170
it("filepath passed, -path passed", () => {
@@ -84,7 +93,7 @@ describe("init", () => {
8493
$0: "browserstack-cypress",
8594
};
8695

87-
assert(get_path(args), '/sample-path/browserstack.json');
96+
expect(get_path(args)).to.be.eql('/sample-path/browserstack.json');
8897
});
8998

9099
it("filename not passed, -path not passed", () => {
@@ -95,7 +104,7 @@ describe("init", () => {
95104
$0: "browserstack-cypress",
96105
};
97106

98-
assert(get_path(args), 'browserstack.json');
107+
expect(get_path(args)).to.be.eql(path.join(process.cwd(), 'browserstack.json'));
99108
});
100109
});
101110

0 commit comments

Comments
 (0)