RealOrangeOne / react-native-mock

A fully mocked and test-friendly version of react native (maintainers wanted)
MIT License
571 stars 153 forks source link

RN 0.33.0 Conflicts with react-native/lib/* ? #95

Closed joncursi closed 8 years ago

joncursi commented 8 years ago

As of React Native 0.33.0, my build started failing as it could not find the react-native/lib/* files. Example:

Cannot find module 'deepDiffer'

I've gotten around this with mockery:

mockery.registerMock('react-native/lib/deepDiffer', () => null);
mockery.registerMock('react-native/lib/flattenStyle', () => null);
mockery.registerMock('react-native/lib/InitializeJavaScriptAppEngine', () => null);
mockery.registerMock('react-native/lib/RCTEventEmitter', () => null);
mockery.registerMock('react-native/lib/TextInputState', () => null);
mockery.registerMock('react-native/lib/UIManager', () => null);
mockery.registerMock('react-native/lib/UIManagerStatTracker', () => null);
mockery.registerMock('react-native/lib/View', () => null);
mockery.registerMock('react-native/lib/deepFreezeAndThrowOnMutationInDev', () => null);

While this got past the above errors, it prompted a new one:

Error: Cannot find module 'BoundingDimensions'

I assume these to be issues with RN 0.33.0?

RealOrangeOne commented 8 years ago

I'm not sure youre meant to be importing things from react native with paths like that. You should probably be getting the components from the keys of react-native itself. As our project doesnt use the same directory structure as react-native, this is unlikely to work. Are the modules youre getting from libs/ available off react-native?

joncursi commented 8 years ago

That's the interesting thing! I'm only importing standard components from the React Native docs, so I'm trying to figure out why my test setup is getting tripped up on react native internals. I figured this could be due to the RN 0.33.0 upgrade and the way this package handles that, but it looks like I was wrong. I'll continue to investigate in my repo and report back any findings.

Thanks!

RealOrangeOne commented 8 years ago

during tests, you shouldnt be touching react-native itself at all. So i'm confused why this is a problem with versions of react-native. I can only presume that you are somewhere requiring like that with paths.

joncursi commented 8 years ago

Ah, so it turns out this issue was being caused by react-native-svg.

The following snippet inside mocha's setup.js fixed the issue:

import mockery from 'mockery';

...

mockery.registerMock('react-native-svg', () => null);

Sorry for logging this where it didn't belong!

RealOrangeOne commented 8 years ago

Great. I would also be tempted to open an issue against react-native-svg, as they really shouldnt be importing react-native things like that