Skip to content

Commit 8f124fe

Browse files
committed
(refactor): get tsdx test working with babel-jest, JS/JSX
- TSDX changes some of Jest's defaults and so causes some issues for JS/JSX support - by default Jest supports JS and JSX in testMatch and babel-jest is automatically run on JS/JSX files if a babelrc is found - also had to configure class-properties for Babel as while it's automatically included with tsdx build, no Babel transforms are included with tsdx test (yet) (deps): remove jest as it's a dep of TSDX (deps): remove babel-jest@23 since we can use @24 now - which is a dep of jest@24 - remove require.resolve from it as it causes errors due to not being a direct dependency
1 parent 2980b8a commit 8f124fe

File tree

4 files changed

+8
-172
lines changed

4 files changed

+8
-172
lines changed

.babelrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ module.exports = {
22
presets: [
33
['@babel/preset-env'], // needed at least until https://github.com/jaredpalmer/tsdx/pull/473 is released
44
['@babel/preset-react']
5+
],
6+
plugins: [
7+
['@babel/plugin-proposal-class-properties'] // required for tsdx test, related to https://github.com/jaredpalmer/tsdx/issues/383#issuecomment-581637869
58
]
69
}

jest.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ module.exports = {
66
'<rootDir>/test/config/window-resizeTo.js'
77
],
88
transform: {
9-
// use babel-jest@23 for babel@6 support (https://github.com/facebook/jest/issues/8230#issuecomment-479470547)
10-
'\\.js$': require.resolve('babel-jest')
9+
// support babel-jest. TSDX defaults to just ts-jest. see https://github.com/jaredpalmer/tsdx/pull/486
10+
'\\.js$': 'babel-jest'
1111
},
12+
// support JS + JSX. TSDX defaults to just TS + TSX. see https://github.com/jaredpalmer/tsdx/pull/486
13+
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
1214
coveragePathIgnorePatterns: [
1315
'/node_modules/', // default
1416
'<rootDir>/test/' // ignore any test helper files

package-lock.json

Lines changed: 0 additions & 167 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"lint:fix": "tsdx lint '**/*.js' --fix",
4242
"start": "webpack-dev-server -d --inline --hot",
4343
"dist": "tsdx build",
44-
"test": "jest",
44+
"test": "tsdx test",
4545
"test:pub": "npm run dist && npm pack",
4646
"pub": "npm run dist && npm publish",
4747
"changelog": "changelog-maker"
@@ -60,7 +60,6 @@
6060
"@babel/preset-react": "^7.8.3",
6161
"babel-core": "^6.26.3",
6262
"babel-eslint": "^10.0.2",
63-
"babel-jest": "^23.6.0",
6463
"babel-loader": "^6.0.0",
6564
"babel-preset-es2015": "^6.14.0",
6665
"babel-preset-react": "^6.11.1",
@@ -76,7 +75,6 @@
7675
"eslint-plugin-promise": "^4.2.1",
7776
"eslint-plugin-react": "^7.18.3",
7877
"eslint-plugin-standard": "^4.0.1",
79-
"jest": "^24.8.0",
8078
"jest-without-globals": "^0.0.2",
8179
"react": "^16.8.6",
8280
"react-dom": "^16.8.6",

0 commit comments

Comments
 (0)