rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.94k stars 866 forks source link

During Test Redux Persist import Storage fails test #848

Open HeratPatel1 opened 6 years ago

HeratPatel1 commented 6 years ago

redux-persist - 5.9.1 react - 16.3.2 jest - 22.4.3

import storage from "redux-persist/es/storage";

({"Object.":function(module,exports,require,dirname,filename,global,jest){import createWebStorage from './createWebStorage'; ^^^^^^

SyntaxError: Unexpected token import

  23 |   key: "root",
  24 |   storage,
> 25 |   whitelist: ["provider", "location", "user"]
  26 | };
  27 | 
  28 | const combinedReducer = persistCombineReducers(config, reducers);

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
  at Object.<anonymous> (app/javascript/bundles/ReduxProvider.jsx:25:16)
  at Object.<anonymous> (app/javascript/bundles/AdminPanel/Location/containers/EditLocationContainer.jsx:13:22)

I also tried with

import storage from "redux-persist/lib/storage";

import React, { PureComponent } from 'react'; // eslint-disable-line import/no-unresolved ^^^^^^

SyntaxError: Unexpected token import

  29 | 
  30 | let AppStore = configureStore(combinedReducer);
> 31 | let persistor = persistStore(AppStore);
  32 | 
  33 | export default class ReduxProvider extends React.Component {
  34 |   render() {

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
  at Object.<anonymous> (app/javascript/bundles/ReduxProvider.jsx:31:15)
  at Object.<anonymous> (app/javascript/bundles/AdminPanel/Location/containers/EditLocationContainer.jsx:13:22)

console.error node_modules/redux-persist/lib/storage/getStorage.js:40 redux-persist failed to create sync storage. falling back to memory storage.

aaronisme commented 6 years ago

seems like the jest is not compile the library, try to add the config on the jest config file? you can refer jest documents

ggsjyoon commented 6 years ago

Same issue here. I'm trying to write tests using ...

"devDependencies": {
    "@types/enzyme": "^3.1.11",
    "@types/enzyme-adapter-react-16": "^1.0.2",
    "@types/faker": "^4.1.2",
    "@types/fetch-mock": "^6.0.3",
    "@types/jest": "^23.1.3",
    "@types/react-test-renderer": "^16.0.1",
    "@types/redux-mock-store": "^1.0.0",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "faker": "^4.1.0",
    "fetch-mock": "^6.4.4",
    "react-scripts-ts": "^2.16.0",
    "react-test-renderer": "^16.4.1",
    "redux-mock-store": "^1.5.3",
    "typescript": "2.9.2"
  }

but I'm getting the below error when import storage from "redux-persist/lib/storage";

$ yarn test
yarn run v1.7.0
$ react-scripts-ts test --env=jsdom
  console.error node_modules\redux-persist\lib\storage\getStorage.js:40
    redux-persist failed to create sync storage. falling back to memory storage.

and same error as @HeratPatel1 's when import storage from "redux-persist/es/storage";

arananegra commented 5 years ago

I'm also running into the same problem. Also tried to switch from import storage from "redux-persist/es/storage" to import storage from "redux-persist/lib/storage" but the error ... persist (no pun intended).

bkostrowiecki commented 2 years ago

This is huge disaster from my perspective. redux-persist just shattered my unit test suites. I cannot find any better solution then just to get rid off redux-persist completely. So if you have app with good coverage don't borther installing redux-persist, better write your own custom solution.

Durgesh00 commented 2 years ago

I am also facing this issue, any updates on this

Segnicho commented 4 months ago

I am also facing this issue, any updates on this?