Skip to content

Commit 2796ba5

Browse files
committed
ctco-dev: fix jest config
1 parent 51811e2 commit 2796ba5

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
const tsJestPreprocessor = require('ts-jest/preprocessor');
3+
module.exports = tsJestPreprocessor;

packages/react-scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aeldar/react-scripts",
3-
"version": "1.1.4-10",
3+
"version": "1.1.4-11",
44
"description": "Configuration and scripts for Create React App. Modified by @aeldar",
55
"repository": "aeldar/create-react-app",
66
"license": "MIT",

packages/react-scripts/scripts/utils/createJestConfig.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,34 @@ module.exports = (resolve, rootDir, isEjecting) => {
1515
// Use this instead of `paths.testsSetup` to avoid putting
1616
// an absolute filename into configuration after ejecting.
1717
const setupTestsFile = fs.existsSync(paths.testsSetup)
18-
? '<rootDir>/src/setupTests.js'
18+
? '<rootDir>/src/setupTests.ts'
1919
: undefined;
2020

2121
// TODO: I don't know if it's safe or not to just use / as path separator
2222
// in Jest configs. We need help from somebody with Windows to determine this.
2323
const config = {
24-
collectCoverageFrom: ['src/**/*.{js,jsx,mjs}'],
24+
collectCoverageFrom: ['src/**/*.{js,jsx,mjs,ts,tsx}'],
2525
setupFiles: [resolve('config/polyfills.js')],
2626
setupTestFrameworkScriptFile: setupTestsFile,
2727
testMatch: [
28-
'<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}',
29-
'<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}',
28+
'<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs,ts,tsx}',
29+
'<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs,ts,tsx}',
3030
],
3131
testEnvironment: 'node',
3232
testURL: 'http://localhost',
3333
transform: {
3434
'^.+\\.(js|jsx|mjs)$': isEjecting
3535
? '<rootDir>/node_modules/babel-jest'
3636
: resolve('config/jest/babelTransform.js'),
37+
'^.+\\.tsx?$': resolve('config/jest/typescriptTransform.js'),
3738
'^.+\\.css$': resolve('config/jest/cssTransform.js'),
3839
'^(?!.*\\.(js|jsx|mjs|css|json)$)': resolve(
3940
'config/jest/fileTransform.js'
4041
),
4142
},
42-
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$'],
43+
transformIgnorePatterns: [
44+
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$',
45+
],
4346
moduleNameMapper: {
4447
'^react-native$': 'react-native-web',
4548
},
@@ -51,7 +54,16 @@ module.exports = (resolve, rootDir, isEjecting) => {
5154
'jsx',
5255
'node',
5356
'mjs',
57+
'web.ts',
58+
'ts',
59+
'web.tsx',
60+
'tsx',
5461
],
62+
globals: {
63+
'ts-jest': {
64+
tsConfigFile: paths.appTsTestConfig,
65+
},
66+
},
5567
};
5668
if (rootDir) {
5769
config.rootDir = rootDir;

0 commit comments

Comments
 (0)