utils.js 966 B

123456789101112131415161718192021222324252627282930
  1. const fs = require('fs')
  2. const path = require('path')
  3. const simulate = require('miniprogram-simulate')
  4. const config = require('../tools/config')
  5. // const dir = config.srcPath // 使用源码进行测试,对于 debug 和代码覆盖率检测会比较友好
  6. const dir = config.distPath // 使用构建后代码进行测试,如果使用了 typescript 进行开发,必须选择此目录
  7. try {
  8. fs.accessSync(dir)
  9. } catch (err) {
  10. console.error('请先执行 npm run build 再进行单元测试!!!')
  11. }
  12. const oldLoad = simulate.load
  13. simulate.load = function (componentPath, ...args) {
  14. if (typeof componentPath === 'string') componentPath = path.join(dir, componentPath)
  15. return oldLoad(componentPath, ...args)
  16. }
  17. module.exports = simulate
  18. // adjust the simulated wx api
  19. const oldGetSystemInfoSync = global.wx.getSystemInfoSync
  20. global.wx.getSystemInfoSync = function() {
  21. const res = oldGetSystemInfoSync()
  22. res.SDKVersion = '2.4.1'
  23. return res
  24. }