Skip to content

Commit 8daedbf

Browse files
authored
feat: 添加单测的 utils 工具包 (#162)
1 parent 7e0d887 commit 8daedbf

File tree

13 files changed

+253
-162
lines changed

13 files changed

+253
-162
lines changed

.fatherrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ export default {
99
lessInBabelMode: true,
1010
cssModules: true,
1111
extraBabelPlugins: ['@babel/plugin-proposal-class-static-block'],
12-
pkgs: ['f-engine', 'f-lottie', 'f-react', 'f-my', 'f-vue', 'f-wx'],
12+
pkgs: ['f-engine', 'f-lottie', 'f-react', 'f-my', 'f-vue', 'f-wx', 'f-test-utils'],
1313
};

packages/f-engine/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"eventemitter3": "^4.0.0",
2020
"tslib": "^2.3.1"
2121
},
22+
"devDependencies": {
23+
"@antv/f-test-utils": "~0.0.1"
24+
},
2225
"homepage": "https://github.com/antvis/FEngine",
2326
"author": "https://github.com/orgs/antvis/people",
2427
"repository": {

packages/f-engine/test/util.ts

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1 @@
1-
function delay(time) {
2-
const half = Math.round(time / 2);
3-
return new Promise((resolve) => {
4-
// 用 2 个 setTimeout 是为了提升 ci 的成功率
5-
setTimeout(() => {
6-
setTimeout(resolve, half);
7-
}, half);
8-
});
9-
}
10-
11-
const createContext = (title = '', { width = '300px', height = '225px' } = {}) => {
12-
const container = document.createElement('div');
13-
const canvasEl = document.createElement('canvas');
14-
const titleEl = document.createElement('p');
15-
16-
container.id = 'container';
17-
18-
titleEl.innerText = title + ':';
19-
titleEl.style.fontSize = '12px';
20-
21-
canvasEl.style.display = 'block';
22-
canvasEl.style.width = width;
23-
canvasEl.style.height = height;
24-
25-
container.appendChild(titleEl);
26-
container.appendChild(canvasEl);
27-
document.body.appendChild(container);
28-
const context = canvasEl.getContext('2d');
29-
return context;
30-
};
31-
32-
const dispatchEvent = (dom: HTMLElement, eventType: string, exData) => {
33-
let event = new Event(eventType, { bubbles: true, cancelable: true });
34-
event = Object.assign(event, exData);
35-
dom.dispatchEvent(event);
36-
};
37-
38-
const gestureSimulator = async (dom, eventType: string, option: { x: number; y: number }) => {
39-
const { top, left } = dom.getBoundingClientRect();
40-
const { x, y } = option;
41-
const clientX = left + x;
42-
const clientY = top + y;
43-
const event = {
44-
x,
45-
y,
46-
clientX,
47-
clientY,
48-
};
49-
50-
const touchEvent = {
51-
...event,
52-
targetTouches: [event],
53-
touches: [event],
54-
changedTouches: [event],
55-
};
56-
57-
if (['touchstart', 'touchmove', 'touchend'].indexOf(eventType) !== -1) {
58-
dispatchEvent(dom, eventType, touchEvent);
59-
return;
60-
}
61-
62-
if (eventType === 'press') {
63-
dispatchEvent(dom, 'touchstart', touchEvent);
64-
await delay(270);
65-
dispatchEvent(dom, 'touchend', touchEvent);
66-
return;
67-
}
68-
69-
if (eventType === 'tap') {
70-
dispatchEvent(dom, 'touchstart', touchEvent);
71-
await delay(50);
72-
dispatchEvent(dom, 'touchend', touchEvent);
73-
return;
74-
}
75-
76-
if (eventType === 'click') {
77-
dispatchEvent(dom, 'click', event);
78-
return;
79-
}
80-
};
81-
82-
export { createContext, delay, dispatchEvent, gestureSimulator };
1+
export * from '@antv/f-test-utils';

packages/f-lottie/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"@babel/runtime": "^7.12.5",
2121
"tslib": "^2.3.1"
2222
},
23+
"devDependencies": {
24+
"@antv/f-test-utils": "~0.0.1"
25+
},
2326
"homepage": "https://f2.antv.vision",
2427
"author": "https://github.com/orgs/antvis/people",
2528
"license": "MIT",

packages/f-lottie/test/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { jsx, Canvas } from '@antv/f-engine';
22
import Lottie from '../src/index';
33
import data from './data/data.json';
4-
import { createContext, delay } from './util';
4+
import { createContext, delay } from '@antv/f-test-utils';
55

66
describe('Lottie', () => {
77
it('加载 lottie 文件', async () => {

packages/f-lottie/test/util.ts

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

packages/f-test-utils/.npmignore

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# lock
9+
package-lock.json
10+
11+
# Runtime data
12+
pids
13+
*.pid
14+
*.seed
15+
*.pid.lock
16+
17+
# Directory for instrumented libs generated by jscoverage/JSCover
18+
lib-cov
19+
20+
# Coverage directory used by tools like istanbul
21+
coverage
22+
23+
# nyc test coverage
24+
.nyc_output
25+
26+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
27+
.grunt
28+
29+
# Bower dependency directory (https://bower.io/)
30+
bower_components
31+
32+
# node-waf configuration
33+
.lock-wscript
34+
35+
# Compiled binary addons (http://nodejs.org/api/addons.html)
36+
build/Release
37+
38+
# Dependency directories
39+
node_modules/
40+
jspm_packages/
41+
42+
# Typescript v1 declaration files
43+
typings/
44+
45+
# Optional npm cache directory
46+
.npm
47+
48+
# Optional eslint cache
49+
.eslintcache
50+
51+
# Optional REPL history
52+
.node_repl_history
53+
54+
# Output of 'npm pack'
55+
*.tgz
56+
57+
# Yarn Integrity file
58+
.yarn-integrity
59+
60+
# dotenv environment variables file
61+
.env
62+
63+
.DS_Store
64+
65+
# npmignore - content above this line is automatically generated and modifications may be omitted
66+
# see npmjs.com/npmignore for more details.
67+
test
68+
69+
*.sw*
70+
*.un~
71+
.idea
72+
bin
73+
demos
74+
docs
75+
temp
76+
webpack-dev.config.js
77+
webpack.config.js
78+
examples
79+
site
80+
gatsby-browser.js
81+
gatsby-config.js
82+
.cache
83+
public

packages/f-test-utils/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT LICENSE
2+
3+
Copyright (c) 2015-present Alipay.com, https://www.alipay.com/
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

packages/f-test-utils/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
F 系列单测的 util 方法

packages/f-test-utils/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@antv/f-test-utils",
3+
"version": "0.0.1",
4+
"description": "FEngine for Test",
5+
"main": "lib/index.js",
6+
"module": "es/index.js",
7+
"types": "es/index.d.ts",
8+
"keywords": [
9+
"antv",
10+
"f2",
11+
"chart",
12+
"charts",
13+
"mobile",
14+
"visualization",
15+
"lottie"
16+
],
17+
"dependencies": {
18+
"@babel/runtime": "^7.12.5",
19+
"tslib": "^2.3.1"
20+
},
21+
"homepage": "https://f2.antv.vision",
22+
"author": "https://github.com/orgs/antvis/people",
23+
"license": "MIT",
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/antvis/f2"
27+
},
28+
"bugs": {
29+
"url": "https://github.com/antvis/f2/issues"
30+
}
31+
}

0 commit comments

Comments
 (0)