Skip to content

Commit

Permalink
doc: add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinAgha committed Sep 25, 2019
1 parent edcfad9 commit 54009dd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Convert your tsconfig paths to jest `moduleNameMappers`.
I created this as [tsconfig-paths-jest](https://www.npmjs.com/package/tsconfig-paths-jest) is not maintained anymore (archived).
Specially this package will escape the special character like `$` in `$components`.

# 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
}
```
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@
"version": "1.0.0",
"main": "dist/index.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/HosseinAgha/tsconfig-paths-jest-mapper.git"
},
"author": {
"name": "Hossein Saniei",
"email": "[email protected]"
},
"scripts": {
"prepare": "npm run compile",
"precompile": "rimraf dist",
"compile": "tsc",
"test": "jest"
},
"keywords": [
"TypeScript",
"jest",
"config",
"tsconfig",
"tsconfig-paths"
],
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/plugin-proposal-class-properties": "^7.5.5",
Expand Down

0 comments on commit 54009dd

Please sign in to comment.