Skip to content

Commit ed24db5

Browse files
Adding unit test cases for isCypressProjDirValid
1 parent 73b2809 commit ed24db5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

bin/helpers/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ exports.isCypressProjDirValid = (cypressDir, cypressProjDir) => {
140140
// Getting absolute path
141141
cypressDir = path.resolve(cypressDir);
142142
cypressProjDir = path.resolve(cypressProjDir);
143-
144143
if(cypressProjDir === cypressDir) return true;
145-
let parentTokens = cypressDir.split('/').filter(i => i.length)
146-
return parentTokens.every((t, i) => cypressProjDir.split('/')[i] === t)
144+
let parentTokens = cypressDir.split('/').filter(i => i.length);
145+
let childTokens = cypressProjDir.split('/').filter(i => i.length);
146+
return parentTokens.every((t, i) => childTokens[i] === t);
147147
}

test/unit/bin/helpers/utils.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,18 @@ describe("utils", () => {
236236
sinon.assert.calledOnce(sendUsageReportStub);
237237
});
238238
});
239+
240+
describe("isCypressProjDirValid", () => {
241+
it("should return true when cypressDir and cypressProjDir is same", () =>{
242+
expect(utils.isCypressProjDirValid("/absolute/path","/absolute/path")).to.be.true;
243+
});
244+
245+
it("should return true when cypressProjDir is child directory of cypressDir", () =>{
246+
expect(utils.isCypressProjDirValid("/absolute/path","/absolute/path/childpath")).to.be.true;
247+
});
248+
249+
it("should return false when cypressProjDir is not child directory of cypressDir", () =>{
250+
expect(utils.isCypressProjDirValid("/absolute/path","/absolute")).to.be.false;
251+
});
252+
});
239253
});

0 commit comments

Comments
 (0)