Giter Site home page Giter Site logo

ra80533 / ts-jest-resolver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vitorluizc/ts-jest-resolver

0.0 1.0 0.0 223 KB

A resolver for jest that uses the same strategy as TS when resolving files with JavaScript extension (".js"). It works pretty well with ts-jest or babel with @babel/preset-typescript.

License: MIT License

JavaScript 28.35% TypeScript 71.65%

ts-jest-resolver's Introduction

ts-jest-resolver

Build Status License

A resolver for jest that uses the same strategy as TS when resolving files with JavaScript extension (".js"). It works pretty well with ts-jest or babel with @babel/preset-typescript.

  • ๐Ÿ“ฆ Distributions in ESM and CommonJS.
    • Supports both Node.js ESM (import/export) and CommonJS (require/module.exports).
  • โšก Lightweight:
    • It's bundled using rollup.js.
  • ๐Ÿ”‹ Bateries included:
    • No dependencies, it just uses jest-resolve (which is already a jest dependency).
  • โœ… Safe:

Usage

This library is published in the NPM registry and can be installed using any compatible package manager.

npm install ts-jest-resolver --save

# For Yarn, use the command below.
yarn add ts-jest-resolver

After installation, you can set "ts-jest-resolver" as jest's resolver.

// jest.config.js

module.exports = {
  preset: "ts-jest",
  resolver: "ts-jest-resolver",
};

How it works

It just changes module resolution when the import statement has ".js" extension:

Ex.

import EventEmitter from './EventEmitter.js';
  1. It tries to resolve the import path with ".ts" instead of ".js".

    Ex.

    import EventEmitter from './EventEmitter.ts';
  2. If the module wasn't found, it tries to resolve the import path with ".tsx" instead of ".js".

    Ex.

    import EventEmitter from './EventEmitter.tsx';
  3. If the module wasn't found, it resolves to the original import path (with ".js").

    Ex.

    import EventEmitter from './EventEmitter.js';

License

Released under MIT License.

ts-jest-resolver's People

Contributors

vitorluizc avatar

Watchers

 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.