【发布时间】:2019-10-23 09:47:32
【问题描述】:
我是 Vue.js 的初学者,我试图用 Jest 进行一些简单的测试,但是自从使用 Webpack 安装 Vue(第一件事我只是尝试运行脚本),我无法运行npm test 脚本。
我尝试了一些教程(this 和 this)让它运行,但我仍然遇到错误。
我在 Github 上搜索了一些问题,看起来像是依赖错误,所以我尝试安装很多 babel 依赖项,更改为我在答案中可以找到的所有内容,删除 node_modules 并重新安装几次,但似乎没有任何效果。
控制台日志错误:
Test suite failed to run
Plugin/Preset files are not allowed to export objects, only functions. In /home/.../node_modules/babel-preset-stage-2/lib/index.js
at createDescriptor (node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
at items.map (node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
at presets (node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
at mergeChainOpts (node_modules/@babel/core/lib/config/config-chain.js:320:26)
at node_modules/@babel/core/lib/config/config-chain.js:283:7
at buildRootChain (node_modules/@babel/core/lib/config/config-chain.js:120:22)
at loadPrivatePartialConfig (node_modules/@babel/core/lib/config/partial.js:85:55)
Running coverage on untested files...Failed to collect coverage from /home/.../src/utils/ma
ps.js
ERROR: Plugin/Preset files are not allowed to export objects, only functions. In /home/.../node_modules/babel-preset-stage-2/lib/index.js
STACK: Error: Plugin/Preset files are not allowed to export objects, only functions. In /home/.../node_modules/babel-preset-stage-2/lib/index.js
at createDescriptor (/home/.../node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
at items.map (/home/.../node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (/home/.../node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/home/.../node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
at presets (/home/.../node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
at mergeChainOpts (/home/.../node_modules/@babel/core/lib/config/config-chain.js:320:26)
at /home/.../node_modules/@babel/core/lib/config/config-chain.js:283:7
at buildRootChain (/home/.../node_modules/@babel/core/lib/config/config-chain.js:120:22)
at loadPrivatePartialConfig (/home/.../node_modules/@babel/core/lib/config/partial.js:85:55)
我的package.json 文件:
{
"name": "luiza-challenge",
"version": "1.0.0",
"description": "This app makes calls from a API to request address info.",
"author": "~",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"unit": "jest --config test/unit/jest.conf.js --coverage",
"test": "npm run unit",
"lint": "eslint --ext .js,.vue src test/unit",
"build": "node build/build.js"
},
"dependencies": {
"react-scripts": "^3.0.1",
"vue": "^2.5.2",
"vue-resource": "^1.5.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-eslint": "^8.2.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-jest": "^24.8.0",
"babel-loader": "^7.1.1",
"babel-plugin-dynamic-import-node": "^1.2.0",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^2.1.1",
"eslint": "^4.15.0",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-vue": "^4.0.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"jest": "^24.8.0",
"jest-serializer-vue": "^0.3.0",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^2.0.0",
"vue-jest": "^1.0.2",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^3.3.3",
"webpack-dev-server": "^2.9.7",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
还有我的.babelrc 文件:
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2"
],
"plugins": ["transform-vue-jsx", "transform-runtime"],
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]
}
}
}
【问题讨论】:
标签: javascript vue.js jestjs