Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

pkuczynski
Copy link
Member

Includes #300 which should be merged first

@pkuczynski pkuczynski requested a review from a team as a code owner February 1, 2022 21:50
@pkuczynski pkuczynski added the c: feature Request for new feature label Feb 1, 2022
@pkuczynski pkuczynski added this to the v6.2 - New small features milestone Feb 1, 2022
@pkuczynski pkuczynski changed the title fix: remove duplicated extension in system.filePath feat: add ability to define number of generated extensions in system filePath Feb 1, 2022
@pkuczynski pkuczynski changed the title feat: add ability to define number of generated extensions in system filePath feat: add ability to define number of generated extensions in system.filePath Feb 1, 2022
@Shinigami92 Shinigami92 added the p: 1-normal Nothing urgent label Mar 15, 2022
src/system.ts Outdated
Comment on lines 181 to 202
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}`;
}
}
Copy link
Member

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()?

Copy link
Member Author

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...

Copy link
Member Author

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?

Copy link
Member

@ST-DDT ST-DDT Apr 6, 2022

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

Copy link
Member

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 {
Copy link
Member

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?}

Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

sure

Copy link
Member

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, ...

Copy link
Member Author

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.

Copy link
Member

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

@pkuczynski pkuczynski self-assigned this Mar 29, 2022
@pkuczynski pkuczynski added the s: on hold Blocked by something or frozen to avoid conflicts label Mar 29, 2022
@ST-DDT ST-DDT added the needs rebase There is a merge conflict label Mar 29, 2022
@ST-DDT
Copy link
Member

ST-DDT commented Mar 29, 2022

#300 has been merged

@ST-DDT ST-DDT removed the s: on hold Blocked by something or frozen to avoid conflicts label Mar 29, 2022
@Shinigami92
Copy link
Member

@pkuczynski please rebase and resolve any conflicts 🙂

@pkuczynski pkuczynski requested a review from a team April 5, 2022 23:00
@codecov
Copy link

codecov bot commented Apr 5, 2022

Codecov Report

Merging #395 (3651bb1) into main (5beac4b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 3651bb1 differs from pull request most recent head 1cddd1b. Consider uploading reports for the commit 1cddd1b to get more accurate results

@@           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           
Impacted Files Coverage Δ
src/system.ts 96.78% <100.00%> (+0.32%) ⬆️

@ST-DDT ST-DDT removed the needs rebase There is a merge conflict label Apr 6, 2022
Copy link
Member

@ST-DDT ST-DDT left a 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.

@pkuczynski
Copy link
Member Author

Please implement the requested features above.

Yes yes, give me a moment :)

@import-brain import-brain added the s: accepted Accepted feature / Confirmed bug label Apr 9, 2022
Copy link
Member

@import-brain import-brain left a 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');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
new FakerError('Options.ext shall not have negative value')
new FakerError('Options.ext should not be negative')

@xDivisionByZerox
Copy link
Member

@pkuczynski are you still working on this? Otherwise, I would continue the development process for you.

@xDivisionByZerox
Copy link
Member

Will be continued in #1101.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature needs rebase There is a merge conflict p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants