Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/orangecms/jest-meteor-stubs
Stubs for using Jest to unit test Meteor modules
https://github.com/orangecms/jest-meteor-stubs
Last synced: 3 months ago
JSON representation
Stubs for using Jest to unit test Meteor modules
- Host: GitHub
- URL: https://github.com/orangecms/jest-meteor-stubs
- Owner: orangecms
- License: mit
- Created: 2017-04-28T06:56:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-11T20:26:08.000Z (about 6 years ago)
- Last Synced: 2024-09-30T05:20:29.242Z (3 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 14
- Watchers: 4
- Forks: 21
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## About
Testing Meteor code is very slow when using the built-in `meteor test` command.
These stubs will help you get rid of the dependencies which are not present in
your project's `node_modules` directory. Use the setup below which does most of
the actual magic. :)## Installation
`npm i -D jest-meteor-stubs` or `yarn add -D jest-meteor-stubs`## How it works
Jest preprocesses the files to be executed through the test runner. When pulling
in dependencies, i.e. using `require` (in ES6 `import`), similar to the default
behavior of Node.js, the resolver will look for them in a local directory named
`node_modules`. However, Meteor injects additional modules when running `meteor`
instead of plain Node.js, which do not reside in this directory. Jest allows you
to overcome this issue by providing additional locations where the load should
look for modules.## Usage
Add this module's `lib/` directory to the `modulePaths` in your Jest config.
For Meteor packages, you will need to use `moduleNameMapper` to rewrite the
module names to use `_` instead of `:` for the namespaces as `:` is not allowed
by some file/operating systems.
The configuration has to be in `jest.config.js` in Jest 20 because of
[a bug in the mapper](https://github.com/facebook/jest/issues/3716).Here is a working example:
```javascript
module.exports = {
transform: {
'^.+\\.jsx?$': 'babel-jest',
},
moduleFileExtensions: [
'js',
'jsx',
],
modulePaths: [
'/node_modules/',
'/node_modules/jest-meteor-stubs/lib/',
],
moduleNameMapper: {
'^(.*):(.*)$': '$1_$2',
},
unmockedModulePathPatterns: [
'/^imports\\/.*\\.jsx?$/',
'/^node_modules/',
],
};
```## Examples
Please see [this demo](https://github.com/orangecms/jest-meteor-demo)
for a small example. :)