-
-
Notifications
You must be signed in to change notification settings - Fork 953
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
feat: add ability to define number of generated extensions in system.filePath #395
Conversation
src/system.ts
Outdated
switch (true) { | ||
case ext === 0: | ||
return path.slice(0, path.lastIndexOf('.')); | ||
|
||
case ext === 1: | ||
return path; | ||
|
||
default: { | ||
const extensions = new Array(ext - 1) | ||
.fill('') | ||
.map(() => this.fileExt()) | ||
.join('.'); | ||
|
||
return `${path}.${extensions}`; | ||
} | ||
} |
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.
Maybe move this logic into fileName()
?
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.
Good idea, let me do that...
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.
Actually, Mayne I should do that in a separate PR not to mix concerts @ST-DDT ? It would be also better to spot on the changelog?
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 PR is about changing the number of generated extensions,
I think that its acceptable to do so in two/three related methods within a single PR.
feat: add ability to define the number of generated file extensions
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.
Maybe we just need to adjust the PR title a little bit 🤷
But I also think it's okay to provide this in one PR
src/system.ts
Outdated
return this.faker.fake( | ||
'{{system.directoryPath}}/{{system.fileName}}.{{system.fileExt}}' | ||
); | ||
filePath(ext = 1): string { |
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.
Should we make it also possible to set the nested dir depth?
So we would need to forward an arg to directoryPath
So IMO we should use an option here {extCount = 1, dirCount: 1-3?}
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.
Sure, why not! :) I can do that once #300 is merged, ok?
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.
sure
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.
Sounds good, for now stick to a fixed number for each of them.
In a later feature we can introduce number | { min, max }
(that might be handy for multiple locations)
Words, Lorem, ...
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.
directoryPath
does not take any params. I would propose to extend it in a separate PR not to mix the concerns.
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.
directory path in separate PR: OK
#300 has been merged |
@pkuczynski please rebase and resolve any conflicts 🙂 |
Codecov Report
@@ Coverage Diff @@
## main #395 +/- ##
=======================================
Coverage 99.34% 99.34%
=======================================
Files 1921 1921
Lines 176656 176676 +20
Branches 905 909 +4
=======================================
+ Hits 175503 175523 +20
Misses 1097 1097
Partials 56 56
|
3651bb1
to
a0f7905
Compare
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.
Please implement the requested features above.
Yes yes, give me a moment :) |
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.
Other than these two minor changes, this LGTM!
|
||
switch (true) { | ||
case ext < 0: | ||
throw new FakerError('Options.ext shall not have negative value'); |
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.
throw new FakerError('Options.ext shall not have negative value'); | |
throw new FakerError('Options.ext should not be negative'); |
I think this phrasing would be more natural
|
||
it('should throw error ext < 0', () => { | ||
expect(() => faker.system.filePath({ ext: -1 })).toThrow( | ||
new FakerError('Options.ext shall not have negative value') |
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.
new FakerError('Options.ext shall not have negative value') | |
new FakerError('Options.ext should not be negative') |
@pkuczynski are you still working on this? Otherwise, I would continue the development process for you. |
Will be continued in #1101. |
Includes #300 which should be merged first