这个应该很简单,但是我运行不了。我已经根据他们的文档安装了插件,并根据他们的文档编写了一个简单的示例:
测试.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 一起使用的。我觉得自己好傻。