-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edcfad9
commit 54009dd
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|