-
-
Notifications
You must be signed in to change notification settings - Fork 25
[Fix] Infinite while loop when called on root folder, add tests #29
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
Open
BrettCleary
wants to merge
13
commits into
Alex-D:main
Choose a base branch
from
HyperPlay-Gaming:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8be40d3
fix getFirstExistingParentPath when called with root folder
BrettCleary 60f46da
fix tests on windows
BrettCleary 48b36a4
rm console log
BrettCleary 4ec9f3a
add variable for failed to get parent dir, add max number of folders …
BrettCleary 2716fd7
Merge pull request #1 from HyperPlay-Gaming/fix/root_check
BrettCleary 600295e
Update test/functions/getFirstExistingParentPath.spec.ts
BrettCleary 43f5a0f
rm hyperplay, add platform check for tests, rm normalize
BrettCleary c85da1e
revert path sep
BrettCleary 98775ff
add '.' check to early return
BrettCleary c69f184
update tests to use '/'
BrettCleary 72c3f71
revert mistaken sep removal
BrettCleary 4cc36da
revert sep in mock deps
BrettCleary 1ae83c1
rm cross-env
BrettCleary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,47 @@ import { PathLike } from 'fs' | |
import getFirstExistingParentPath from '@/src/functions/getFirstExistingParentPath' | ||
import mockDependencies from '@/test/__helpers__/mockDependencies' | ||
|
||
const getDependencies = (parentPath: string) => mockDependencies({ | ||
BrettCleary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fsAccess: async (directoryPath: PathLike) => directoryPath === parentPath ? Promise.resolve() : Promise.reject(new Error('File does not exists')), | ||
}) | ||
BrettCleary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
test('unix: get first existing parent path', async t => { | ||
const parentPath = '/home/Alex' | ||
const dependencies = mockDependencies({ | ||
fsAccess: async (directoryPath: PathLike) => directoryPath === parentPath ? Promise.resolve() : Promise.reject(new Error('File does not exists')), | ||
}) | ||
const dependencies = getDependencies(parentPath) | ||
|
||
t.is(await getFirstExistingParentPath('/home/Alex/games/Some/Game', dependencies), parentPath) | ||
}) | ||
|
||
test('unix: get first parent can be the path itself', async t => { | ||
const parentPath = '/home/Alex' | ||
const dependencies = mockDependencies({ | ||
fsAccess: async (directoryPath: PathLike) => directoryPath === parentPath ? Promise.resolve() : Promise.reject(new Error('File does not exists')), | ||
}) | ||
const dependencies = getDependencies(parentPath) | ||
|
||
t.is(await getFirstExistingParentPath(parentPath, dependencies), parentPath) | ||
}) | ||
|
||
test('unix: get first parent of root is root', async t => { | ||
const parentPath = '/' | ||
const dependencies = getDependencies(parentPath) | ||
|
||
t.is(await getFirstExistingParentPath(parentPath, dependencies), parentPath) | ||
}) | ||
|
||
test('win32: Gets parent to C:\\Alex', async t => { | ||
// note that 'C:/' will fail on UNIX os's as normalize(C:/Alex/..) = C: not C:/ | ||
const parentPath = 'C:' | ||
const dependencies = getDependencies(parentPath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to define the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not following. Is this still relevant after the changes I committed? |
||
t.is(await getFirstExistingParentPath('C:/Alex', dependencies), parentPath) | ||
}) | ||
|
||
test('win32: Returns root folder when called on root folder', async t => { | ||
const parentPath = 'C:/' | ||
const dependencies = getDependencies(parentPath) | ||
t.is(await getFirstExistingParentPath(parentPath, dependencies), parentPath) | ||
}) | ||
|
||
test('win32: returns empty string when drive does not exist', async t => { | ||
const drivePathThatExists = 'C:/' | ||
const dependencies = getDependencies(drivePathThatExists) | ||
const drivePathThatDoesNotExist = 'Z:/' | ||
t.is(await getFirstExistingParentPath(drivePathThatDoesNotExist, dependencies), '') | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This limit is not valid on every file system
https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
So... I do not know if I want to add that to this loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a number we can change it to that would accomplish this goal? Or another way to avoid a while loop/provide a failsafe if we miss another edge case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately this is of course your call and I'm happy to revert to the while loop if you would like