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: introduce FakerCore #2838

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
Open

feat: introduce FakerCore #2838

wants to merge 8 commits into from

Conversation

ST-DDT
Copy link
Member

@ST-DDT ST-DDT commented Apr 20, 2024

First part of the standalone module function feature #2667

@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent labels Apr 20, 2024
@ST-DDT ST-DDT added this to the v9.0 milestone Apr 20, 2024
@ST-DDT ST-DDT requested review from a team April 20, 2024 14:11
@ST-DDT ST-DDT self-assigned this Apr 20, 2024
Copy link

netlify bot commented Apr 20, 2024

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit 7353a69
🔍 Latest deploy log https://app.netlify.com/sites/fakerjs/deploys/6648f5ce488d8e00081f25af
😎 Deploy Preview https://deploy-preview-2838.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@Shinigami92 Shinigami92 left a comment

Choose a reason for hiding this comment

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

I know the PR is still in draft but I would like to provide some early-feedback

  1. I think the refDate should still be named something like default or fallback or base, so the intent is more clear and there might be no variable naming conflict when using an option's refDate + the ...RefDate
  2. I suggest to not do something like super({ fakerCore: fakerCore ?? { locale, randomizer, config: {} } }) but only pass the locale and randomizer so the config get's set like every other method call to a default internally. Or is there something special about that I currently overlook? 👀

@ST-DDT
Copy link
Member Author

ST-DDT commented Apr 22, 2024

  1. Done
  2. Changed slightly to improve readability.

@ST-DDT
Copy link
Member Author

ST-DDT commented Apr 22, 2024

Does anybody know why this test is failing with that particular error message?

❯ test/simple-faker.spec.ts > simpleFaker > should not log anything on startup
→ Unexpected token ','

It seems to happen only with vitest/CJS.

@ST-DDT ST-DDT requested a review from Shinigami92 April 22, 2024 21:53
@Shinigami92
Copy link
Member

Shinigami92 commented Apr 23, 2024

Does anybody know why this test is failing with that particular error message?

❯ test/simple-faker.spec.ts > simpleFaker > should not log anything on startup
→ Unexpected token ','

It seems to happen only with vitest/CJS.

If I set minify: false in tsup.config.ts everything runs fine. Please report a bug-issue to https://github.com/egoist/tsup

Or it is related to https://github.com/egoist/tsup/issues/1091

@ST-DDT
Copy link
Member Author

ST-DDT commented May 14, 2024

The error is caused by this part:

_class.prototype.__init23.call(this);,this.definitions=_chunkWAQHUEHTcjs.d.call(void 0, this.rawDefinitions)
                                     ^

Which is equivalent to this source code:

faker/src/faker.ts

Lines 195 to 197 in e4da2f5

super({ fakerCore });
this.definitions = createLocaleProxy(this.rawDefinitions);

@ST-DDT
Copy link
Member Author

ST-DDT commented May 14, 2024

I created an issue in tsup with a minimal reproduction:

And it has reeeaaally specific conditions, check the issue for more details.

Copy link

codecov bot commented May 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.95%. Comparing base (7dc8a18) to head (7353a69).

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2838      +/-   ##
==========================================
- Coverage   99.96%   99.95%   -0.01%     
==========================================
  Files        2977     2977              
  Lines      215422   215463      +41     
  Branches      950      954       +4     
==========================================
+ Hits       215351   215375      +24     
- Misses         71       88      +17     
Files Coverage Δ
src/faker.ts 100.00% <100.00%> (ø)
src/modules/number/index.ts 100.00% <100.00%> (ø)
src/simple-faker.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Comment on lines +89 to +92
get rawDefinitions(): LocaleDefinition {
// TODO @ST-DDT 2024-05-14: Should we deprecate this?
return this.fakerCore.locale;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we deprecate this field?

@ST-DDT ST-DDT marked this pull request as ready for review May 14, 2024 20:48
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 p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants