Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit test framework #123

Merged
merged 34 commits into from May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
315aa63
add swan's filter transform rule
sky-admin May 13, 2019
683ea81
update
sky-admin May 13, 2019
f85455f
unsupported of toutiao
xuehebinglan May 13, 2019
f487306
Merge branch 'cross-transform' of https://github.com/didi/mpx into cr…
xuehebinglan May 13, 2019
3563b91
change the showing name of btyedance
xuehebinglan May 13, 2019
e4cccff
<scroll-view> of bytedance
xuehebinglan May 13, 2019
b601ea9
<swiper> of bytedance
xuehebinglan May 13, 2019
7546a12
<progress> for bytedance
xuehebinglan May 13, 2019
1a600ac
<rich-text> for bytedance
xuehebinglan May 13, 2019
6815077
<button> for bytedance
xuehebinglan May 13, 2019
9f57e4d
微信小程序新出了'editor'组件,都不支持
xuehebinglan May 13, 2019
f02abaf
<form> for bytedance
xuehebinglan May 13, 2019
4a1bd00
<input> for bytedance
xuehebinglan May 13, 2019
91db27b
<picker-view> for bytedance
xuehebinglan May 13, 2019
75ead8e
<slider> for bytedance
xuehebinglan May 13, 2019
7b9d534
<switch> for bytedance
xuehebinglan May 13, 2019
3932443
<textarea> for bytedance
xuehebinglan May 13, 2019
71a5fe9
unsupported 'functional-page-navigator' for bytedance
xuehebinglan May 13, 2019
a8f61a1
<navigator> for bytedance
xuehebinglan May 13, 2019
a08c5ae
unsupported components for bytedance
xuehebinglan May 13, 2019
e4bf018
Unified the Variable name
xuehebinglan May 13, 2019
3965771
unsupported 'show-menu-by-longpress' for <image> for ali && baidu && …
xuehebinglan May 13, 2019
31cbd99
<video> for bytedance
xuehebinglan May 13, 2019
0cb9d32
unsupported 'show-menu-by-longpress' for <image> for qq
xuehebinglan May 13, 2019
9b34557
npm run fix
xuehebinglan May 13, 2019
06e0839
Merge commit '3d04c5f7e2f2c52774f9bfe38bcc7198c588e5ed' into cross-tr…
sky-admin May 14, 2019
256b65a
add jest as unit framework
sky-admin May 14, 2019
54a90ef
fix bug for wxs in ali, add unit case
sky-admin May 14, 2019
acb215f
add npm script to launch unit test and add it to travis config
sky-admin May 14, 2019
6f20ab8
rename a manual test file to avoid jest run it as a unit case
sky-admin May 14, 2019
831c95e
fix lint
sky-admin May 14, 2019
5c414c3
fix travis config
sky-admin May 14, 2019
929fb46
fix travis config again
sky-admin May 14, 2019
2812c7a
Merge branch 'dev' into unit
sky-admin May 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions .eslintrc.js
Expand Up @@ -6,7 +6,8 @@ module.exports = {
},
extends: 'standard',
plugins: [
'html'
'html',
'jest'
],
'globals': {
'wx': false,
Expand All @@ -22,6 +23,9 @@ module.exports = {
},
rules: {
'no-cond-assign': 0,
"camelcase": ['error', {'allow': ['__mpx_mode__', '__swan_exports_map__']}]
'camelcase': ['error', {'allow': ['__mpx_mode__', '__swan_exports_map__']}]
},
env: {
'jest/globals': true
}
}
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -3,9 +3,10 @@ node_js:
- 11.3.0
install:
- npm i
- lerna bootstrap --ignore-prepublish
- lerna bootstrap --ignore-prepublish --no-ci
script:
- npm run lint
- npm t
before_deploy:
- cd docs
- npx gitbook-cli install
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -4,7 +4,8 @@
"scripts": {
"lerna:publish": "lerna publish from-package --yes",
"lint": "eslint --ext .js packages/",
"fix": "eslint --fix --ext .js packages/"
"fix": "eslint --fix --ext .js packages/",
"test": "jest"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
Expand All @@ -14,11 +15,13 @@
"eslint-friendly-formatter": "^4.0.1",
"eslint-plugin-html": "^5.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^22.5.1",
"eslint-plugin-local-rules": "^0.1.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^2.6.2",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"jest": "^24.8.0",
"lerna": "^3.4.3"
}
}
2 changes: 1 addition & 1 deletion packages/core/src/helper/utils.js
Expand Up @@ -33,7 +33,7 @@ export function aliasReplace (options = {}, alias, target) {

export function findItem (arr = [], key) {
for (const item of arr) {
if (type(key) === 'RegExp' && key.test(item) || item === key) {
if ((type(key) === 'RegExp' && key.test(item)) || item === key) {
return true
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/platform/patch/wx/getDefaultOptions.js
Expand Up @@ -53,6 +53,7 @@ function transformApiForProxy (context, currentInject) {
// mounted 之后才监听updated
callback = (...rest) => {
this.$mpxProxy.updated()
// eslint-disable-next-line standard/no-callback-literal
typeof cb === 'function' && cb(...rest)
}
}
Expand Down
Expand Up @@ -10,6 +10,9 @@ module.exports = function ({ print }) {
const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false })
const qqEventLog = print({ platform: 'qq', tag: TAG_NAME, isError: false, type: 'event' })
const qqValueLogError = print({ platform: 'qq', tag: TAG_NAME, isError: true, type: 'value' })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })
const ttValueLogError = print({ platform: 'bytedance', tag: TAG_NAME, isError: true, type: 'value' })
const ttEventLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false, type: 'event' })

