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

UI库在写单元测试时,如果遇到mono-repo,如何指定process.env.TARO_ENV #6937

Closed
luna-zhao-8 opened this issue Jul 6, 2020 · 1 comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-2 Version - 2.x

Comments

@luna-zhao-8
Copy link

相关平台

H5

复现仓库

https://github.com/luna-zhao-8/mono-repo-taro-project
浏览器版本: Chrome 83
使用框架: React

复现步骤

yarn build
yarn test

期望结果

执行h5环境,测试通过

实际结果

FAIL tests/Card.test.js
  ● Test suite failed to run

    Cannot find module './weapp/index' from 'index.js'

    Require stack:
      /Users/luna.zhao/privatespace/mono-repo-taro-project/packages/ui/dist/index.js
      .temp/component/Card.js
      tests/Card.test.js


    However, Jest was able to find:
        'weapp/index.ts'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'jsx', 'json'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-arraystring

       6 |             module.exports.default = module.exports
       7 |           } else {
    >  8 |               module.exports = require('./weapp/index')
         |                                ^
       9 |               module.exports.default = module.exports
      10 |             }

      at Resolver.resolveModule (../../node_modules/jest-resolve/build/index.js:299:11)
      at Object.<anonymous> (../ui/dist/index.js:8:32)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.704s
Ran all test suites.

环境信息

 Taro CLI 2.2.9 environment info:
    System:
      OS: macOS 10.15.5
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 14.2.0 - /usr/local/bin/node
      Yarn: 1.22.4 - /usr/local/bin/yarn
      npm: 6.14.4 - /usr/local/bin/npm
    npmPackages:
      @tarojs/taro: 2.2.9 => 2.2.9 
      eslint-plugin-taro: 2.2.9 => 2.2.9 
@taro-bot2 taro-bot2 bot added F-react Framework - React T-h5 Target - 编译到 H5 V-2 Version - 2.x labels Jul 6, 2020
@scarcoco
Copy link

同问,项目中使用 2.0.6 版本,然后工程也是 mono-repo,按照 taro-ui 的单测逻辑,先用 --ui 方式把 tsx、ts 等文件编译到 .temp 目录下 js,然后再给 .temp 目录下文件写单测,感觉好傻,另外工程中引入了其他内部包(@scope/xxxx),按照这种方式也没法引入编译后的 .temp 目录下的文件。

编译 taro build --ui 之后,把里面引入的 Taro 变成了 Nerv,搞不明白。

import Taro from '@tarojs/taro' 
import Nerv from "nervjs";
import Taro from "@tarojs/taro-h5";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-2 Version - 2.x
Projects
Archived in project
Development

No branches or pull requests

3 participants