Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/HosseinAgha/tsconfig-paths-jest-mapper

Generates Jest moduleNameMappers from TSConfig's paths
https://github.com/HosseinAgha/tsconfig-paths-jest-mapper

jest jest-config tsconfig-paths typescript

Last synced: about 2 months ago
JSON representation

Generates Jest moduleNameMappers from TSConfig's paths

Awesome Lists containing this project

README

        

[![NPM ndb package](https://img.shields.io/npm/v/tsconfig-paths-jest-mapper)](https://www.npmjs.com/package/tsconfig-paths-jest-mapper)
[![CircleCI](https://circleci.com/gh/HosseinAgha/vscode-open-react-component-style.svg?style=svg)](https://circleci.com/gh/HosseinAgha/vscode-open-react-component-style)

Convert your tsconfig paths to jest `moduleNameMappers`.
This introduces many bug fixes and improvements to [archived](https://github.com/ryohey/tsconfig-paths-jest) [tsconfig-paths-jest](https://www.npmjs.com/package/tsconfig-paths-jest) package.

## Usage
In your `jest.config.js` file:
```javascript
const getJestMappersFromTSConfig = require('tsconfig-paths-jest-mapper');
const moduleNameMapper = getJestMappersFromTSConfig();

module.exports = {
moduleNameMapper,
// ... other configs
}
```

It assumes you have tsconfig besides your `jest.config.js` file.
You can also provide the path to your tsconfig if it is in a non-standard location:
```javascript
const path = require('path');
const getJestMappersFromTSConfig = require('tsconfig-paths-jest-mapper');
const tsconfigPath = path.resolve(__dirname, '../../tsconfig.json');
const moduleNameMapper = getJestMappersFromTSConfig(tsconfigPath);

module.exports = {
moduleNameMapper,
// ... other configs
}
```

## Options

- __startsWith:__ ensures that all the replaced paths (keys in the tsconfig) happen at the beginning of the path. `true` by default.