- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 Jest 来测试我的 Node API。我有一个简单的 npm 脚本,它调用 jest
{
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js",
"test": "jest",
"precommit": "lint-staged"
},
"dependencies": {
"@koa/cors": "^2.2.1",
"apollo-link-http": "^1.5.4",
"apollo-server-koa": "^1.3.6",
"axios": "^0.18.0",
"dotenv": "^6.0.0",
"graphql": "^0.13.2",
"graphql-tools": "^3.0.4",
"koa": "^2.5.1",
"koa-bodyparser": "^4.2.1",
"koa-router": "^7.4.0",
"node-fetch": "^2.1.2"
},
"devDependencies": {
"husky": "^0.14.3",
"jest": "^23.3.0",
"lint-staged": "^7.2.0",
"nodemon": "^1.17.5",
"prettier": "^1.13.7"
},
"lint-staged": {
"gitDir": "./",
"*.{js,json}": [
"prettier --no-semi --print-width 140 --tab-width 2 --write",
"git add"
]
},
"jest": {
"bail": true,
"verbose": true,
"testMatch": [
"<rootDir>/**/*.test.js"
]
}
}
我的 package.json
中有一个 jest 配置,它告诉 jest 要测试什么:
"jest": {
"bail": true,
"verbose": true,
"testMatch": [
"<rootDir>/**/*.test.js"
]
}
我在我的项目中根本没有使用 babel,但由于某种原因,当我尝试在 ./test.test.js
中运行我的一个测试时
test("Example test", () => {
expect(true).toBe(true)
})
我收到以下错误:
$ jest
FAIL ./test.test.js
● Test suite failed to run
Couldn't find preset "env" relative to directory "/Users/<myusername>/Projects"
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map (<anonymous>)
at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (node_modules/babel-core/lib/transformation/pipeline.js:46:16)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 7.563s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
我尝试添加 babel env 预设,但仍然遇到相同的错误。我认为我也不应该仅仅为了测试而添加 babel 配置。
我正在运行 Node 版本8.11.3
和yarn 1.7.0
,并使用版本^23.2.0
在项目本地安装jest
我如何告诉 jest 不要担心 babel env?
最佳答案
当您安装 Jest 时,
babel-jest
会自动添加。如果您不打算转译 ES6 代码(看起来像您的情况),也许只需重置配置即可:
// package.json
{
"jest": {
"transform": {}
}
}
关于javascript - Jest 无法找到相对于目录的预设 "env",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51211570/
我想我读过一些可以在 cocoa 应用程序中包含 NSUserDefaults 文件的地方。我似乎无法找到如何做到这一点。 我知道我可以在第一次应用程序启动时创建,但我还不想这样做...... 最佳答
所以我有一个 HTML 表单,用户可以在其中通过选中三个预设答案之一或编写自己的自定义答案来回答单选题。 虽然这显然是一个多对多关系,但我仍然找不到合适的方法来设计数据库表以处理这两种类型(TEXT
这个问题在这里已经有了答案: Unexpected token '=' in React Component [duplicate] (2 个答案) 关闭 4 年前。 我在使用 Webpack 构建
我正在创建一个自定义相机 View ,并尝试查看是否有办法为输入和输出设置不同的 session 预设。我希望能够向用户展示高分辨率,但以低分辨率捕获 var captureSession: AVCa
我当前的设置如下(基于 Brad Larson 的 ColorTrackingCamera 项目): 我正在使用设置为 AVCaptureSessionPreset640x480 的 AVCaptur
我正在开发一个 React-Native 应用程序,它是使用 Expo 安装的,使用以下代码创建 .babelrc 配置: { "presets": ["babel-preset-expo"]
在一个工作 Jest + puppeteer 操作项目中, 为了使用 jest-circus retry feature,我要去 jest-circus . 正如所记录的,我安装了 jest-circ
这个问题已经有答案了: How to use arrow functions (public class fields) as class methods? (4 个回答) 已关闭 4 年前。 当我尝
我正在使用实现 Browserify-Rails 的 Rails 4.0 项目实现Babelify . 在我的本地和远程 Beta 服务器上,一切似乎都很顺利。但是当我部署到生产环境时,某些文件将被跳
我正在向 dat.gui 界面动态添加控件,但“保存设置”功能无法识别它们。 var mygui = new dat.GUI(); mygui.remember(mygui); // standard
我想创建一个录制方形视频的自定义相机。然而,所有的捕获 session 预设都不是方形格式 例如: 1920x1080 1280x720 640x480 无论如何我可以创建一个自定义预设。我仍然想要高
function floatTo16BitPCM(output, offset, input){ for (var i = 0; i < input.length; i++, offset+=2)
我正在阅读有关使用 systemd 预设的 Fedora 打包指南,但遗漏了一个关键点: 宏 %systemd_post 运行 systemctl preset 意味着有关是否启用或禁用该服务的信息必
错误描述:当为 javascript 代码的简单单元测试运行 jest 时,出现错误测试套件无法运行未知选项:.preset 以下是重现错误的文件: { "name": "Relocati
我正在尝试使用 ffmpeg 和 x264 对视频进行编码。我知道 ffmpeg 从命令行使用程序 ffmpeg 时可以使用 x264 预设。但是在代码中使用 ffmpeg 编码时是否可以轻松使用
我的 npm 包构建使用 babel 运行,我在我的 package.json 中配置了一个 babel 预设 "babel": { "presets": ["es2015"] } 我还配置了一个 m
我们正在尝试使用 javacpp 重新编译 ffmpeg 项目,并启用 --enable-libfdk-aac ,构建可以正常工作,但我们无法使用 libfdk_aac 来解码 audio_strea
美好的一天: 我刚刚通过 NPM 安装了 Babel Preset-ENV 并遇到了这个问题: [nodemon] starting `babel-node server.js server.js`
我正在通过 ffmpeg(在 C++ 程序中)使用 libx264,我需要知道如何激活“非常快”预设。 x264 源代码树中的 grep 生成: include/x264.h:static const
我正在处理的一个项目已经配置了 Jest,并且测试工作正常。这就是当前 jest.config.js 文件的样子; const ignores = [...]; const coverageIgnor
我是一名优秀的程序员,十分优秀!