istanbuljs/istanbuljs

Instrument Only Function , Methods , Classes and Modules to reduce instrumented code size

Opened this issue · 0 comments

As of now istanbul cli / nyc config doesn't have optional parameter to ignore other statement like for loop, branches, variable declaration etc. Using ignore comments in every file is also not a good way to approach this problem.

by default its instrumenting everything and application size is 2~3 times larger than actual codebase and hence its impacting application performance while running e2e test cases.

May be some parameter ex : --ignoreIfStatement=true/false , --ignoreForLoop=true/false can be passed in cli or in nyc config to avoid selective instrumentation.

const codeVisitor = {
    ArrowFunctionExpression: entries(convertArrowExpression, coverFunction),
    // AssignmentPattern: entries(coverAssignmentPattern),
    // BlockStatement: entries(), // ignore processing only
    ExportDefaultDeclaration: entries(), // ignore processing only
    ExportNamedDeclaration: entries(), // ignore processing only
    ClassMethod: entries(coverFunction),
    ClassDeclaration: entries(parenthesizedExpressionProp('superClass')),
    // ClassProperty: entries(coverClassPropDeclarator),
    // ClassPrivateProperty: entries(coverClassPropDeclarator)
    ObjectMethod: entries(coverFunction),
    // ExpressionStatement: entries(coverStatement),
    // BreakStatement: entries(coverStatement),
    // ContinueStatement: entries(coverStatement),
    // DebuggerStatement: entries(coverStatement),
    // ReturnStatement: entries(coverStatement),
    // ThrowStatement: entries(coverStatement),
    // TryStatement: entries(coverStatement),
    // VariableDeclaration: entries(), // ignore processing only
    // VariableDeclarator: entries(coverVariableDeclarator),
    // IfStatement: entries(
    //     blockProp('consequent'),
    //     blockProp('alternate'),
    //     coverStatement,
    //     coverIfBranches
    // ),
    // ForStatement: entries(blockProp('body'), coverStatement),
    // ForInStatement: entries(blockProp('body'), coverStatement),
    // ForOfStatement: entries(blockProp('body'), coverStatement),
    // WhileStatement: entries(blockProp('body'), coverStatement),
    // DoWhileStatement: entries(blockProp('body'), coverStatement),
    // SwitchStatement: entries(createSwitchBranch, coverStatement),
    // SwitchCase: entries(coverSwitchCase),
    // WithStatement: entries(blockProp('body'), coverStatement),
    FunctionDeclaration: entries(coverFunction),
    FunctionExpression: entries(coverFunction),
    // LabeledStatement: entries(coverStatement),
    // ConditionalExpression: entries(coverTernary),
    // LogicalExpression: entries(coverLogicalExpression)
};

we have tried instrumentation with above raw changes in packages/istanbul-lib-instrument/src/visitor.js and instrumented codebase size is reduced comparatively.