Skip to content

Commit

Permalink
Included setupTests.js in the jest-config package
Browse files Browse the repository at this point in the history
  • Loading branch information
souyahia-monk committed Sep 3, 2024
1 parent 660dc07 commit 31daf77
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
38 changes: 35 additions & 3 deletions configs/jest-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ And replace the `base` keyword with one of the following Jest configuration avai
| `base` | Base configuration for any Node.Js project . |
| `react` | Base configuration used for React-based projects. |

# Tests Setup
If you are using the [@monkvision/test-utils](https://github.com/monkvision/monkjs/tree/main/configs/test-utils)
package, and you wish to enjoy Jest automocking with the provided mocks, you can use the following test set up file :
# External Developments
If you are using MonkJs packages in an app outside the MonkJs monorepository, you might want to use our predefined
tests setup file to avoid ECMAScript Modules conflicts and to set up automocks for @monkvision packages :

```js
const { base } = require('@monkvision/jest-config');
Expand All @@ -40,3 +40,35 @@ module.exports = {
setupFilesAfterEnv: ['<rootDir>/node_modules/@monkvision/jest-config/setupTests.js']
};
```

This will prevent errors like this to show up when running your tests :

```
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/souyahia/Projects/Monk/monkjs_private/apps/drive/node_modules/ky/distribution/index.js:2
import { Ky } from './core/Ky.js';
^^^^^^
SyntaxError: Cannot use import statement outside a module
```
5 changes: 1 addition & 4 deletions configs/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
"main": "index.js",
"license": "BSD-3-Clause-Clear",
"files": [
"index.js",
"base.js",
"react.js",
"__mocks__",
"*.js",
"LICENSE",
"README.md"
],
Expand Down

0 comments on commit 31daf77

Please sign in to comment.