https://github.com/joscha/ts-jest-transformer
A base class that can be used to implement a transformer for use with ts-jest
https://github.com/joscha/ts-jest-transformer
jest testing transformer ts-jest typescript
Last synced: 5 months ago
JSON representation
A base class that can be used to implement a transformer for use with ts-jest
- Host: GitHub
- URL: https://github.com/joscha/ts-jest-transformer
- Owner: joscha
- License: mit
- Created: 2017-03-14T12:15:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-05-30T20:15:53.000Z (about 6 years ago)
- Last Synced: 2025-09-12T20:22:24.891Z (10 months ago)
- Topics: jest, testing, transformer, ts-jest, typescript
- Language: JavaScript
- Size: 3.33 MB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `ts-jest` transformer base class
[](https://travis-ci.org/joscha/ts-jest-transformer)
[](https://greenkeeper.io/)
A base class that can be used to implement a transformer for use with [ts-jest](https://github.com/kulshekhar/ts-jest).
## Usage
Run
```console
yarn add ts-jest-transformer --dev
```
then create your custom transformer:
```js
// my-transformer.js
const path = require('path');
const TsJestTransformer = require('ts-jest-transformer');
class MyFileBaseNameTransformer extends TsJestTransformer {
process(src, filename, config, options) {
// Write TS here
const source = 'export default ' + JSON.stringify(path.basename(filename)) + ';';
return super.process(source, filename, config, options);
}
}
module.exports = new MyFileBaseNameTransformer();
```
and finally add the according `jest` config:
```json
{
"transform": {
"\\.(svg)$": "/my-transformer.js",
"\\.(ts|tsx)$": "/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
}
```
## Example
For a more complete example, you can have a look at the [ts-jest-transformer-example](https://github.com/joscha/ts-jest-transformer-example) repository.