GithubHelp home page GithubHelp logo

tahoemph / jest-meteor-stubs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tomscholz/meteor-jest-stubs

0.0 2.0 0.0 23 KB

Stubs for using Jest to unit test Meteor modules

License: MIT License

JavaScript 100.00%

jest-meteor-stubs's Introduction

meteor-jest-stubs

This is a supported fork of orangecms/jest-meteor-stubs. Please note that, the package name is slightly different that the original one:

- jest-meteor-stubs
+ meteor-jest-stubs

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 meteor-jest-stubs or yarn add -D meteor-jest-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.

Here is a working example:

module.exports = {
  transform: {
    '^.+\\.jsx?$': 'babel-jest',
  },
  moduleFileExtensions: [
    'js',
    'jsx',
  ],
  modulePaths: [
    '<rootDir>/node_modules/',
    '<rootDir>/node_modules/jest-meteor-stubs/lib/',
  ],
  moduleNameMapper: {
    '^(.*):(.*)$': '$1_$2',
  },
  unmockedModulePathPatterns: [
    '/^imports\\/.*\\.jsx?$/',
    '/^node_modules/',
  ],
};

jest-meteor-stubs's People

Contributors

mackbrowne avatar tomscholz avatar callmephilip avatar orangecms avatar

Watchers

Michael Hunter avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.