简体   繁体   中英

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:

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:

npm install jest --save-dev

My package.json file:

{
  "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:

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

I try to run npx jest test.js but it just spits out

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. I feel so stupid.

This is stupid. I had to rename my testfile to fit *.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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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