Skip to content

Commit 7f7818f

Browse files
committed
build: change jest config to use babel for ts transforms
This change updates the base jest config to use `babel-jest` with the typescript preset to transform `.ts` files. The existing `preprocessor`, which intercepts ts files, appears to be pretty old and wasn't implemented with entire packages of typescript source in mind.
1 parent 8c52146 commit 7f7818f

File tree

5 files changed

+218
-3
lines changed

5 files changed

+218
-3
lines changed

babel.config-ts.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* This file is purely being used for local jest runs, and doesn't participate in the build process.
3+
*/
4+
'use strict';
5+
6+
module.exports = {
7+
plugins: [
8+
'@babel/plugin-syntax-jsx',
9+
'@babel/plugin-transform-flow-strip-types',
10+
],
11+
presets: [
12+
['@babel/preset-env', {targets: {node: 'current'}}],
13+
'@babel/preset-typescript',
14+
],
15+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@babel/plugin-transform-template-literals": "^7.10.5",
3636
"@babel/preset-flow": "^7.10.4",
3737
"@babel/preset-react": "^7.23.3",
38+
"@babel/preset-typescript": "^7.26.0",
3839
"@babel/traverse": "^7.11.0",
3940
"@rollup/plugin-babel": "^6.0.3",
4041
"@rollup/plugin-commonjs": "^24.0.1",

packages/react/src/__tests__/ReactTypeScriptClass-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ describe('ReactTypeScriptClass', function () {
529529
'StateBasedOnContext uses the legacy contextTypes API which will soon be removed. ' +
530530
'Use React.createContext() with static contextType instead. (https://react.dev/link/legacy-context)\n' +
531531
(ReactFeatureFlags.enableOwnerStacks
532-
? ' in ProvideChildContextTypes.Object.<anonymous>.ProvideChildContextTypes (at **)'
532+
? ' in ProvideChildContextTypes.createElement (at **)'
533533
: ' in StateBasedOnContext (at **)\n') +
534534
' in ProvideChildContextTypes (at **)',
535535
]);
@@ -725,7 +725,7 @@ describe('ReactTypeScriptClass', function () {
725725
'ReadContext uses the legacy contextTypes API which will soon be removed. ' +
726726
'Use React.createContext() with static contextType instead. (https://react.dev/link/legacy-context)\n' +
727727
(ReactFeatureFlags.enableOwnerStacks
728-
? ' in ProvideContext.Object.<anonymous>.ProvideContext (at **)'
728+
? ' in ProvideContext.createElement (at **)'
729729
: ' in ReadContext (at **)\n') +
730730
' in ProvideContext (at **)',
731731
]);

scripts/jest/config.base.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ module.exports = {
77
'<rootDir>/scripts/bench/',
88
],
99
transform: {
10-
'.*': require.resolve('./preprocessor.js'),
10+
'^.+\\.ts$': [
11+
'babel-jest',
12+
{configFile: require.resolve('../../babel.config-ts.js')},
13+
],
14+
'.(?!ts$)': require.resolve('./preprocessor.js'),
1115
},
1216
prettierPath: require.resolve('prettier-2'),
1317
setupFiles: [require.resolve('./setupEnvironment.js')],

0 commit comments

Comments
 (0)