-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(taro-babel): babel-plugin-transform-taroapi 添加测试用例 (#13603)
* test(babel): taro babel 插件添加单元测试 * test(babel): taro babel 插件添加单元测试 * test(snapshot): 更新快照 * test(snapshot): 更新快照 * test(babel): 删除单元测试无用代码 * test(babel): 删除单元测试无用代码 * chore(advacne): 补充缺失依赖 --------- Co-authored-by: xuanzebin <xuanzebin3@jd.com>
- Loading branch information
Showing
9 changed files
with
205 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/babel-plugin-transform-taroapi/__tests__/__snapshots__/index.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should leave other apis untouched 1`] = ` | ||
"import Taro from '@tarojs/taro-h5'; | ||
Taro.noop;" | ||
`; | ||
|
||
exports[`should move static apis under "Taro" 1`] = ` | ||
"import Taro from '@tarojs/taro-h5'; | ||
Taro.noop; | ||
Taro.noop();" | ||
`; | ||
|
||
exports[`should not go wrong when using an api twice 1`] = ` | ||
"import Taro, { createAnimation as _createAnimation } from '@tarojs/taro-h5'; | ||
const animation = _createAnimation({ | ||
duration: dura * 1000, | ||
timingFunction: 'linear' | ||
}); | ||
const resetAnimation = _createAnimation({ | ||
duration: 0, | ||
timingFunction: 'linear' | ||
});" | ||
`; | ||
|
||
exports[`should not import taro duplicatly 1`] = ` | ||
"import Taro, { createAnimation as _createAnimation, initPxTransform as _initPxTransform } from "@tarojs/taro-h5"; | ||
Taro.Component; | ||
_createAnimation(); | ||
_initPxTransform();" | ||
`; | ||
|
||
exports[`should preserve assignments in lefthands 1`] = ` | ||
"import Taro, { createAnimation as _createAnimation, request as _request } from '@tarojs/taro-h5'; | ||
let animation; | ||
animation = _createAnimation({ | ||
transformOrigin: "50% 50%", | ||
duration: 1000, | ||
timingFunction: "ease", | ||
delay: 0 | ||
}); | ||
_request(); | ||
Taro.request = ''; | ||
Taro['request'] = '';" | ||
`; | ||
|
||
exports[`should preserve default imports 1`] = ` | ||
"import Taro from '@tarojs/taro-h5'; | ||
console.log(Taro);" | ||
`; | ||
|
||
exports[`should support rename of imported names 1`] = ` | ||
"// import { inject as mobxInject, observer as mobxObserver } from '@tarojs/mobx' | ||
import Taro from "@tarojs/taro-h5"; | ||
export class Connected extends Taro.Component {}" | ||
`; | ||
|
||
exports[`should work! 1`] = ` | ||
"import Taro, { setStorage as _setStorage, initPxTransform as _initPxTransform, getStorage as _getStorage } from '@tarojs/taro-h5'; | ||
_initPxTransform(Taro.param); | ||
_initPxTransform(); | ||
_initPxTransform(); | ||
_getStorage(); | ||
_setStorage(); | ||
export { Taro };" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"ios": "9", | ||
"android": "4.4" | ||
} | ||
} | ||
] | ||
], | ||
"plugins": ["@babel/plugin-transform-react-jsx"], | ||
"env": { | ||
"test": { | ||
"plugins": ["@babel/plugin-transform-runtime"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
collectCoverage: false, | ||
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'], | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/__tests__/**/?(*.)+(spec|test).[jt]s?(x)'], | ||
testPathIgnorePatterns: [ | ||
'node_modules', | ||
], | ||
transform: { | ||
'^.+\\.jsx?$': 'babel-jest', | ||
'^.+\\.tsx?$': ['ts-jest', { | ||
diagnostics: false, | ||
tsconfig: { | ||
allowJs: true | ||
} | ||
}], | ||
}, | ||
transformIgnorePatterns: ['<rootDir>/node_modules/'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.root.json", | ||
"compilerOptions": { | ||
"allowJs": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.