繁体   English   中英

如何用 jest 运行 babel-plugin-tester?

[英]How do I run babel-plugin-tester with jest?

这个应该很简单,但是我运行不了。 我已经根据他们的文档安装了插件,并根据他们的文档编写了一个简单的示例:

测试.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? 为什么不相信我打算运行的文件确实包含测试?! 这显然是一个愚蠢的玩笑实现!!

浪费了数小时的时间..多亏了愚蠢的笑话

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM