JEST和ES6导入-基于根文件夹的导入不起作用

鲁斯塔姆

我有基于https://github.com/davezuko/react-redux-starter-kit的React项目

在JEST测试中:当我尝试导入基于根目录的路径(例如“ components / Link”)时,它不起作用,只有相对路径起作用。

推杆

{ "jest": { "rootDir": "<rootDir>/src" } }

在package.json中不起作用。

还有其他办法吗?

Package.json:

{
  "name": "react-redux-starter-kit",
  "version": "3.0.0-alpha.2",
  "description": "",
  "main": "index.js",
  "engines": {
    "node": ">=4.5.0",
    "npm": "^3.0.0"
  },
  "scripts": {
    "clean": "rimraf dist",
    "compile": "better-npm-run compile",
    "lint": "eslint bin build config server src tests",
    "lint:fix": "npm run lint -- --fix",
    "start": "better-npm-run start",
    "dev": "better-npm-run dev",
    "test": "jest",
    "test:dev": "npm run test -- --watch",
    "deploy": "better-npm-run deploy",
    "deploy:dev": "better-npm-run deploy:dev",
    "deploy:prod": "better-npm-run deploy:prod",
    "codecov": "cat coverage/*/lcov.info | codecov"
  },
  "betterScripts": {
    "compile": {
      "command": "node bin/compile",
      "env": {
        "DEBUG": "app:*"
      }
    },
    "dev": {
      "command": "nodemon bin/server --ignore dist --ignore coverage --ignore tests --ignore src",
      "env": {
        "NODE_ENV": "development",
        "DEBUG": "app:*"
      }
    },
    "deploy": {
      "command": "npm run lint && npm run clean && npm run compile",
      "env": {
        "DEBUG": "app:*"
      }
    },
    "deploy:dev": {
      "command": "npm run deploy",
      "env": {
        "NODE_ENV": "development",
        "DEBUG": "app:*"
      }
    },
    "deploy:prod": {
      "command": "npm run deploy",
      "env": {
        "NODE_ENV": "production",
        "DEBUG": "app:*"
      }
    },
    "start": {
      "command": "node bin/server",
      "env": {
        "DEBUG": "app:*"
      }
    },
    "test": {
      "command": "node ./node_modules/karma/bin/karma start build/karma.conf",
      "env": {
        "NODE_ENV": "test",
        "DEBUG": "app:*"
      }
    }
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/davezuko/react-redux-starter-kit.git"
  },
  "author": "MyCityOnline",
  "license": "MIT",
  "dependencies": {
    "babel-core": "^6.18.2",
    "babel-loader": "^6.2.5",
    "babel-plugin-transform-runtime": "^6.15.0",
    "babel-preset-es2015": "^6.14.0",
    "babel-preset-react": "^6.11.1",
    "babel-preset-stage-0": "^6.3.13",
    "babel-runtime": "^6.11.6",
    "better-npm-run": "0.0.11",
    "cropperjs": "^1.0.0-beta.2",
    "css-loader": "^0.25.0",
    "cssnano": "^3.7.4",
    "debug": "^2.2.0",
    "dotenv": "^2.0.0",
    "es6-promise": "^4.1.0",
    "essence-core": "^1.0.20",
    "essence-switch": "^1.0.10",
    "exports-loader": "^0.6.3",
    "extract-text-webpack-plugin": "^1.0.0",
    "file-loader": "^0.9.0",
    "font-awesome": "^4.7.0",
    "fs-extra": "^0.30.0",
    "html-webpack-plugin": "^2.22.0",
    "imports-loader": "^0.6.5",
    "ip": "^1.1.2",
    "isomorphic-fetch": "^2.2.1",
    "json-loader": "^0.5.4",
    "jwt-decode": "^2.1.0",
    "lodash": "^4.16.3",
    "moment": "^2.17.1",
    "node-sass": "^3.7.0",
    "normalize.css": "^4.1.1",
    "pikaday": "^1.5.1",
    "postcss-loader": "^0.13.0",
    "react": "^15.0.0",
    "react-dom": "^15.0.0",
    "react-redux": "^4.4.5",
    "react-router": "^2.8.0",
    "redux": "^3.6.0",
    "redux-api-middleware": "^1.0.2",
    "redux-thunk": "^2.0.0",
    "rimraf": "^2.5.4",
    "sass-loader": "^4.0.0",
    "style-loader": "^0.13.1",
    "url-loader": "^0.5.6",
    "webpack": "^1.12.14",
    "whatwg-fetch": "^2.0.1",
    "yargs": "^5.0.0"
  },
  "devDependencies": {
    "babel-eslint": "^6.0.0-beta.6",
    "babel-jest": "^19.0.0",
    "babel-plugin-istanbul": "^2.0.1",
    "breakpoint-sass": "^2.7.0",
    "chai": "^3.4.1",
    "chai-as-promised": "^5.3.0",
    "chai-enzyme": "^0.5.0",
    "cheerio": "^0.20.0",
    "codecov": "^1.0.1",
    "connect-history-api-fallback": "^1.3.0",
    "enzyme": "^2.0.0",
    "eslint": "^3.0.1",
    "eslint-config-standard": "^6.2.1",
    "eslint-config-standard-react": "^4.0.0",
    "eslint-plugin-babel": "^3.2.0",
    "eslint-plugin-promise": "^3.3.0",
    "eslint-plugin-react": "^6.0.0",
    "eslint-plugin-standard": "^2.0.0",
    "express": "^4.14.0",
    "http-proxy-middleware": "^0.17.2",
    "jest": "^19.0.2",
    "karma": "^1.0.0",
    "karma-coverage": "^1.0.0",
    "karma-mocha": "^1.0.1",
    "karma-mocha-reporter": "^2.0.0",
    "karma-phantomjs-launcher": "^1.0.2",
    "karma-webpack-with-fast-source-maps": "^1.9.2",
    "less": "^2.7.1",
    "less-loader": "^2.2.3",
    "mocha": "^3.0.1",
    "nodemon": "^1.10.2",
    "phantomjs-prebuilt": "^2.1.12",
    "react-addons-test-utils": "^15.0.0",
    "redbox-react": "^1.2.10",
    "redux-logger": "^2.6.1",
    "regenerator-runtime": "^0.10.3",
    "sinon": "^1.17.5",
    "sinon-chai": "^2.8.0",
    "susy": "^2.2.12",
    "webpack-dev-middleware": "^1.6.1",
    "webpack-hot-middleware": "^2.12.2"
  },
    "jest": {
        "rootDir": "<rootDir>/src"
  }
}

package.json的最后工作JEST部分:

"jest": {
        "rootDir": "./src/",
        "moduleFileExtensions": ["js", "jsx"],
    "moduleDirectories": ["node_modules", "bower_components", "src"],
        "verbose": true
  }
戴维·里夫勒

我认为,如果您不想使用相对路径,则必须定义额外的moduleDirectories,例如

// package.json
{
  "jest": {
    "moduleFileExtensions": ["js", "jsx"],
    "moduleDirectories": ["node_modules", "bower_components", "src"],
  }
} 

更多关于moduleDirectories开玩笑文档配置开玩笑查找文件

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TOP 榜单

  1. 1

    来自Microsoft Office加载项taskpane.js的MySQL驱动程序模块的空引用

  2. 2

    使用AWS Cognito和React的仅限Facebook / Google的登录名(无用户名/密码)

  3. 3

    创建Windows Phone 8应用并将其连接到数据库的最佳方法(最好是SQL Server)

  4. 4

    为什么Java中的System.out.println()打印到控制台?

  5. 5

    卷曲函数无法解析来自bash中变量的代理

  6. 6

    是什么在Android的consumer-rules.pro和proguard-rules.pro之间的区别?

  7. 7

    设置与Apache POI Excel表散点图标记图标的颜色

  8. 8

    将Qt Pyside2与asyncio await语法一起使用?

  9. 9

    崇高的文字+蟒蛇的蟒蛇

  10. 10

    任务':app:minifyReleaseWithR8'.java.lang.NullPointerException的执行失败(无错误消息)

  11. 11

    OpenJDK的和AdoptOpenJDK的区别

  12. 12

    大型数据集缓存到Spark内存中时,“超出了GC开销限制”(通过sparklyr和RStudio)

  13. 13

    “执行测试CMAKE_HAVE_LIBC_PTHREAD”失败实际上是什么意思?

  14. 14

    使用Core 2.2中的Identity,如何在关闭浏览器15分钟后保持会话活动?

  15. 15

    React中的ForwardRefExoticComponent和ForwardRefRenderFunction有什么区别?

  16. 16

    猫鼬查找结果,然后将字段替换为findOne

  17. 17

    如何降级Google Colab的Torch版本

  18. 18

    Keras提前停止回调错误,val_loss指标不可用

  19. 19

    如何避免VSCode中的“导入路径不能以.ts扩展名结尾”错误?

  20. 20

    Nuxt.JS:如何在页面中获取路由URL参数

  21. 21

    是否有为什么会AccessibilityManager.sInstance导致内存泄漏的一个原因?

热门标签

归档