javascript - 如何用 jest 运行 babel-plugin-tester?
问题描述
这个应该很简单,但是我运行不了。我已经根据他们的文档安装了插件,并根据他们的文档编写了一个简单的示例:
测试.js:
import pluginTester from 'babel-plugin-tester'
pluginTester({
plugin: identifierReversePlugin,
snapshot: true,
tests: [
{code: '"hello";', snapshot: false},
{
code: 'var hello = "hi";',
output: 'var olleh = "hi";',
},
`
function sayHi(person) {
return 'Hello ' + person + '!'
}
console.log(sayHi('Jenny'))
`,
],
})
// normally you would import this from your plugin module
function identifierReversePlugin() {
return {
name: 'identifier reverse',
visitor: {
Identifier(idPath) {
idPath.node.name = idPath.node.name.split('').reverse().join('')
},
},
}
}
我已经根据 jest docs 安装了 jest:
npm install jest --save-dev
我的 package.json 文件:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"@babel/cli": "^7.10.1",
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"babel-jest": "^26.0.1",
"babel-plugin-tester": "^9.2.0",
"jest": "^26.0.1"
}
}
我也有 babel 配置为:
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
我试着跑npx jest test.js
,但它只是吐出来
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
我可以在没有 babel-plugin-tester 的简单示例上运行 jest,所以一切似乎都正常,但我可能不明白它是如何与 jest 一起使用的。我觉得自己好傻。
解决方案
这是愚蠢的!我不得不重命名我的测试文件以适应 *.test.js。为什么不相信我打算运行的文件确实包含测试?!这显然是一个愚蠢的玩笑实现!!
浪费了数小时的时间..多亏了愚蠢的笑话
推荐阅读
- bash - 基于 C++ 二进制运行时参数创建 Bash 脚本文件名
- javascript - 如何在 MarkLogic 10 的资源扩展中导入 JavaScript 模块
- c# - 当 oject 不为空时,为什么我在搜索查询中收到 NullReferenceException
- reactjs - 如何使用 setState 回调函数进行条件函数调用
- regex - oracle regexp_like:使用 Perl 正则表达式与运算符等效
- c# - 有点像头文件,我可以在 C# 中分离一些定义吗?
- python - Pandas 突然无法打开 Excel 文件(在 OLE2 复合文档中找不到工作簿
- c# - 如何绑定多个输入字段,包括单选按钮以在.net核心中列出
- vba - 即使 IIF 条件状态不检查,空访问 VBA 的使用也无效
- swift - textfielddidbegin 编辑不更新标签