Skip to content

Commit 23a8277

Browse files
committed
test: add e2e test
1 parent f5523cd commit 23a8277

14 files changed

Lines changed: 10501 additions & 347 deletions

babel.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// babel-preset-taro 更多选项和默认值:
2+
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
3+
module.exports = {
4+
presets: [
5+
[
6+
'taro',
7+
{
8+
framework: 'react',
9+
ts: true,
10+
},
11+
],
12+
],
13+
}

babel.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const path = require('path')
2+
const pkg = require('./package.json')
3+
4+
module.exports = [
5+
'import',
6+
{
7+
libraryName: pkg.name,
8+
customName: path.resolve(__dirname, './customName.js'),
9+
},
10+
]

config/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import WebpackChain from 'webpack-chain'
2+
import { IProjectConfig } from '@tarojs/taro/types/compile'
3+
import { TaroProvidePlugin } from '@tarojsx/polyfill/dist/plugins'
4+
5+
const config: IProjectConfig = {
6+
projectName: 'test',
7+
date: '2020-2-22',
8+
designWidth: 750,
9+
deviceRatio: { 750: 1 },
10+
sourceRoot: 'test/src',
11+
outputRoot: 'test/dist',
12+
framework: 'react',
13+
mini: {
14+
webpackChain(chain: WebpackChain) {
15+
chain.plugin('taroProvidePlugin').use(TaroProvidePlugin)
16+
},
17+
},
18+
}
19+
20+
export default function (merge) {
21+
if (process.env.NODE_ENV === 'development') {
22+
return merge({}, config, { env: { NODE_ENV: '"development"' } })
23+
}
24+
return merge({}, config, { env: { NODE_ENV: '"production"' } })
25+
}

customName.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path')
2+
const fs = require('fs')
3+
const glob = require('glob')
4+
const pkg = require('./package.json')
5+
6+
const prefix = path.join(pkg.name, 'dist')
7+
8+
const files = glob.sync('**/*.js', { cwd: path.join(__dirname, 'dist') })
9+
10+
console.log(files)
11+
12+
module.exports = function customName(name) {
13+
return `antd/lib/${name}`
14+
}

