jeffrifwald / babel-istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
144 stars 23 forks source link

Doesn't recognize static properies #75

Closed roastedfrost-zz closed 7 years ago

roastedfrost-zz commented 7 years ago

fails on

class Klass {
    static props = {
        prop: 'value'
    }
}

but ok with

class Klass {
}
Klass.props = {
    prop: 'value'
};

Used with babel-istanbul-instrumenter-loader (with updated babel-istanbul dependency).

jeffrifwald commented 7 years ago

Hi @roastedfrost,

By fails, do you mean it won't even run or it produces incorrect instrumentation? Also, what version of babel are you using? Thanks!

roastedfrost-zz commented 7 years ago

Hi @jmcriffey,

I'm using babel-core v. 5.8.38. It fails with syntax error (unexpected token) and without coverage output.

"babel-core": "5.8.38",
"babel-istanbul-instrumenter-loader": "1.0.1",
"babel-loader": "5.4.2",
"babel-polyfill": "6.13.0",
"babel-runtime": "5.8.38",

But there aren't fails with static props during code execution, only for code instrumentation.

jeffrifwald commented 7 years ago

Try adding a semicolon to the end of your static prop. Also make sure you are using babel-plugin-transform-class-properties .

class Klass {
    static props = {
        prop: 'value'
    };
}
roastedfrost-zz commented 7 years ago

I'm sorry, everything is ok! I forgot to pass babel config into instrumenter.

    var babelConfig = {
        presets: [
            [require.resolve('babel-preset-es2015'), {loose: true}],
            require.resolve('babel-preset-stage-0'),
            require.resolve('babel-preset-react')
        ],
        plugins: [
            require.resolve('babel-plugin-add-module-exports'),
            require.resolve('babel-plugin-transform-decorators-legacy'),
            require.resolve('babel-plugin-transform-class-properties')                            
        ]
    };

    return instrumenter.instrumentSync(source, this.resourcePath, babelConfig);