-
-
Notifications
You must be signed in to change notification settings - Fork 26
[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
base: main
Are you sure you want to change the base?
Changes from 5 commits
8be40d3
60f46da
48b36a4
4ec9f3a
2716fd7
600295e
43f5a0f
c85da1e
98775ff
c69f184
72c3f71
4cc36da
1ae83c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
import { normalize } from 'node:path' | ||
|
||
import test from 'ava' | ||
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 parentPath = normalize('/home/Alex') | ||
BrettCleary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 parentPath = normalize('/home/Alex') | ||
const dependencies = getDependencies(parentPath) | ||
|
||
t.is(await getFirstExistingParentPath(parentPath, dependencies), parentPath) | ||
}) | ||
|
||
test('win32: Gets parent to C:\\HyperPlay', async t => { | ||
BrettCleary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const parentPath = normalize('C:\\') | ||
BrettCleary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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(normalize('C:\\HyperPlay'), dependencies), parentPath) | ||
BrettCleary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
test('win32: Returns root folder when called on root folder', async t => { | ||
const parentPath = normalize('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 = normalize('C:\\') | ||
const dependencies = getDependencies(drivePathThatExists) | ||
const drivePathThatDoesNotExist = normalize('Z:\\') | ||
t.is(await getFirstExistingParentPath(drivePathThatDoesNotExist, dependencies), '') | ||
}) |
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