Giter Site home page Giter Site logo

Comments (6)

theKashey avatar theKashey commented on May 21, 2024

So - you just have an issue with importing ESModules from node_modules, that’s absolutely ok-ish.
By default, even if you are running your tests with Babel/register, it will ignore node_modules. So, as long as Babel won’t transpile code, and node won’t understand imports - it does not work.

How to solve:

  • or change Babel configuration (I am not sure how)
  • use ‘esm_modules’ from require-control, that would save your day.

from rewiremock.

loicpw avatar loicpw commented on May 21, 2024

thanks, sorry I'm not sure to understand as I'm quite new to Javascript and React, I tried the following in my test script but this didn't work:

require('babel-register');
const { esm_modules } = require('require-control');
esm_modules();

from rewiremock.

theKashey avatar theKashey commented on May 21, 2024

Sorry, I've read your issue a bit inaccurate - the original problem import './mycompoent.css'; is happening in your own mycomponent.js.

That means that babel-register is not working as expected. Probably you have modules:false setting in your .babelrc - could you please check it?

from rewiremock.

loicpw avatar loicpw commented on May 21, 2024
./node_modules/babel-plugin-dynamic-import-node/.babelrc:
-------------------------------------------------
{
  "presets": [
    "airbnb"
  ],
  "plugins": [
    "add-module-exports",
    ["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }],
  ],
}


./node_modules/compare-module-exports/.babelrc:
-------------------------------------------------
{
  "presets": [],
  "env": {
    "cjs": {
      "presets": [
        [
          "env",
          {
            "targets": {
              "node": "7.0",
              "ie": 11
            }
          }
        ]
      ]
    }
  }
}


./node_modules/eslint-plugin-jsx-a11y/.babelrc:
-------------------------------------------------
{
  "presets": ["es2015"],
  "plugins": [
    "transform-object-rest-spread",
    "transform-flow-strip-types",
  ]
}


./node_modules/esrecurse/.babelrc:
-------------------------------------------------
{
    "presets": ["es2015"]
}


./node_modules/estraverse/.babelrc:
-------------------------------------------------
{
    "presets": ["es2015"]
}

./node_modules/fileset/.babelrc:
-------------------------------------------------
{
  "presets": ["es2015"],

  "plugins": [
    "add-module-exports"
  ]
}


./node_modules/identity-obj-proxy/.babelrc:
-------------------------------------------------
{
  "presets": [ "es2015", "stage-0" ],
}


./node_modules/jsx-ast-utils/.babelrc:
-------------------------------------------------
{
  "presets": ["es2015"]
}


./node_modules/optimize-css-assets-webpack-plugin/.babelrc:
-------------------------------------------------
{
  "presets": [
    [
      "env",
      {
        "useBuiltIns": true,
        "targets": {
          "node": "current"
        },
        "exclude": [
          "transform-async-to-generator",
          "transform-regenerator"
        ]
      }
    ]
  ],
  "plugins": [
    [
      "transform-object-rest-spread",
      {
        "useBuiltIns": true
      }
    ]
  ]
}


./node_modules/wipe-node-cache/.babelrc:
-------------------------------------------------
{
  "presets": [],
  "env": {
    "cjs": {
      "presets": [
        [
          "env",
          {
            "targets": {
              "node": "7.0",
              "ie": 11
            }
          }
        ]
      ]
    }
  }
}


./node_modules/wipe-webpack-cache/.babelrc:
-------------------------------------------------
{
  "presets": [],
  "env": {
    "cjs": {
      "presets": [
        [
          "env",
          {
            "targets": {
              "node": "7.0",
              "ie": 11
            }
          }
        ]
      ]
    }
  }
}

Also note I'm using create-react-app, I didn't change any config so far but I have no clue if they're doing something special...
Thanks !

from rewiremock.

theKashey avatar theKashey commented on May 21, 2024

ok, not it's clear why it's not working - there is no setup for a babel.
If you are using CRA and running npm run test, then according to the documentation you should have Jest.
Jest should handle babel out of the box, and also should handle mocking (via jest.mock).
! rewrimock is incompatible with Jest

In the same time - as long as you were able to mock something, and have babel related issues - it's not the default CRA config.

Then - just drop .babelrc to your tests or root dirrectory

{ 
 presets: ["env","react"]
}

from rewiremock.

loicpw avatar loicpw commented on May 21, 2024

Thanks for your help, sorry I need to use react-app-rewired to be able to customize babelrc, I don't have time right now I'm gonna try this a little bit later asap...

from rewiremock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.