jedireza / hapi-react-views

:package: A hapi view engine for React components
MIT License
231 stars 33 forks source link

Coverage is suppressed when loading `babel-register` #45

Closed prashaantt closed 8 years ago

prashaantt commented 8 years ago

I recently opened an issue on Lab that doesn't seem to really have anything to do with it. Since I encountered this while working with hapi-react-views, I thought I'd throw this here too, just in case.

Looks like Lab doesn't also report coverage errors if I comment out any fixtures in hapi-react-views itself. It begins to care about coverage only if I comment out the require('babel-register') (of course in addition to other test failures).

In my own test project I've tried requiring babel-register inside of a dummy plugin, and then registering it at the end after all the other plugins:


// babel-registrar.js

require('babel-register')({
    presets: ['react', 'es2015']
});

exports.register = function (server, options, next) {

    next();
};

exports.register.attributes = {
    name: 'babel-registrar'
};
// manifest.js

...
plugins: {
    'vision': {},
    'visionary': {...},
    ...,
    './babel-registrar': {}
}
...

This somehow defers whatever's causing this issue and makes Lab start reporting coverage again. Would you know what may be the problem and if there's a better way to fix this?

jedireza commented 8 years ago

Hmm. Babel registration needs to happen at the top level of your app (not in a plugin). You cannot guarantee the order in which plugins are called with manifests.

Have you checked out lab-babel?

prashaantt commented 8 years ago

Thanks, I didn't know of lab-babel, will check it out.

Meantime, I've been digging some more and transpiling ahead of time using the Babel API with a build tool (such as gulp) appears to be the better way, which also obviates this issue altogether.

prashaantt commented 8 years ago

I closed a little too soon, but I had a related question in mind. What would be your config to let hapi-react-views use pre-transpiled JSX? I came up with this:

server.register(require('vision'), (err) => {
    server.views({
        engines: {
            js: require('hapi-react-views')
        }
    });
}

But I don't know if this will lead to any performance issues since it might start looking at all .js files.

jedireza commented 8 years ago

Seems like you got it right. You can make the extensions anything you want.