New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Packager][Testing] Best way to get react native running with mocha #5392
Comments
cc @martinbigio or @amasad |
Hey lelandrichardson, thanks for reporting this issue! React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
|
OK, I figured it out... I forgot that babel-core/register ignores node_modules by default. Since RN's files arent compiled, this doesn't work out very well. I was able to run this file on startup which got it done: var fs = require('fs');
var path = require('path');
function getBabelRC() {
var rcpath = path.join(__dirname, '..', '.babelrc');
var source = fs.readFileSync(rcpath).toString();
return JSON.parse(source);
}
var config = getBabelRC();
config.ignore = function(filename) {
if (!(/\/node_modules\//).test(filename)) {
return false; // if not in node_modules, we want to compile it
} else if ((/\/node_modules\/react-native\//).test(filename)) {
// its RN source code, so we want to compile it
return false;
} else {
// it's in node modules and NOT RN source code
return true;
}
};
require("babel-register")(config);
global.__DEV__ = true; |
Hi Leland, thanks for this and your great work on Enzyme. Can you elaborate on: "I was able to run this file on startup which got it done:"? I'm currently trying to setup mocha as well, but also having an issue with babel and node modules. package.json:
./test/setup.js:
.babelrc:
|
Looks like this code is actually running as intended based on my previous post, but gets stuck on external node modules. The error I'm getting:
|
I've gotten past the spread issue, but now I'm having an issue with
Did either of you have an issue with this? Maybe it's not including the Platform modules because of the platform specific extensions |
I'm having the same issue with tests and platform specific extensions. Do you have any workaround for that? |
@alvaromb: At the suggestion of @lelandrichardson, I started using his library https://github.com/lelandrichardson/react-native-mock. Not sure if it's a long term solution for me, but I was able to successfully run tests for now with it 👍 |
Any solutions using |
Having the same issue with tests and platform specific extensions. |
I'm trying to get React Native working with Enzyme (https://github.com/airbnb/enzyme) and am running into issues getting the project into a state where I can actually import the react-native module.
I'm trying to run mocha with the
--compilers
flag like so:Additionally, i have the .babelrc that's in the packager folder in the root folder, with the following:
But it is throwing an error as soon as it runs into the object-rest-spread operator:
I'd assume that since the
transform-object-rest-spread
is in the babelrc that this would work fine? What am I missing? Any help would be appreciated.The text was updated successfully, but these errors were encountered: