Last active
January 18, 2022 19:15
-
-
Save ShayDavidson/af407086b857d7d0a5e3d12e85575355 to your computer and use it in GitHub Desktop.
Istanbul coverage fix for Nest.JS code
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
// HOW TO USE: | |
// 1. copy the code below into a new file (e.g. `jest.fixCoverage.js`). | |
// 2. In your `jest.config.js`, have this for the `transform` config: | |
// transform: { '^.+\\.[tj]sx?$': '<rootDir>/jest.fixCoverage.js' }, | |
const { default: tsJest } = require('ts-jest') | |
module.exports = fixIstanbulDecoratorCoverageTransformer() | |
function fixIstanbulDecoratorCoverageTransformer() { | |
const transformer = tsJest.createTransformer() | |
const process = transformer.process.bind(transformer) | |
transformer.process = (...args) => { | |
let result = process(...args) | |
result = result.replaceAll('__decorate', '/* istanbul ignore next */__decorate') | |
result = result.replace(/(\(.*__metadata\)\("design:paramtypes",.*)/g, '/* istanbul ignore next */$1') | |
result = result.replace(/(\(.*__metadata\)\("design:returntype",.*)/g, '/* istanbul ignore next */$1') | |
result = result.replace(/(\(.*__metadata\)\("design:type",.*)/g, '/* istanbul ignore next */$1') | |
result = result.replace(/(\(.*__metadata\)\("design:type", )(.*)/g, '$1/* istanbul ignore next */$2') | |
return result | |
} | |
return transformer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment