bernard-lin / babel-plugin-glamorous-displayname

A babel plugin for Glamorous displayNames 💄
http://npm.im/babel-plugin-glamorous-displayname
MIT License
32 stars 2 forks source link

Doesn't work well with istanbul... #6

Closed kentcdodds closed 6 years ago

kentcdodds commented 7 years ago

I'll have to provide more info later, but if you using this with the babel-plugin-istanbul first, then it inserts the displayName assignment before the component is created. Totally bonkers. But it means that you can't use this when using --coverage with jest... At least that's what I found in the glamorous-website project. Which is really odd because that seems to work fine in my work project. 🤔

bernard-lin commented 7 years ago

Does this have something to do with the order in which plugins are loaded?

kentcdodds commented 7 years ago

Yes, and unfortunately with jest we have no control over the order (without a bunch of extra config). I'm unsure of the solution :-(

dylanmoz commented 6 years ago

@kentcdodds any thoughts? I'm running into this issue as well. I tried writing my own preprocessor, which ended up seeming to work but started spitting out different errors after adding more tests. Here was my simple attempt:

// package.json under "jest"
"transform": {
  "^.+\\.jsx?$": "<rootDir>/jestPreprocessor.js"
}
// jestPreprocessor.js
const babel = require('babel-core')

module.exports = {
  process(src, path, config) {
    const code = babel.transform(src, {
      "presets": [
        "env",
        "flow",
        "react"
      ],
      "plugins": [
        // other plugins...
        "glamorous-displayname",
        "istanbul"
      ]
    })

    return code
  }
}
kentcdodds commented 6 years ago

I solved it doing some fancy stuff with my babelrc (here's the real thing) :smile:

dylanmoz commented 6 years ago

@kentcdodds ah.. the irony. I was using the plugin to help with writing enzyme tests, i.e. component.find('SomeInnerGlamorousComponent'). I'll just switch out the string usage for the actual references and not use this plugin during tests.