speedskater/babel-plugin-rewire

Integration with CRACO

SnapeEye opened this issue · 3 comments

Hey!

Faced a problem when tried to add this plugin in CRACO project. Jest test runner is used.
What I did:

  • added new setup file for jest (the file is used by jest, inserted log to verify it):
module.exports = {
  jest: {
    configure: (jestConfig, { env, paths, resolve, rootDir }) => {
      if (!jestConfig.setupFiles) {
        jestConfig.setupFiles = [`${rootDir}\\jestGlobalSetup.js`]
      } else {
        jestConfig.setupFiles.push(`${rootDir}\\jestGlobalSetup.js`)
      }
      return jestConfig
    },
  },
}
  • added require for plugin to integrate (tried all the 3 ways - no result):
 require('babel-register')({
   plugins: ['babel-plugin-rewire'],
})
// require('babel-core').transform('code', { plugins: ['babel-plugin-rewire'] })
// require('babel-core').transform('code', { plugins: ['rewire'] })

So when I run tests, I expect the following code to be valid:

import { __RewireAPI__ as RWA } from '../logic'
import { __Rewire__ as RW } from '../logic'
console.log(RWA)
console.log(RW)

Tried different naming, thought maybe smth changed. But got undefined for both.

Maybe someone will advice what can be done? Or explain why it is not working. Or where I messed up -_-
Will appreciate any help, comments, explanations, etc.

ping

ping

ping