1.0.0 • Published 7 years ago

ts-jest-transformer v1.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

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"
    ]
}