Skip to content

Commit 949d38f

Browse files
committed
feat: add jest react babel support
1 parent f251b22 commit 949d38f

File tree

8 files changed

+1816
-1314
lines changed

8 files changed

+1816
-1314
lines changed

declare/npm.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ declare module '@babel/plugin-proposal-optional-chaining';
7272
declare module '@babel/plugin-proposal-nullish-coalescing-operator';
7373
declare module '@babel/plugin-transform-react-display-name';
7474
declare module 'babel-plugin-react-wrapped-display-name';
75+
declare module 'enzyme-adapter-react-16';

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pri",
3-
"version": "4.0.20",
3+
"version": "4.0.21",
44
"types": "src/node/index.ts",
55
"main": "built/node/index.js",
66
"scripts": {
@@ -51,6 +51,7 @@
5151
"@koa/cors": "3.0.0",
5252
"@material-ui/core": "4.7.1",
5353
"@mdx-js/loader": "1.5.1",
54+
"@types/enzyme": "^3.10.5",
5455
"@types/eslint": "^6.1.3",
5556
"@types/fs-extra": "8.0.1",
5657
"@types/highlight.js": "9.12.3",
@@ -72,6 +73,7 @@
7273
"@typescript-eslint/eslint-plugin": "2.10.0",
7374
"@typescript-eslint/parser": "2.10.0",
7475
"babel-core": "7.0.0-bridge.0",
76+
"babel-jest": "25.1.0",
7577
"babel-loader": "8.0.6",
7678
"babel-plugin-react-css-modules": "5.2.6",
7779
"chokidar": "3.3.0",
@@ -81,6 +83,8 @@
8183
"conventional-changelog-cli": "^2.0.28",
8284
"cors": "2.8.5",
8385
"css-loader": "3.2.1",
86+
"enzyme": "^3.11.0",
87+
"enzyme-adapter-react-16": "^1.15.2",
8488
"eslint": "6.8.0",
8589
"eslint-config-airbnb-base": "14.0.0",
8690
"eslint-config-prettier": "6.10.0",
@@ -106,7 +110,7 @@
106110
"husky": "4.2.1",
107111
"inquirer": "7.0.0",
108112
"isomorphic-fetch": "2.2.1",
109-
"jest": "24.9.0",
113+
"jest": "25.1.0",
110114
"koa": "2.11.0",
111115
"koa-compress": "3.0.0",
112116
"koa-connect": "2.0.1",
@@ -141,7 +145,7 @@
141145
"url-join": "4.0.1",
142146
"url-loader": "3.0.0",
143147
"walk": "2.3.14",
144-
"webpack": "4.41.5",
148+
"webpack": "4.42.0",
145149
"webpack-bundle-analyzer": "3.6.0",
146150
"webpack-dev-server": "3.10.3",
147151
"webpack-node-externals": "1.7.2",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// setup file
2+
// import { configure } from 'enzyme';
3+
// import * as Adapter from 'enzyme-adapter-react-16';
4+
5+
// configure({ adapter: new Adapter() });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as babelJest from 'babel-jest';
2+
import { getBabelOptions } from '../../../utils/babel-options';
3+
4+
module.exports = babelJest.createTransformer(getBabelOptions());

src/built-in-plugins/command-test/plugin/run-test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export const runTest = async () => {
1111
findNearestNodemodulesFile('/.bin/jest'),
1212
`--testRegex "${path.join(pri.sourceRoot, testsPath.dir)}/.*\\.tsx?$"`,
1313
'--moduleFileExtensions ts tsx js jsx',
14+
`--transform '${JSON.stringify({
15+
[`${path.join(pri.sourceRoot, testsPath.dir)}/.*\\.tsx?$`]: path.join(__dirname, './jest-transformer'),
16+
})}'`,
17+
// `--setupFilesAfterEnv '${path.join(__dirname, './jest-setup')}'`,
1418
'--coverage',
1519
]
1620
.map(each => {

src/built-in-plugins/ensure-project-files/plugin/ensure-project.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function ensureProjectEntry() {
4343

4444
export function ensureTest() {
4545
pri.project.addProjectFiles({
46-
fileName: path.join(pri.sourceRoot, testsPath.dir, 'index.ts'),
46+
fileName: path.join(pri.sourceRoot, testsPath.dir, 'index.tsx'),
4747
pipeContent: async (prev: string) => {
4848
if (prev) {
4949
return prev;

src/utils/babel-options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function getBabelOptions(options?: Partial<DefaultOptions>) {
5050
[babelPluginProposalJsonStrings],
5151
[babelPluginProposalOptionalCatchBinding],
5252
// TODO: gulp don't support css module
53-
...(globalState.sourceConfig.type === 'project'
53+
...(globalState && globalState.sourceConfig && globalState.sourceConfig.type === 'project'
5454
? [
5555
[
5656
babelPluginReactCssModules,

0 commit comments

Comments
 (0)