return {
test: TAG_NAME,
Expand Down Expand Up @@ -45,6 +48,12 @@ module.exports = function ({ print }) {
if (supportList.indexOf(value) === -1) {
qqValueLogError({ name, value })
}
},
tt ({ name, value }) {
let supportList = ['share']
if (supportList.indexOf(value) === -1) {
ttValueLogError({ name, value })
}
}
},
{
Expand All @@ -59,6 +68,10 @@ module.exports = function ({ print }) {
{
test: /^(session-from|send-message-title|send-message-path|send-message-img|show-message-card)$/,
qq: qqPropLog
},
{
test: /^(plain|lang|session-from|send-message-title|send-message-path|send-message-img|app-parameter|show-message-card)$/,
tt: ttPropLog
}
],
event: [
Expand All @@ -79,6 +92,10 @@ module.exports = function ({ print }) {
{
test: /^(contact)$/,
qq: qqEventLog
},
{
test: /^(getuserinfo|contact|getphonenumbe|error|launchapp|opensetting)$/,
tt: ttEventLog
}
]
}
Expand Down
Expand Up @@ -2,6 +2,7 @@ const TAG_NAME = 'canvas'

module.exports = function ({ print }) {
const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })
return {
test: TAG_NAME,
props: [
Expand All @@ -13,6 +14,10 @@ module.exports = function ({ print }) {
value
}
}
},
{
test: 'disable-scroll',
tt: ttPropLog
}
],
// 组件事件中的差异部分
Expand Down
Expand Up @@ -4,6 +4,7 @@ module.exports = function ({ print }) {
const aliPropLog = print({ platform: 'ali', tag: TAG_NAME, isError: false })
const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })

return {
test: TAG_NAME,
Expand All @@ -13,6 +14,10 @@ module.exports = function ({ print }) {
ali: aliPropLog,
swan: baiduPropLog,
qq: qqPropLog
},
{
test: /^(report-submit|report-submit-timeout)$/,
tt: ttPropLog
}
],
event: [
Expand Down
@@ -1,8 +1,22 @@
const TAG_NAME = 'image'

module.exports = function ({ print }) {
const aliPropLog = print({ platform: 'ali', tag: TAG_NAME, isError: false })
const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })

return {
test: TAG_NAME,
props: [
{
test: /^show-menu-by-longpress$/,
ali: aliPropLog,
swan: baiduPropLog,
qq: qqPropLog,
tt: ttPropLog
}
],
event: [
{
test: /^(error|load)$/,
Expand Down
Expand Up @@ -46,6 +46,11 @@ module.exports = function getComponentConfigs ({ warn, error }) {
case 'value':
msg = `<${tag}>'s property '${arg && arg.name}' does not support '[${arg && arg.value}]' value in ${platform} environment!`
break
case 'tagRequiredProps':
msg = `<${tag}> should have '${arg}' attr in ali environment!`
break
default:
msg = `<${tag}>'s transform has some error happened!`
}
isError ? error(msg) : warn(msg)
}
Expand Down Expand Up @@ -76,6 +81,6 @@ module.exports = function getComponentConfigs ({ warn, error }) {
image({ print }),
map({ print }),
canvas({ print }),
wxs()
wxs({ print })
]
}
Expand Up @@ -4,6 +4,7 @@ module.exports = function ({ print }) {
const aliPropLog = print({ platform: 'ali', tag: TAG_NAME, isError: false })
const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' })
const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })

return {
test: TAG_NAME,
Expand All @@ -15,6 +16,10 @@ module.exports = function ({ print }) {
{
test: /^(auto-focus)$/,
swan: baiduPropLog
},
{
test: /^(placeholder-class|auto-focus|confirm-type|confirm-hold|adjust-position)$/,
tt: ttPropLog
}
],
event: [
Expand Down
Expand Up @@ -5,6 +5,8 @@ module.exports = function ({ print }) {
const aliPropLog = print({ platform: 'ali', tag: TAG_NAME, isError: false })
const aliPropLogError = print({ platform: 'ali', tag: TAG_NAME, isError: true })
const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })
const ttEventLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false, type: 'event' })

return {
test: TAG_NAME,
Expand All @@ -25,12 +27,17 @@ module.exports = function ({ print }) {
{
test: /^(hover-stop-propagation)$/,
ali: aliPropLog
},
{
test: /^(target|app-id|path|extra-data|version)$/,
tt: ttPropLog
}
],
event: [
{
test: /^(success|fail|complete)$/,
ali: aliEventLog
ali: aliEventLog,
tt: ttEventLog
}
]
}
Expand Down
Expand Up @@ -3,9 +3,17 @@ const TAG_NAME = 'picker-view'
module.exports = function ({ print }) {
const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' })
const baiduEventLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })
const ttEventLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false, type: 'event' })

return {
test: TAG_NAME,
props: [
{
test: /^(indicator-class|mask-class)$/,
tt: ttPropLog
}
],
event: [
{
test: /^(change)$/,
Expand All @@ -19,7 +27,8 @@ module.exports = function ({ print }) {
{
test: /^(pickstart|pickend)$/,
ali: aliEventLog,
swan: baiduEventLog
swan: baiduEventLog,
tt: ttEventLog
}
]
}
Expand Down
Expand Up @@ -5,6 +5,8 @@ module.exports = function ({ print }) {
const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' })
const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
const baiduEventLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false, type: 'event' })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })
const ttEventLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false, type: 'event' })

return {
test: TAG_NAME,
Expand All @@ -26,14 +28,27 @@ module.exports = function ({ print }) {
}
obj.name = propsMap[obj.name]
return obj
},
tt (obj) {
const propsMap = {
'activeColor': 'active-color',
'backgroundColor': 'background-color'
}
obj.name = propsMap[obj.name]
return obj
}
},
{
test: /^(show-info|border-radius|font-size|)$/,
tt: ttPropLog
}
],
event: [
{
test: /^(activeend)$/,
ali: aliEventLog,
swan: baiduEventLog
swan: baiduEventLog,
tt: ttEventLog
}
]
}
Expand Down
Expand Up @@ -3,14 +3,16 @@ const TAG_NAME = 'rich-text'
module.exports = function ({ print }) {
const aliPropLog = print({ platform: 'ali', tag: TAG_NAME, isError: false })
const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })

return {
test: TAG_NAME,
props: [
{
test: /^(space)$/,
ali: aliPropLog,
swan: baiduPropLog
swan: baiduPropLog,
tt: ttPropLog
}
]
}
Expand Down
Expand Up @@ -2,13 +2,15 @@ const TAG_NAME = 'scroll-view'

module.exports = function ({ print }) {
const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })

return {
test: TAG_NAME,
props: [
{
test: /^(enable-back-to-top)$/,
swan: baiduPropLog
swan: baiduPropLog,
tt: ttPropLog
}
],
event: [
Expand Down
Expand Up @@ -34,6 +34,17 @@ module.exports = function ({ print }) {
obj.name = propsMap[obj.name]
return obj
}
},
{
test: /^(activeColor|backgroundColor)$/,
tt (obj) {
const propsMap = {
'activeColor': 'active-color',
'backgroundColor': 'background-color'
}
obj.name = propsMap[obj.name]
return obj
}
}
],
event: [
Expand Down
Expand Up @@ -6,6 +6,8 @@ module.exports = function ({ print }) {
const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
const baiduEventLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false, type: 'event' })
const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false })
const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })
const ttEventLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false, type: 'event' })

return {
test: TAG_NAME,
Expand All @@ -21,6 +23,10 @@ module.exports = function ({ print }) {
{
test: /^(easing-function)$/,
qq: qqPropLog
},
{
test: /^(previous-margin|next-margin|skip-hidden-item-layout|easing-function)$/,
tt: ttPropLog
}
],
event: [
Expand All @@ -35,7 +41,8 @@ module.exports = function ({ print }) {
},
{
test: /^(transition|animationfinish)$/,
ali: aliEventLog
ali: aliEventLog,
tt: ttEventLog
},
{
test: /^(transition)$/,
Expand Down