简体   繁体   English

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

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

It should be very simple this one, but I can't run it.这个应该很简单,但是我运行不了。 I have installed the plugin according the their docs and written a simple example also according to their docs:我已经根据他们的文档安装了插件,并根据他们的文档编写了一个简单的示例:

test.js:测试.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('')
      },
    },
  }
}

I have installed jest according to jest docs:我已经根据 jest docs 安装了 jest:

npm install jest --save-dev

My package.json file:我的 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"
  }
}

I also have babel config as:我也有 babel 配置为:

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
  ],
};

I try to run npx jest test.js but it just spits out我尝试运行npx jest test.js但它只是吐出来

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0

I can run jest on a simple example without babel-plugin-tester, so everything seems to work, but I probably don't understand how it is intended to be used with jest.我可以在没有 babel-plugin-tester 的简单示例上运行 jest,所以一切似乎都正常,但我可能不明白它是如何与 jest 一起使用的。 I feel so stupid.我觉得好蠢。

This is stupid.这是愚蠢的。 I had to rename my testfile to fit *.test.js?我必须重命名我的测试文件以适应 *.test.js? Why don't jest trust me that the file I intend to run indeed contains tests?!为什么不相信我打算运行的文件确实包含测试?! This is obviously a stupid implementation of jest!!这显然是一个愚蠢的玩笑实现!!

Hours of wasted time.. thanks to stupid jest浪费了数小时的时间..多亏了愚蠢的笑话

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

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