Skip to content

Update logic for isCypressProjDirValid to handle windows path #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ exports.isCypressProjDirValid = (cypressProjDir, integrationFoldDir) => {
integrationFolderDir = path.resolve(path.join(cypressProjDir, integrationFoldDir));
}
if (integrationFolderDir === cypressDir) return true;
let parentTokens = cypressDir.split("/").filter((i) => i.length);
let childTokens = integrationFolderDir.split("/").filter((i) => i.length);
let parentTokens = cypressDir.split(path.sep).filter((i) => i.length);
let childTokens = integrationFolderDir.split(path.sep).filter((i) => i.length);
return parentTokens.every((t, i) => childTokens[i] === t);
};

Expand Down
31 changes: 18 additions & 13 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,23 +541,28 @@ describe('utils', () => {
});

describe('isCypressProjDirValid', () => {
it('should return true when cypressDir and cypressProjDir is same', () => {
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute/path')).to
.be.true;
it('should return true when cypressProjDir and integrationFoldDir is same', () => {
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute/path')).to.be.true;

// should be as below for windows but path.resolve thinks windows path as a filename when run on linux/mac
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case , do we need to comment this and add one more expect ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for future use if we detect the platform is win32

// expect(utils.isCypressProjDirValid('C:\\absolute\\path', 'C:\\absolute\\path')).to.be.true;
expect(utils.isCypressProjDirValid('/C/absolute/path', '/C/absolute/path')).to.be.true;
});

it('should return true when cypressProjDir is child directory of cypressDir', () => {
expect(
utils.isCypressProjDirValid(
'/absolute/path',
'/absolute/path/childpath'
)
).to.be.true;
it('should return true when integrationFoldDir is child directory of cypressProjDir', () => {
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute/path/childpath')).to.be.true;

// should be as below for windows but path.resolve thinks windows path as a filename when run on linux/mac
// expect(utils.isCypressProjDirValid('C:\\absolute\\path', 'C:\\absolute\\path\\childpath')).to.be.true;
expect(utils.isCypressProjDirValid('/C/absolute/path', '/C/absolute/path/childpath')).to.be.true;
});

it('should return false when cypressProjDir is not child directory of cypressDir', () => {
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute')).to.be
.false;
it('should return false when integrationFoldDir is not child directory of cypressProjDir', () => {
expect(utils.isCypressProjDirValid('/absolute/path', '/absolute')).to.be.false;

// should be as below for windows but path.resolve thinks windows path as a filename when run on linux/mac
// expect(utils.isCypressProjDirValid('C:\\absolute\\path', 'C:\\absolute')).to.be.false;
expect(utils.isCypressProjDirValid('/C/absolute/path', '/C/absolute')).to.be.false;
});
});

Expand Down