-
-
Notifications
You must be signed in to change notification settings - Fork 887
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
After updating faker, jest tests started failing #2978
Comments
I'm unable to reproduce the error (outside of jest). import { faker } from '@faker-js/faker/locale/en';
import pack from './node_modules/@faker-js/faker/package.json' assert { type: 'json' };
console.log(faker.helpers.arrayElement(['test']), pack.version); $ pnpm exe
> faker-test@ exe ~/git/Faker/faker-playground
> tsx index.ts
test 8.1.0 $ pnpm exe
> faker-test@ exe ~/git/Faker/faker-playground
> tsx index.ts
test 8.4.1 Please also check the latest version of faker v8.4.1. |
The error occurs when upgrading from 8.0.2 to 8.1.0. |
Could you please also test our latest alpha? Please create a minimal reproduction. |
When using the method discussed on Stack Overflow above, the error disappears. Specifically: import { fakerRU } from '@faker-js/faker' Instead of: import { faker } from '@faker-js/faker/locale/ru' The problem persists in the latest alpha. |
Caused by 3df98a0 Does the following work for you? |
In this case, an error occurs: > jest store/__tests__/profiles.test.ts
FAIL store/__tests__/profiles.test.ts
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/someUser/Documents/work/company/ui/website/node_modules/@faker-js/faker/dist/esm/locale/en.mjs:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import{a}from"../chunk-3LPAMF3R.mjs";import"../chunk-LSZKOVGW.mjs";import"../chunk-GTEBSQTL.mjs";export{a as faker};
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import { faker } from '@faker-js/faker/dist/esm/locale/en'
Fixed by adding transformIgnorePatterns node_modules/@faker to jest.config.js |
If you are using CJS code, then you have to adjust the import accordingly. v8.1.0 is also the first version that uses node 14 features (AFAICT). Note: fakerjs-v9 (currently alpha) has improved tree-shaking, so that the imports with paths are no longer needed. |
Please describe in more detail what you mean In this case, do I need to import { fakerRU } for localization? |
import { faker } from '@faker-js/faker/dist/cjs/locale/ru'; alternatively: import { fakerRU } from '@faker-js/faker'; You might still run into troubles, because of JS Features > Node 12. |
Got it, thank you! |
Pre-Checks
Describe the bug
The faker package was updated in the project from 8.0.0 to 8.1.0.
Now, if you use the following import in jest tests:
or
you get the following error:
If you use the following, there is no error:
There are no additional configurations for faker in jest.config.js.
Minimal reproduction code
No response
Additional Context
No response
Environment Info
Which module system do you use?
Used Package Manager
npm
The text was updated successfully, but these errors were encountered: