0

I encountered a weird problem when trying to use babel-plugin-rewireand should.js assertion library in my tests. With my current configuration I cannot require should to a variable:

const should = require('should')
console.log('should through variable: ', should)  // --> undefined !!!
console.log('should through require: ', require('should'))  // --> function should...

Tests are run using command

NODE_ENV=test mocha --compilers js:babel-register --require babel-polyfill --require should

The problem goes away if I comment out the rewire plugin from my .babelrc:

{
  "presets": ["es2015", "es2015-node4", "async-to-bluebird"],
  "env": {
    "test": {
      // "plugins": ["babel-plugin-rewire"]
    }
  }
}

... but then I cannot use the rewire functionality.

Do you have any clues how to get babel-plugin-rewire and should.js work together?

The used library versions are:

"babel-plugin-rewire": "^1.0.0-rc-3",
"should": "^7.1.0",
ronkot
  • 5,915
  • 4
  • 27
  • 41
  • What if you will remove `--require should` from run test cmd? – den bardadym Aug 01 '16 at 11:33
  • Removing `--require should` didn't seem to change anything. It's there to provide object property based assertions like `someString.should.equal('foo')`. – ronkot Aug 01 '16 at 11:42
  • If you will create working example that clearly show an issue (that i pull and just run) create an issue in should.js i will try to help. – den bardadym Aug 01 '16 at 11:48
  • Okay, here's quite minimal gist about the problem: https://gist.github.com/ronkot/2babe4b777d7bcb4053b9747d9c59346 – ronkot Aug 01 '16 at 12:36
  • Not sure why but your example working fine for me. – den bardadym Aug 01 '16 at 13:58
  • @denbardadym Actually the error in the gist is not that `should` would be undefined, but that trying to print the object to console causes a `ReferenceError: _get__ is not defined`. I couldn't replicate the original issue but I'm quite sure that the root cause of these two errors is the same. What does your test run give as output? Mine gives: `[ReferenceError: _get__ is not defined] should through require: function should(obj) { return (new should.Assertion(obj)); }` – ronkot Aug 01 '16 at 14:06

0 Answers0