vitalets / react-native-extended-stylesheet

Extended StyleSheets for React Native
MIT License
2.93k stars 132 forks source link

SyntaxError with jest, babel, and react-native-web #143

Closed kumar303 closed 4 years ago

kumar303 commented 4 years ago

Steps to Reproduce

Is there something I'm missing to set up Jest? I get this when Jest runs my test:

  ● Test suite failed to run

    <project_path>/node_modules/react-native-extended-stylesheet/src/index.js:5
    import Api from './api';
           ^^^

    SyntaxError: Unexpected identifier

The stack trace points to the first place my app under test tries to import react-native-extended-stylesheet.

I tried adding __mocks__ like the jest-testing example but I get the same SyntaxError when it tries to load the mock (in the require statement).

Do I need a special babel transform?

Try in Expo

Expected Behavior

Actual Behavior

Show the code

My babel.config.js:

module.exports = {
  plugins: [["react-native-web", { commonjs: true }]],
  presets: [
    ["@babel/preset-env", { targets: { node: "current" } }],
    "@babel/preset-react",
    "@babel/preset-typescript",
  ],
};

My jest.config.js:

module.exports = {
  setupFiles: ["<rootDir>src/__tests__/setupJsDom.js"],
  setupFilesAfterEnv: ["<rootDir>src/__tests__/setupTests.tsx"],
  testEnvironment: "node",
  testPathIgnorePatterns: [
    "/node_modules/",
    "<rootDir>/build/",
    "<rootDir>/src/__tests__/helpers.*",
    "<rootDir>/src/__tests__/setup.*",
  ],
  // This needs to match the url in __tests__/setupJsDom.js
  testURL: "http://localhost",
};

Environment

N/A because I'm using react-native-web?

I am using react-native-extended-stylesheet@0.12.0, react-native-web@0.13.3, @babel/core@7.10.3, and jest@26.0.1

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

sourabhAfunky commented 2 years ago

@kumar303 have you figured it out?

Mister-CK commented 1 year ago

Yes, this is still relevant, we are running into this issue right now.