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

this package was slowing down my jest tests #1114

Closed
Alino opened this issue Jun 28, 2022 · 9 comments · Fixed by #1629
Closed

this package was slowing down my jest tests #1114

Alino opened this issue Jun 28, 2022 · 9 comments · Fixed by #1629
Assignees
Labels
c: docs Improvements or additions to documentation good first issue Good for newcomers p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug

Comments

@Alino
Copy link

Alino commented Jun 28, 2022

I have been debugging my jest tests all day because they were failing due to timeouts, and sometimes passing but it took like 200 seconds sometimes to run few simple tests. Long story short, I have disabled creating my random mock data with faker and used hard-coded data instead. Now my jest runs in few seconds.

Note that it was not slowing down particular unit tests (they took few milliseconds), but the whole jest runtime took over hundreds of seconds. So it does not play nice with jest runner or whatever on windows 10 and also WSL.

@xDivisionByZerox
Copy link
Member

Please provide a minimal test suite where this issue is present.
I'm using faker for personal and business tests in jest for fuzzing and have no problems at all with faker. Jest itself is running terribly slow in windows machines (for me even with WSL), so please test your jest test suite on a linux VM and see if it happens there as well.

@Alino
Copy link
Author

Alino commented Jun 28, 2022

Sorry I can't spend more time on this by recreating a repo. But I can share the code change that has fixed my problem. Now my jest runs in 10 seconds instead of 200 seconds.

image

I was using version 6.2.0, I have also tried upgrading to the latest 7.3.0 but the problem was still there. Only removing it helped.

@import-brain import-brain added the s: awaiting more info Additional information are requested label Jun 29, 2022
@Shinigami92
Copy link
Member

Try @faker-js/faker/locale/en and test again

@maximgeerinck
Copy link

maximgeerinck commented Jul 8, 2022

/locale/en

I can verify that this sped up my tests a lot in some cases

@wodCZ
Copy link

wodCZ commented Aug 25, 2022

I've isolated my tests slowdown to Faker too.

console.time('require');
const faker = require('@faker-js/faker');
console.timeEnd('require');

The require takes on average 1.6s on 2019 MacBook Pro

console.time('require');
const faker = require('@faker-js/faker/locale/en');
console.timeEnd('require');

Changing the import to locale/en reduces the require time to ~180ms on average.

@ST-DDT ST-DDT added c: docs Improvements or additions to documentation good first issue Good for newcomers p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug and removed c: test s: awaiting more info Additional information are requested labels Oct 6, 2022
@ST-DDT
Copy link
Member

ST-DDT commented Oct 6, 2022

Team decision

We should amend the readme usage section to contain a hint why the user should use a locale specific variant.
https://github.com/faker-js/faker#-usage

The docs should also mention it in the usage section ( locale specific versions ).

Also the downsides of the the locale specific versions might need some documentation.

@CookrC
Copy link

CookrC commented Nov 29, 2022

Hello, I am willing to start updating the documentation relating to this issue! If you do not mind, I would like to be assigned to this issue.
Thanks!

@ST-DDT
Copy link
Member

ST-DDT commented Nov 29, 2022

Thanks for your help.

@ST-DDT
Copy link
Member

ST-DDT commented Nov 29, 2022

Note that we already have a page partially mentioning this, but the main usage page might need a hint for this as well and the localization page might need some more details.
https://fakerjs.dev/guide/localization.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: docs Improvements or additions to documentation good first issue Good for newcomers p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

8 participants