package.json

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,19 @@
3939
"start": "tsc -w --preserveWatchOutput",
4040
"prebuild": "rimraf dist tsconfig.tsbuildinfo",
4141
"build": "tsc",
42+
"pretest": "npm run build && taro build --type weapp",
43+
"test": "jest",
44+
"test:watch": "jest --watch",
4245
"prepublishOnly": "npm run build",
4346
"release": "np"
4447
},
4548
"dependencies": {
49+
"@antv/f2": "^3.7.0",
50+
"@tarojsx/polyfill": "^0.16.0",
4651
"@types/react-window": "^1.8.2",
4752
"@types/react-window-infinite-loader": "^1.0.3",
53+
"async-retry": "^1.3.1",
54+
"fast-deep-equal": "^3.1.3",
4855
"react-spring": "^9.0.0-rc.3",
4956
"react-use-gesture": "^7.0.15",
5057
"react-vtree": "^1.0.2",
@@ -53,16 +60,38 @@
5360
"tslib": "^2.0.0"
5461
},
5562
"devDependencies": {
56-
"@commitlint/cli": "^8.3.5",
57-
"@commitlint/config-conventional": "^8.3.4",
58-
"@tarojs/components": "^3.0.0-rc.0",
59-
"@tarojs/taro": "^3.0.0-rc.0",
60-
"@types/react": "^16.9.35",
61-
"np": "^6.2.3",
63+
"@babel/preset-typescript": "^7.10.4",
64+
"@minapp/wx": "^2.2.1",
65+
"@commitlint/cli": "^9.0.1",
66+
"@commitlint/config-conventional": "^9.0.1",
67+
"@tarojs/mini-runner": "^3.0.2",
68+
"@tarojs/react": "^3.0.2",
69+
"@tarojs/runtime": "^3.0.2",
70+
"@tarojs/components": "^3.0.2",
71+
"@tarojs/taro": "^3.0.2",
72+
"@tarojs/webpack-runner": "^3.0.2",
73+
"@types/async-retry": "^1.4.2",
74+
"@types/classnames": "^2.2.10",
75+
"@types/jest": "^26.0.3",
76+
"@types/react": "^16.9.41",
77+
"babel-preset-taro": "^3.0.0-rc.6",
78+
"jest": "^26.1.0",
79+
"miniprogram-automator": "^0.9.1",
80+
"np": "^6.3.1",
81+
"react": "^16.13.1",
6282
"react-calendar": "^3.1.0",
6383
"rimraf": "^3.0.2",
6484
"taro-ui": "^2.3.4",
65-
"typescript": "^3.9.3"
85+
"typescript": "^3.9.6",
86+
"webpack": "^4.43.0",
87+
"webpack-chain": "^6.4.0"
88+
},
89+
"jest": {
90+
"testRegex": "/test/.*\\.test\\.[t]sx?$",
91+
"watchPathIgnorePatterns": [
92+
".+\\.js(on)$",
93+
"/config|dist|src/"
94+
]
6695
},
6796
"husky": {
6897
"hooks": {

project.config.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"miniprogramRoot": "test/dist/",
3+
"projectname": "tarojsx-library-test",
4+
"appid": "touristappid",
5+
"compileType": "miniprogram",
6+
"simulatorType": "wechat",
7+
"simulatorPluginLibVersion": {},
8+
"setting": {
9+
"urlCheck": false,
10+
"es6": false,
11+
"enhance": false,
12+
"postcss": false,
13+
"preloadBackgroundData": false,
14+
"minified": false,
15+
"newFeature": true,
16+
"coverView": true,
17+
"nodeModules": false,
18+
"autoAudits": false,
19+
"showShadowRootInWxmlPanel": true,
20+
"scopeDataCheck": false,
21+
"uglifyFileName": false,
22+
"checkInvalidKey": true,
23+
"checkSiteMap": false,
24+
"uploadWithSourceMap": true,
25+
"compileHotReLoad": false,
26+
"babelSetting": {
27+
"ignore": [],
28+
"disablePlugins": [],
29+
"outputPath": ""
30+
},
31+
"useIsolateContext": true,
32+
"useCompilerModule": false,
33+
"userConfirmedUseCompilerModuleSwitch": false
34+
},
35+
"condition": {
36+
"search": {
37+
"current": -1,
38+
"list": []
39+
},
40+
"conversation": {
41+
"current": -1,
42+
"list": []
43+
},
44+
"plugin": {
45+
"current": -1,
46+
"list": []
47+
},
48+
"game": {
49+
"current": -1,
50+
"list": []
51+
},
52+
"gamePlugin": {
53+
"current": -1,
54+
"list": []
55+
},
56+
"miniprogram": {
57+
"current": -1,
58+
"list": [
59+
{
60+
"id": -1,
61+
"name": "AntV F2",
62+
"pathName": "pages/antv-f2",
63+
"scene": null
64+
},
65+
{
66+
"id": 0,
67+
"name": "React Spring",
68+
"pathName": "pages/react-spring",
69+
"scene": null
70+
},
71+
{
72+
"id": 0,
73+
"name": "React Use Gesture",
74+
"pathName": "pages/react-use-gesture",
75+
"scene": null
76+
}
77+
]
78+
}
79+
}
80+
}

test/src/app.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { AppConfig } from '@tarojs/taro'
2+
3+
export default {
4+
pages: ['pages/index', 'pages/antv-f2', 'pages/react-spring', 'pages/react-use-gesture'],
5+
} as AppConfig

test/src/app.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react'
2+
3+
export default class App extends React.Component {
4+
render() {
5+
return this.props.children
6+
}
7+
}

test/src/pages/antv-f2.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React, { useState, useEffect } from 'react'
2+
import { View } from '@tarojs/components'
3+
import { F2 } from '../../../src/antv'
4+
5+
const f2style: React.CSSProperties = { width: '100vw', height: '50vh' }
6+
7+
export default () => {
8+
const [data1, setData1] = useState([
9+
{ genre: 'Sports', sold: 275 },
10+
{ genre: 'Strategy', sold: 115 },
11+
{ genre: 'Action', sold: 120 },
12+
{ genre: 'Shooter', sold: 350 },
13+
{ genre: 'Other', sold: 150 },
14+
])
15+
const [data2, setData2] = useState([
16+
{ year: '2001', population: 41.8 },
17+
{ year: '2002', population: 25.8 },
18+
{ year: '2003', population: 31.7 },
19+
{ year: '2004', population: 46 },
20+
{ year: '2005', population: 28 },
21+
])
22+
23+
useEffect(() => {
24+
const timer = setInterval(() => {
25+
setData1((prev) => prev.map(({ genre }) => ({ genre, sold: Math.round(Math.random() * 100) })))
26+
setData2((prev) => prev.map(({ year }) => ({ year, population: Math.round(Math.random() * 10) })))
27+
}, 2000)
28+
29+
return () => clearInterval(timer)
30+
}, [])
31+
32+
return (
33+
<View style={{ display: 'flex', flexWrap: 'wrap' }}>
34+
<F2
35+
style={f2style}
36+
// F2 对数据源格式的要求,仅仅是 JSON 数组,数组的每个元素是一个标准 JSON 对象。
37+
data={data1}
38+
>
39+
{
40+
// Step 1: 接收 Chart 对象
41+
({ chart, data }) => {
42+
// Step 2: 载入数据源
43+
chart.source(data)
44+
45+
// Step 3:创建图形语法,绘制柱状图,由 genre 和 sold 两个属性决定图形位置,genre 映射至 x 轴,sold 映射至 y 轴
46+
chart.interval().position('genre*sold').color('genre')
47+
48+
// Step 4: 渲染图表
49+
chart.render()
50+
}
51+
}
52+
</F2>
53+
54+
<F2
55+
style={f2style}
56+
data={data2}
57+
>
58+
{({ chart, data }) => {
59+
chart.source(data)
60+
chart.coord('polar')
61+
chart.legend({
62+
position: 'right',
63+
})
64+
chart.axis(false)
65+
chart.interval().position('year*population').color('year').style({
66+
lineWidth: 1,
67+
stroke: '#fff',
68+
})
69+
chart.render()
70+
}}
71+
</F2>
72+
</View>
73+
)
74+
}

test/src/pages/index.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react'
2+
import Taro from '@tarojs/taro'
3+
import { View, Button } from '@tarojs/components'
4+
5+
const btnStyle: React.CSSProperties = { margin: 30 }
6+
7+
export default () => (
8+
<View>
9+
<Button style={btnStyle} onClick={() => Taro.navigateTo({ url: '/pages/antv-f2' })}>
10+
AntV F2
11+
</Button>
12+
<Button style={btnStyle} onClick={() => Taro.navigateTo({ url: '/pages/react-spring' })}>
13+
React Spring
14+
</Button>
15+
<Button style={btnStyle} onClick={() => Taro.navigateTo({ url: '/pages/react-use-gesture' })}>
16+
React Use Gesture
17+
</Button>
18+
</View>
19+
)

0 commit comments

Comments
 (0)