Skip to content

Commit

Permalink
feat: mock for quickapp
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode authored and luckyadam committed Dec 31, 2019
1 parent 2796e46 commit a26c41a
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/barcode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/geolocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/record.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/sensor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/share.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/sms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/vibrator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__mocks__/@system/webview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions packages/taro-quickapp/__test__/api.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test('api test', () => {})
15 changes: 15 additions & 0 deletions packages/taro-quickapp/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
'presets': [
['@babel/preset-env', {
// 'modules': 'umd',
'spec': true
}]
],
'plugins': [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
['@babel/plugin-transform-react-jsx', {
'pragma': 'Nerv.createElement'
}]
]
}
15 changes: 15 additions & 0 deletions packages/taro-quickapp/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
verbose: true,
moduleNameMapper: {
'@tarojs/taro-quickapp': '<rootDir>/src/index.js',
// '@tarojs/taro': '<rootDir>/../taro/src/index',
'@tarojs/utils': '<rootDir>/../taro-utils/src/index',
'^@system.(.*)': '<rootDir>/__mocks__/@system/$1.js'
},
rootDir: __dirname,
testMatch: ['<rootDir>/**/*.test.js'],
transform: {
'^.+\\.js?$': 'babel-jest'
},
transformIgnorePatterns: ['<rootDir>/node_modules/']
}
5 changes: 3 additions & 2 deletions packages/taro-quickapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"package.json"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c rollup.config.js"
"build": "rollup -c rollup.config.js",
"dev": "rollup -c rollup.config.js -w",
"test": "jest"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-quickapp/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export * from './notification'
export * from './system'
export * from './webview'
export * from './media'
export * from './device'
export * from './device'
3 changes: 3 additions & 0 deletions packages/taro-quickapp/src/api/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const api = require('./index')

console.log(Object.keys(api).join(' '))
8 changes: 8 additions & 0 deletions packages/taro-quickapp/src/api/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ export function makeSyncPromise (fnName, process, options = {}) {
}
})
}

export function temporarilyNotSupport (apiName) {
return () => {
const errMsg = `暂时不支持 API ${apiName}`
console.error(errMsg)
return Promise.reject(new Error(errMsg))
}
}

0 comments on commit a26c41a

Please sign in to comment.