Skip to content

Commit 9695642

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 4a123c1 commit 9695642

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
@@ -8,9 +8,11 @@ module.exports = {
88
'window-resizeto/polyfill'
99
],
1010
transform: {
11-
// use babel-jest@23 for babel@6 support (https://github.com/facebook/jest/issues/8230#issuecomment-479470547)
12-
'\\.js$': require.resolve('babel-jest')
11+
// support babel-jest. TSDX defaults to just ts-jest. see https://github.com/jaredpalmer/tsdx/pull/486
12+
'\\.js$': 'babel-jest'
1313
},
14+
// support JS + JSX. TSDX defaults to just TS + TSX. see https://github.com/jaredpalmer/tsdx/pull/486
15+
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
1416
coveragePathIgnorePatterns: [
1517
'/node_modules/', // default
1618
'<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
@@ -44,7 +44,7 @@
4444
"lint:fix": "tsdx lint '**/*.js' --fix",
4545
"start": "webpack-dev-server -d --inline --hot",
4646
"build": "tsdx build",
47-
"test": "jest",
47+
"test": "tsdx test",
4848
"test:pub": "npm run build && npm pack",
4949
"pub": "npm run build && npm publish",
5050
"changelog": "changelog-maker"
@@ -64,7 +64,6 @@
6464
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.6",
6565
"babel-core": "^6.26.3",
6666
"babel-eslint": "^10.0.2",
67-
"babel-jest": "^23.6.0",
6867
"babel-loader": "^6.0.0",
6968
"babel-preset-es2015": "^6.14.0",
7069
"babel-preset-react": "^6.11.1",
@@ -79,7 +78,6 @@
7978
"eslint-plugin-promise": "^4.2.1",
8079
"eslint-plugin-react": "^7.18.3",
8180
"eslint-plugin-standard": "^4.0.1",
82-
"jest": "^24.8.0",
8381
"jest-environment-jsdom-fifteen": "^1.0.2",
8482
"jest-without-globals": "^0.0.2",
8583
"react": "^17.0.2",

0 commit comments

Comments
 (0)