Created
May 28, 2018 23:36
-
-
Save babie/0c86e9edb52b40c515bc85b6a1acb957 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const fs = require('fs') | |
const path = require('path') | |
const traverse = require('traverse') | |
const setupTestsFile = fs.existsSync( | |
path.resolve(__dirname, 'src/setupTests.ts') | |
) | |
? '<rootDir>/src/setupTests.ts' | |
: undefined | |
module.exports = { | |
webpack: (config, env) => | |
Object.assign( | |
traverse(config).forEach(function f(x) { | |
if ( | |
x && | |
x.enforce === 'pre' && | |
x.use && | |
x.use instanceof Array && | |
x.use[0] && | |
x.use[0].options && | |
x.use[0].options instanceof Object && | |
x.use[0].options.useEslintrc === false | |
) { | |
this.update( | |
{ | |
test: /\.(js|jsx|mjs)$/, | |
loader: require.resolve('source-map-loader'), | |
enforce: 'pre', | |
include: __dirname, | |
exclude: /node_modules/ | |
}, | |
true | |
) | |
} | |
}), | |
{ | |
devtool: | |
process.env.NODE_ENV === 'production' | |
? undefined | |
: 'inline-source-map' | |
} | |
), | |
jest: (config, env) => | |
Object.assign(config, { | |
collectCoverageFrom: ['<rootDir>/**/*.{ts,tsx}'], | |
setupFiles: [ | |
path.resolve( | |
__dirname, | |
'node_modules/react-scripts/config/polyfills.js' | |
) | |
], | |
setupTestFrameworkScriptFile: setupTestsFile, | |
testMatch: [ | |
'<rootDir>/**/__tests__/**/*.ts?(x)', | |
'<rootDir>/**/?(*.)(spec|test).ts?(x)' | |
], | |
transform: { | |
'^.+\\.(js|jsx|mjs)$': '<rootDir>/node_modules/babel-jest', | |
'^.+\\.tsx?$': '<rootDir>/node_modules/ts-jest', | |
'^.+\\.css$': | |
'<rootDir>/node_modules/react-scripts/config/jest/cssTransform.js', | |
'^(?!.*\\.(js|jsx|mjs|css|json)$)': | |
'<rootDir>/node_modules/react-scripts/config/jest/fileTransform.js' | |
}, | |
transformIgnorePatterns: [ | |
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$' | |
], | |
moduleFileExtensions: [ | |
'web.ts', | |
'ts', | |
'web.tsx', | |
'tsx', | |
'web.js', | |
'js', | |
'web.jsx', | |
'jsx', | |
'json', | |
'node', | |
'mjs' | |
], | |
globals: { | |
'ts-jest': { | |
tsConfigFile: 'tsconfig.test.json' | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment