I found your code using import in npm, for some reasons mocha throws exceptions about ES6 code inside node_modules/:
=>> cat index.js
export { default as createIconSet } from './lib/create-icon-set';
export { default as createIconSetFromFontello } from './lib/create-icon-set-from-fontello';
export { default as createIconSetFromIcoMoon } from './lib/create-icon-set-from-icomoon';
=>> pwd
/Users/chen/my-project/node_modules/react-native-vector-icons
/Users/chen/my-project/node_modules/react-native-vector-icons/FontAwesome.js:6
import createIconSet from './lib/create-icon-set';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
While it's fine for Mocha to recognize import in some other files. Could you bundle compiled code in npm package in next release?
update: for example, babel-register normally ignores files in node_modules:
https://github.com/babel/babel/blob/master/packages/babel-register/src/node.js#L87
function shouldIgnore(filename) {
if (!ignore && !only) {
return getRelativePath(filename).split(path.sep).indexOf("node_modules") >= 0;
} else {
return util.shouldIgnore(filename, ignore || [], only);
}
}
function loader(m, filename) {
m._compile(compile(filename), filename);
}
function registerExtension(ext) {
let old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
require.extensions[ext] = function (m, filename) {
if (shouldIgnore(filename)) {
old(m, filename);
} else {
loader(m, filename, old);
}
};
}
No, I don't plan on doing so unfortunately. Here's a link on how to enable babel transforms for mocha et al: https://babeljs.io/docs/setup/
@oblador I already have --compilers js:babel-register in my command line options, your link does not solve the problem, it's more complicated as I described above, the issue of node_modules/.
A possible solution may be http://stackoverflow.com/a/35045012/883571 . But I don't see the reason why you think it's better to put ES6 code in npm package?
I agree that compiled code is preferable in general for npm, but RN projects are somewhat different because they (almost) all use the same babel preprocessor and this is how the vast majority of components do it. If i change it here you'd have the same trouble for the next module and with RN core itself that uses import and is not precompiled on npm.
So that's not a problem we can solve, either compiling or listing package names in testing with Node.js .
@lelandrichardson @vjeux any opinions please?
I'd just fix the mocha precompiler config, use something else like jest or perhaps try the --harmony flag. Don't expect the whole ecosystem to change for your convenience 馃槃
Testing with Mocha is a need of many people. I don't think the team behind React Native intends to break this thing. A solution would be enough.
I know for a fact that people successfully test React Native with Mocha, you just need to fix your config. Closing as this is really a question for stack overflow.
I faced with the same problem, could somebody explain how can I get rid from these issue?
@NikitaSergeevich I was having the same issue earlier today, fixed by using the solution from the linked StackOverflow page regarding the require/ignore combination. As long as mocha doesn't try to compile this library, everything works fine.