RealOrangeOne / react-native-mock

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

Build a way to safely require single modules from react-native #3

Open lelandrichardson opened 8 years ago

lelandrichardson commented 8 years ago

Need to implement:

  1. flow transforms
  2. babel transforms
  3. fbjs transforms
sibelius commented 8 years ago

I'm receiving a flow error I guess

react-native-vector-icons/lib/create-icon-set.js:39
function createIconSet(glyphMap : Object, fontFamily : string, fontFile : string) : Function {
                                ^
SyntaxError: Unexpected token :

is there a workaround for this for now?

mroswald commented 8 years ago

in our mocha config we do --register a file that looks like this:

require('react-native-mock/mock');

require('babel-core/register')({
    ignore: function(packageName) {
        if (packageName.match(/node_modules/)) {
            return !(packageName.match(/react-native-vector-icons/)
                || packageName.match(/react-native-animatable/)
            );
        }
        return false;
    }
});

[...]
sibelius commented 8 years ago

I'm receiving this error when I try to run tests with react-native-router-flux

app/node_modules/babel-core/lib/transformation/file/index.js:591
      throw err;
      ^

SyntaxError: app/node_modules/react-native-router-flux/src/menu_burger.png: Unexpected character '�' (1:0)
> 1 | �PNG
    | ^
  2 | 
  3 | 

this is my testHelper.js file

require('babel-polyfill');
require('react-native-mock/mock');

require('babel-core/register')({
  ignore: function(packageName) {
    if (packageName.match(/node_modules/)) {
      return !(packageName.match(/react-native-vector-icons/)
        || packageName.match(/react-native-animatable/)
        || packageName.match(/react-native-router-flux/)
        || packageName.match(/react-native-tab-navigator/)
      );
    }
    return false;
  }
});

and this is my npm test script

"test": "node_modules/.bin/mocha --compilers js:babel-core/register --require testHelper.js **/__test__/*.js",

any workaround to handle this?

RealOrangeOne commented 8 years ago

@sibeliusseraphini Yes, this occurs when node tries to require an image as JS. See #11 for more discussions