Skip to content

Commit bd35f64

Browse files
authored
Merge pull request #87 from browserstack/CYP_530_path_resolve
Update logic for isCypressProjDirValid to handle windows path
2 parents 25526df + 2bf8342 commit bd35f64

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

bin/helpers/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ exports.isCypressProjDirValid = (cypressProjDir, integrationFoldDir) => {
280280
integrationFolderDir = path.resolve(path.join(cypressProjDir, integrationFoldDir));
281281
}
282282
if (integrationFolderDir === cypressDir) return true;
283-
let parentTokens = cypressDir.split("/").filter((i) => i.length);
284-
let childTokens = integrationFolderDir.split("/").filter((i) => i.length);
283+
let parentTokens = cypressDir.split(path.sep).filter((i) => i.length);
284+
let childTokens = integrationFolderDir.split(path.sep).filter((i) => i.length);
285285
return parentTokens.every((t, i) => childTokens[i] === t);
286286
};
287287

test/unit/bin/helpers/utils.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -541,23 +541,28 @@ describe('utils', () => {
541541
});
542542

543543
describe('isCypressProjDirValid', () => {
544-
it('should return true when cypressDir and cypressProjDir is same', () => {
545-
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute/path')).to
546-
.be.true;
544+
it('should return true when cypressProjDir and integrationFoldDir is same', () => {
545+
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute/path')).to.be.true;
546+
547+
// should be as below for windows but path.resolve thinks windows path as a filename when run on linux/mac
548+
// expect(utils.isCypressProjDirValid('C:\\absolute\\path', 'C:\\absolute\\path')).to.be.true;
549+
expect(utils.isCypressProjDirValid('/C/absolute/path', '/C/absolute/path')).to.be.true;
547550
});
548551

549-
it('should return true when cypressProjDir is child directory of cypressDir', () => {
550-
expect(
551-
utils.isCypressProjDirValid(
552-
'/absolute/path',
553-
'/absolute/path/childpath'
554-
)
555-
).to.be.true;
552+
it('should return true when integrationFoldDir is child directory of cypressProjDir', () => {
553+
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute/path/childpath')).to.be.true;
554+
555+
// should be as below for windows but path.resolve thinks windows path as a filename when run on linux/mac
556+
// expect(utils.isCypressProjDirValid('C:\\absolute\\path', 'C:\\absolute\\path\\childpath')).to.be.true;
557+
expect(utils.isCypressProjDirValid('/C/absolute/path', '/C/absolute/path/childpath')).to.be.true;
556558
});
557559

558-
it('should return false when cypressProjDir is not child directory of cypressDir', () => {
559-
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute')).to.be
560-
.false;
560+
it('should return false when integrationFoldDir is not child directory of cypressProjDir', () => {
561+
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute')).to.be.false;
562+
563+
// should be as below for windows but path.resolve thinks windows path as a filename when run on linux/mac
564+
// expect(utils.isCypressProjDirValid('C:\\absolute\\path', 'C:\\absolute')).to.be.false;
565+
expect(utils.isCypressProjDirValid('/C/absolute/path', '/C/absolute')).to.be.false;
561566
});
562567
});
563568

0 commit comments

Comments
 (0)