From 6f476ecdef9da088024c7c5ba7130e60304ea78b Mon Sep 17 00:00:00 2001 From: tony chen <329604487@qq.com> Date: Mon, 14 Mar 2022 14:57:26 +0800 Subject: [PATCH] fix(rn): rn test use testing library (#11419) * feat: refactory taro rn tests * feat: update tsconfig --- package.json | 7 +- .../taro-components-rn/__mocks__/fileMock.js | 8 - .../__snapshots__/checkbox.spec.tsx.snap | 90 - .../__snapshots__/movableView.spec.tsx.snap | 33 - .../__snapshots__/video.spec.tsx.snap | 114 - .../__snapshots__/view.spec.tsx.snap | 3 - .../__snapshots__/virtualList.spec.tsx.snap | 15 - .../__tests__/button.-spec.tsx | 97 - .../__tests__/camera.spec.tsx | 11 - .../__tests__/checkbox.spec.tsx | 80 - .../__tests__/icon.spec.tsx | 35 - .../__tests__/image.spec.tsx | 60 - .../__tests__/input.spec.tsx | 35 - .../__tests__/movableArea.spec.tsx | 40 - .../__tests__/scrollView.spec.tsx | 12 - .../__tests__/text.spec.tsx | 22 - .../__tests__/view.spec.tsx | 15 - packages/taro-components-rn/jest.config.js | 31 +- packages/taro-components-rn/package.json | 7 +- packages/taro-components-rn/setup.js | 18 - .../{ => src}/__tests__/1x1.png | Bin .../__snapshots__/camera.spec.tsx.snap | 0 .../__snapshots__/pickerView.spec.tsx.snap | 148 +- .../__snapshots__/richText.spec.tsx.snap | 0 .../__snapshots__/scrollView.spec.tsx.snap | 8 +- .../__snapshots__/video.spec.tsx.snap | 181 ++ .../__snapshots__/virtualList.spec.tsx.snap | 28 + .../src/__tests__/button.spec.tsx | 76 + .../src/__tests__/camera.spec.tsx | 10 + .../src/__tests__/checkbox.spec.tsx | 77 + .../src/__tests__/icon.spec.tsx | 37 + .../src/__tests__/image.spec.tsx | 39 + .../src/__tests__/input.spec.tsx | 40 + .../src/__tests__/movableArea.spec.tsx | 32 + .../{ => src}/__tests__/movableView.spec.tsx | 13 +- .../{ => src}/__tests__/pickerView.spec.tsx | 13 +- .../{ => src}/__tests__/richText.spec.tsx | 7 +- .../src/__tests__/scrollView.spec.tsx | 10 + .../src/__tests__/text.spec.tsx | 17 + .../{ => src}/__tests__/utils.spec.tsx | 2 +- .../{ => src}/__tests__/video.spec.tsx | 10 +- .../src/__tests__/view.spec.tsx | 13 + .../{ => src}/__tests__/virtualList.spec.tsx | 11 +- .../src/components/Button/index.tsx | 7 +- .../src/components/Icon/index.tsx | 3 +- .../src/components/Image/index.tsx | 1 + .../src/components/MovableArea/index.tsx | 2 +- .../src/components/MovableView/index.tsx | 2 +- .../components/Video/__test__/video.test.js | 26 - packages/taro-components-rn/src/setup.ts | 1 + .../src/types/definition.d.ts | 5 + packages/taro-components-rn/tsconfig.json | 12 +- packages/taro-rn/jest.config.js | 33 +- packages/taro-rn/package.json | 8 +- .../__tests__/__mock__/mockAsyncStorage.js | 1 - .../__tests__/__mock__/mockExpoPermissions.js | 2 +- .../__snapshots__/interactive.test.js.snap | 1690 --------------- .../__snapshots__/scanCode.test.js.snap | 113 + .../taro-rn/src/__tests__/interactive.test.js | 106 +- .../taro-rn/src/__tests__/keyboard.test.js | 12 +- .../taro-rn/src/__tests__/scanCode.test.js | 14 + .../taro-rn/src/__tests__/scanCode.test_.js | 24 - .../taro-rn/src/__tests__/storage.test.js | 2 +- packages/taro-rn/src/__tests__/system.test.js | 16 +- packages/taro-rn/src/lib/Mask.tsx | 1 + packages/taro-rn/src/lib/Popup.tsx | 2 +- .../taro-rn/src/lib/connectSocket/index.ts | 1 - packages/taro-rn/src/lib/request/index.ts | 2 +- packages/taro-rn/src/lib/scanCode/index.tsx | 2 +- packages/taro-rn/{setup.js => src/setup.ts} | 40 +- packages/taro-router-rn/jest.config.js | 35 +- yarn.lock | 1825 ++--------------- 72 files changed, 1074 insertions(+), 4419 deletions(-) delete mode 100644 packages/taro-components-rn/__mocks__/fileMock.js delete mode 100644 packages/taro-components-rn/__tests__/__snapshots__/checkbox.spec.tsx.snap delete mode 100644 packages/taro-components-rn/__tests__/__snapshots__/movableView.spec.tsx.snap delete mode 100644 packages/taro-components-rn/__tests__/__snapshots__/video.spec.tsx.snap delete mode 100644 packages/taro-components-rn/__tests__/__snapshots__/view.spec.tsx.snap delete mode 100644 packages/taro-components-rn/__tests__/__snapshots__/virtualList.spec.tsx.snap delete mode 100644 packages/taro-components-rn/__tests__/button.-spec.tsx delete mode 100644 packages/taro-components-rn/__tests__/camera.spec.tsx delete mode 100644 packages/taro-components-rn/__tests__/checkbox.spec.tsx delete mode 100644 packages/taro-components-rn/__tests__/icon.spec.tsx delete mode 100644 packages/taro-components-rn/__tests__/image.spec.tsx delete mode 100644 packages/taro-components-rn/__tests__/input.spec.tsx delete mode 100644 packages/taro-components-rn/__tests__/movableArea.spec.tsx delete mode 100644 packages/taro-components-rn/__tests__/scrollView.spec.tsx delete mode 100644 packages/taro-components-rn/__tests__/text.spec.tsx delete mode 100644 packages/taro-components-rn/__tests__/view.spec.tsx delete mode 100644 packages/taro-components-rn/setup.js rename packages/taro-components-rn/{ => src}/__tests__/1x1.png (100%) rename packages/taro-components-rn/{ => src}/__tests__/__snapshots__/camera.spec.tsx.snap (100%) rename packages/taro-components-rn/{ => src}/__tests__/__snapshots__/pickerView.spec.tsx.snap (74%) rename packages/taro-components-rn/{ => src}/__tests__/__snapshots__/richText.spec.tsx.snap (100%) rename packages/taro-components-rn/{ => src}/__tests__/__snapshots__/scrollView.spec.tsx.snap (85%) create mode 100644 packages/taro-components-rn/src/__tests__/__snapshots__/video.spec.tsx.snap create mode 100644 packages/taro-components-rn/src/__tests__/__snapshots__/virtualList.spec.tsx.snap create mode 100644 packages/taro-components-rn/src/__tests__/button.spec.tsx create mode 100644 packages/taro-components-rn/src/__tests__/camera.spec.tsx create mode 100644 packages/taro-components-rn/src/__tests__/checkbox.spec.tsx create mode 100644 packages/taro-components-rn/src/__tests__/icon.spec.tsx create mode 100644 packages/taro-components-rn/src/__tests__/image.spec.tsx create mode 100644 packages/taro-components-rn/src/__tests__/input.spec.tsx create mode 100644 packages/taro-components-rn/src/__tests__/movableArea.spec.tsx rename packages/taro-components-rn/{ => src}/__tests__/movableView.spec.tsx (51%) rename packages/taro-components-rn/{ => src}/__tests__/pickerView.spec.tsx (76%) rename packages/taro-components-rn/{ => src}/__tests__/richText.spec.tsx (70%) create mode 100644 packages/taro-components-rn/src/__tests__/scrollView.spec.tsx create mode 100644 packages/taro-components-rn/src/__tests__/text.spec.tsx rename packages/taro-components-rn/{ => src}/__tests__/utils.spec.tsx (97%) rename packages/taro-components-rn/{ => src}/__tests__/video.spec.tsx (69%) create mode 100644 packages/taro-components-rn/src/__tests__/view.spec.tsx rename packages/taro-components-rn/{ => src}/__tests__/virtualList.spec.tsx (52%) delete mode 100644 packages/taro-components-rn/src/components/Video/__test__/video.test.js create mode 100644 packages/taro-components-rn/src/setup.ts delete mode 100644 packages/taro-rn/src/__tests__/__snapshots__/interactive.test.js.snap create mode 100644 packages/taro-rn/src/__tests__/__snapshots__/scanCode.test.js.snap create mode 100644 packages/taro-rn/src/__tests__/scanCode.test.js delete mode 100644 packages/taro-rn/src/__tests__/scanCode.test_.js rename packages/taro-rn/{setup.js => src/setup.ts} (51%) diff --git a/package.json b/package.json index e55cd85795b2..b5deb4e4abcf 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,8 @@ "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^8.0.0", "@rollup/plugin-replace": "^2.2.0", + "@testing-library/jest-native": "^4.0.4", + "@testing-library/react-native": "^9.0.0", "@types/autoprefixer": "9.7.0", "@types/babel-types": "^7.0.7", "@types/babel__traverse": "^7.0.7", @@ -93,7 +95,6 @@ "@vue/compiler-core": "3.0.0", "@vue/runtime-core": "3.0.0", "@vue/runtime-dom": "3.0.0", - "@wojtekmaj/enzyme-adapter-react-17": "0.6.1", "babel-jest": "24.9.0", "babel-plugin-syntax-jsx": "6.18.0", "babel-preset-power-assert": "3.0.0", @@ -102,8 +103,6 @@ "copy": "^0.3.2", "cross-env": "^7.0.2", "css-loader": "^0.28.10", - "enzyme": "^3.10.0", - "enzyme-to-json": "^3.4.2", "eslint": "^6.8.0", "eslint-config-prettier": "^6.4.0", "eslint-config-standard": "^14.1.1", @@ -123,8 +122,8 @@ "html-webpack-plugin": "^3.0.6", "husky": "^1.2.0", "jest": "26.4.2", + "jest-expo": "^42.0.0", "jest-dom": "^1.3.1", - "jest-enzyme": "^7.1.1", "jest-fetch-mock": "^3.0.3", "jest-localstorage-mock": "^2.4.0", "jest-mock-console": "^1.0.0", diff --git a/packages/taro-components-rn/__mocks__/fileMock.js b/packages/taro-components-rn/__mocks__/fileMock.js deleted file mode 100644 index 0b7773f691ce..000000000000 --- a/packages/taro-components-rn/__mocks__/fileMock.js +++ /dev/null @@ -1,8 +0,0 @@ -import * as path from 'path' - -/** - * REF: https://jestjs.io/docs/en/webpack - */ -module.exports = (src, filename) => { - return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';' -} diff --git a/packages/taro-components-rn/__tests__/__snapshots__/checkbox.spec.tsx.snap b/packages/taro-components-rn/__tests__/__snapshots__/checkbox.spec.tsx.snap deleted file mode 100644 index 7a8c5bcff960..000000000000 --- a/packages/taro-components-rn/__tests__/__snapshots__/checkbox.spec.tsx.snap +++ /dev/null @@ -1,90 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` default 1`] = ` - - - - - - - - -`; diff --git a/packages/taro-components-rn/__tests__/__snapshots__/movableView.spec.tsx.snap b/packages/taro-components-rn/__tests__/__snapshots__/movableView.spec.tsx.snap deleted file mode 100644 index 6438a52f3e65..000000000000 --- a/packages/taro-components-rn/__tests__/__snapshots__/movableView.spec.tsx.snap +++ /dev/null @@ -1,33 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`MovableView MovableView render 1`] = ` - - <_Clickable - hoverStartTime={20} - hoverStayTime={70} - /> - -`; diff --git a/packages/taro-components-rn/__tests__/__snapshots__/video.spec.tsx.snap b/packages/taro-components-rn/__tests__/__snapshots__/video.spec.tsx.snap deleted file mode 100644 index 015e286e16e0..000000000000 --- a/packages/taro-components-rn/__tests__/__snapshots__/video.spec.tsx.snap +++ /dev/null @@ -1,114 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Video render Video 1`] = ` -<_Clickable - hoverStartTime={20} - hoverStayTime={70} - style={ - Array [ - Object { - "height": 225, - "lineHeight": 0, - "overflow": "hidden", - "position": "relative", - "width": "100%", - }, - undefined, - ] - } -> - <_Clickable - hoverStartTime={20} - hoverStayTime={70} - style={ - Array [ - Object { - "backgroundColor": "#000", - "bottom": 0, - "height": "100%", - "left": 0, - "overflow": "hidden", - "position": "absolute", - "right": 0, - "top": 0, - "width": "100%", - }, - false, - ] - } - > -