Skip to content

Commit

Permalink
(refactor): get tsdx test working with babel-jest, JS/JSX
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Apr 20, 2022
1 parent 12aa4a5 commit 53f047d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 172 deletions.
3 changes: 3 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ module.exports = {
presets: [
['@babel/preset-env'], // needed at least until https://github.com/jaredpalmer/tsdx/pull/473 is released
['@babel/preset-react']
],
plugins: [
['@babel/plugin-proposal-class-properties'] // required for tsdx test, related to https://github.com/jaredpalmer/tsdx/issues/383#issuecomment-581637869
]
}
6 changes: 4 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ module.exports = {
'window-resizeto/polyfill'
],
transform: {
// use babel-jest@23 for babel@6 support (https://github.com/facebook/jest/issues/8230#issuecomment-479470547)
'\\.js$': require.resolve('babel-jest')
// support babel-jest. TSDX defaults to just ts-jest. see https://github.com/jaredpalmer/tsdx/pull/486
'\\.js$': 'babel-jest'
},
// support JS + JSX. TSDX defaults to just TS + TSX. see https://github.com/jaredpalmer/tsdx/pull/486
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
coveragePathIgnorePatterns: [
'/node_modules/', // default
'<rootDir>/test/' // ignore any test helper files
Expand Down
167 changes: 0 additions & 167 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"lint:fix": "tsdx lint '**/*.js' --fix",
"start": "webpack-dev-server -d --inline --hot",
"build": "tsdx build",
"test": "jest",
"test": "tsdx test",
"test:pub": "npm run build && npm pack",
"pub": "npm run build && npm publish",
"changelog": "changelog-maker"
Expand All @@ -64,7 +64,6 @@
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.6",
"babel-core": "^6.26.3",
"babel-eslint": "^10.0.2",
"babel-jest": "^23.6.0",
"babel-loader": "^6.0.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
Expand All @@ -79,7 +78,6 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-standard": "^4.0.1",
"jest": "^24.8.0",
"jest-environment-jsdom-fifteen": "^1.0.2",
"jest-without-globals": "^0.0.2",
"react": "^17.0.2",
Expand Down

0 comments on commit 53f047d

Please sign in to comment.