Skip to content

Commit d962619

Browse files
ianzoneyoyo837
andauthored
test(babel-plugin-transform-taroapi): jest to vitest (#18214)
* test(babel-plugin-transform-taroapi): jest to vitest * fix: script --------- Co-authored-by: Amumu <[email protected]>
1 parent a6bfe71 commit d962619

File tree

13 files changed

+317
-155
lines changed

13 files changed

+317
-155
lines changed

packages/babel-plugin-transform-taroapi/__tests__/__snapshots__/index.spec.ts.snap

Lines changed: 0 additions & 96 deletions
This file was deleted.

packages/babel-plugin-transform-taroapi/babel.config.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/babel-plugin-transform-taroapi/jest.config.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/babel-plugin-transform-taroapi/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
"prebuild": "pnpm run clean",
1010
"clean": "rimraf ./dist",
1111
"build": "tsc",
12-
"test": "cross-env NODE_ENV=jest jest",
13-
"test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent",
14-
"test:dev": "cross-env NODE_ENV=jest jest --watch",
15-
"test:coverage": "cross-env NODE_ENV=jest jest --coverage",
16-
"updateSnapshot": "cross-env NODE_ENV=jest jest --updateSnapshot"
12+
"test": "vitest run",
13+
"test:ci": "vitest run --coverage",
14+
"test:dev": "vitest",
15+
"updateSnapshot": "vitest run --updateSnapshot"
1716
},
1817
"engines": {
1918
"node": ">= 18"
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`babel-plugin-transform-taroapi > should canIUse support scheme with numeric attributes! 1`] = `
4+
"import { canIUse as _canUse } from '@tarojs/taro-h5';
5+
// 入参带有数字属性的对象路径
6+
true;
7+
true;"
8+
`;
9+
10+
exports[`babel-plugin-transform-taroapi > should canIUse support! 1`] = `
11+
"import { canIUse as _canUse } from '@tarojs/taro-h5';
12+
// 对象的属性或方法
13+
false;
14+
false;
15+
false;
16+
false;
17+
18+
// 接口参数、回调或者返回值
19+
true;
20+
false;
21+
false;
22+
false;
23+
false;
24+
true;
25+
26+
// 组件的属性
27+
true;
28+
true;
29+
true;"
30+
`;
31+
32+
exports[`babel-plugin-transform-taroapi > should canIUse work or skip! 1`] = `
33+
"import Taro from '@tarojs/taro-h5';
34+
function canIUse() {}
35+
false;
36+
false;
37+
canIUse('showToast.object.image');"
38+
`;
39+
40+
exports[`babel-plugin-transform-taroapi > should leave other apis untouched 1`] = `
41+
"import Taro from '@tarojs/taro-h5';
42+
Taro.noop;"
43+
`;
44+
45+
exports[`babel-plugin-transform-taroapi > should move static apis under "Taro" 1`] = `
46+
"import Taro from '@tarojs/taro-h5';
47+
Taro.noop;
48+
Taro.noop();"
49+
`;
50+
51+
exports[`babel-plugin-transform-taroapi > should not go wrong when using an api twice 1`] = `
52+
"import Taro, { createAnimation as _createAnimation } from '@tarojs/taro-h5';
53+
const animation = _createAnimation({
54+
duration: dura * 1000,
55+
timingFunction: 'linear'
56+
});
57+
const resetAnimation = _createAnimation({
58+
duration: 0,
59+
timingFunction: 'linear'
60+
});"
61+
`;
62+
63+
exports[`babel-plugin-transform-taroapi > should not import taro duplicity 1`] = `
64+
"import Taro, { createAnimation as _createAnimation, initPxTransform as _initPxTransform } from '@tarojs/taro-h5';
65+
Taro.Component;
66+
_createAnimation();
67+
_initPxTransform();"
68+
`;
69+
70+
exports[`babel-plugin-transform-taroapi > should preserve assignments in left hands 1`] = `
71+
"import Taro, { createAnimation as _createAnimation, request as _request } from '@tarojs/taro-h5';
72+
let animation;
73+
animation = _createAnimation({
74+
transformOrigin: "50% 50%",
75+
duration: 1000,
76+
timingFunction: "ease",
77+
delay: 0
78+
});
79+
_request();
80+
Taro.request = '';
81+
Taro['request'] = '';"
82+
`;
83+
84+
exports[`babel-plugin-transform-taroapi > should preserve default imports 1`] = `
85+
"import Taro from '@tarojs/taro-h5';
86+
console.log(Taro);"
87+
`;
88+
89+
exports[`babel-plugin-transform-taroapi > should support rename of imported names 1`] = `
90+
"// import { inject as mobxInject, observer as mobxObserver } from '@tarojs/mobx'
91+
import Taro from '@tarojs/taro-h5';
92+
export class Connected extends Taro.Component {}"
93+
`;
94+
95+
exports[`babel-plugin-transform-taroapi > should work! 1`] = `
96+
"import Taro, { setStorage as _setStorage, initPxTransform as _initPxTransform, getStorage as _getStorage } from '@tarojs/taro-h5';
97+
_initPxTransform(Taro.param);
98+
_initPxTransform();
99+
_initPxTransform();
100+
_getStorage();
101+
_setStorage();
102+
export { Taro };"
103+
`;
104+
105+
exports[`babel-plugin-transform-taroapi should canIUse support scheme with numeric attributes! 1`] = `
106+
"import { canIUse as _canUse } from '@tarojs/taro-h5';
107+
// 入参带有数字属性的对象路径
108+
true;
109+
true;"
110+
`;
111+
112+
exports[`babel-plugin-transform-taroapi should canIUse support! 1`] = `
113+
"import { canIUse as _canUse } from '@tarojs/taro-h5';
114+
// 对象的属性或方法
115+
false;
116+
false;
117+
false;
118+
false;
119+
120+
// 接口参数、回调或者返回值
121+
true;
122+
false;
123+
false;
124+
false;
125+
false;
126+
true;
127+
128+
// 组件的属性
129+
true;
130+
true;
131+
true;"
132+
`;
133+
134+
exports[`babel-plugin-transform-taroapi should canIUse work or skip! 1`] = `
135+
"import Taro from '@tarojs/taro-h5';
136+
function canIUse() {}
137+
false;
138+
false;
139+
canIUse('showToast.object.image');"
140+
`;
141+
142+
exports[`babel-plugin-transform-taroapi should leave other apis untouched 1`] = `
143+
"import Taro from '@tarojs/taro-h5';
144+
Taro.noop;"
145+
`;
146+
147+
exports[`babel-plugin-transform-taroapi should move static apis under "Taro" 1`] = `
148+
"import Taro from '@tarojs/taro-h5';
149+
Taro.noop;
150+
Taro.noop();"
151+
`;
152+
153+
exports[`babel-plugin-transform-taroapi should not go wrong when using an api twice 1`] = `
154+
"import Taro, { createAnimation as _createAnimation } from '@tarojs/taro-h5';
155+
const animation = _createAnimation({
156+
duration: dura * 1000,
157+
timingFunction: 'linear'
158+
});
159+
const resetAnimation = _createAnimation({
160+
duration: 0,
161+
timingFunction: 'linear'
162+
});"
163+
`;
164+
165+
exports[`babel-plugin-transform-taroapi should not import taro duplicity 1`] = `
166+
"import Taro, { createAnimation as _createAnimation, initPxTransform as _initPxTransform } from '@tarojs/taro-h5';
167+
Taro.Component;
168+
_createAnimation();
169+
_initPxTransform();"
170+
`;
171+
172+
exports[`babel-plugin-transform-taroapi should preserve assignments in left hands 1`] = `
173+
"import Taro, { createAnimation as _createAnimation, request as _request } from '@tarojs/taro-h5';
174+
let animation;
175+
animation = _createAnimation({
176+
transformOrigin: "50% 50%",
177+
duration: 1000,
178+
timingFunction: "ease",
179+
delay: 0
180+
});
181+
_request();
182+
Taro.request = '';
183+
Taro['request'] = '';"
184+
`;
185+
186+
exports[`babel-plugin-transform-taroapi should preserve default imports 1`] = `
187+
"import Taro from '@tarojs/taro-h5';
188+
console.log(Taro);"
189+
`;
190+
191+
exports[`babel-plugin-transform-taroapi should support rename of imported names 1`] = `
192+
"// import { inject as mobxInject, observer as mobxObserver } from '@tarojs/mobx'
193+
import Taro from '@tarojs/taro-h5';
194+
export class Connected extends Taro.Component {}"
195+
`;
196+
197+
exports[`babel-plugin-transform-taroapi should work! 1`] = `
198+
"import Taro, { setStorage as _setStorage, initPxTransform as _initPxTransform, getStorage as _getStorage } from '@tarojs/taro-h5';
199+
_initPxTransform(Taro.param);
200+
_initPxTransform();
201+
_initPxTransform();
202+
_getStorage();
203+
_setStorage();
204+
export { Taro };"
205+
`;

0 commit comments

Comments
 (0)