ts-jest-transformer

1.0.0 • Public • Published

ts-jest transformer base class

Build Status

A base class that can be used to implement a transformer for use with ts-jest.

Usage

Run

yarn add ts-jest-transformer --dev

then create your custom transformer:

// 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:

{
    "transform": {
        "\\.(svg)$": "<rootDir>/my-transformer.js",
        "\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ]
}

Readme

Keywords

none

Package Sidebar

Install

npm i ts-jest-transformer

Weekly Downloads

95

Version

1.0.0

License

MIT

Last publish

Collaborators

  • joscha