Skip to content

Instantly share code, notes, and snippets.

@benbarber
Created December 23, 2016 11:57
Show Gist options
  • Save benbarber/7841d6de2d57bc124c7bbe773199a12f to your computer and use it in GitHub Desktop.
Save benbarber/7841d6de2d57bc124c7bbe773199a12f to your computer and use it in GitHub Desktop.
Config for using Jest in a TypeScript + Webpack project
module.exports = 'test-file-stub'
{
"jest": {
"moduleFileExtensions": [
"ts",
"tsx"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/fileMock.js",
"\\.(css|scss|less)$": "<rootDir>/styleMock.js"
},
"transform": {
"^.+\\.(ts|tsx)$": "<rootDir>/transform.js"
}
}
}
module.exports = {}
const tsc = require('typescript')
const tsConfig = require('tsconfig.json')
module.exports = {
process(src, path) {
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
return tsc.transpile(
src,
tsConfig.compilerOptions,
path,
[]
)
}
return src
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment