ts-jest-transformer
v1.0.0
Published
A base class that can be used to implement a transformer for use with tes-jest
Downloads
463
Readme
ts-jest
transformer base class
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"
]
}