Skip to content
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

"istanbul ignore next" over methods of an es6 class #445

Open
ottes opened this issue Sep 16, 2015 · 45 comments
Open

"istanbul ignore next" over methods of an es6 class #445

ottes opened this issue Sep 16, 2015 · 45 comments
Labels

Comments

@ottes
Copy link

ottes commented Sep 16, 2015

Following example says, that doSomething is not covered, but i guess it should be "ignored"

class Foo {
   /* istanbul ignore next */
  doSomething () {
    return 'something';
  }
}

if i move the ignore-comment into the method, the return is ignored, but the function is still uncovered

@davemackintosh
Copy link

+1 to this. Having issues ignoring an inquirer based function and callback which I plan to test at a later date after a refactor.

@vilicvane
Copy link

Found a workaround (spaces before and after the comment seem to be necessary):

class Foo {
  bar /* istanbul ignore next */ () {
    return 'biu~';
  }
}

@gotwarlost gotwarlost added the bug label Nov 22, 2015
@dcrockwell
Copy link

+1

@saschagehlich
Copy link

If you're using babel and mocha, you can use the loose mode for ES6 classes:

{
  "presets": ["es2015"],
  "plugins": [
    ["transform-es2015-classes", {
      "loose": true
    }]
  ]
}

This will generate code like this:

/* istanbul ignore next */
MyClass.prototype.myMethod = function () { }

Which istanbul understands perfectly

EDIT: Otherwise babel would do sth like this:

  _createClass(MyClass, [{
    key: "myMethod",

    /* istanbul ignore next */
    value: function myMethod() {}
  }]);

@atian25
Copy link

atian25 commented Mar 13, 2016

+1 for this

@seanzer
Copy link

seanzer commented Aug 9, 2016

half way through 2016 now.. any update on this?

@tesarm
Copy link

tesarm commented Sep 8, 2016

+1

@davemackintosh
Copy link

This is still an issue, having to put the comment between descriptor and signature is a horrible looking hack I have to say.

@BenDavidJamin
Copy link

BenDavidJamin commented Oct 18, 2016

+1

@hirikarate
Copy link

+1. Beginning of 2017, I am still waiting.

@devboell
Copy link

ye, I have agree with this. I didn't use coverage before, but now that i am using react-boilerplate, I do find it valuable.

I also understand (from a Martin Fowler article) that we shouldn't be neurotic over getting 100% coverage.

However I find it cumbersome to have to go through the whole list of files and percentages, to see wether a lack of coverage comes from files where I expect it to come from, or wether it is a new place where I actually should improve the testing. That's why I want to have it at 100% all the time, so I can see at once if something is wrong or not.
Now I find myself fighting istanbul to get coverage to 100% for places that are hard or unnecessary to test, which is a bit frustrating.

/* istanbul ignore function */
/* istanbul ignore file */
/* istanbul ignore start */
/* istanbul ignore end */

would be great to have!

@krasimir
Copy link

+1 for /* istanbul ignore file */

@vitaly-t
Copy link

class Foo {
  bar /* istanbul ignore next */ () {
    return 'biu~';
  }
}

This work-around doesn't work for this type of code:

.then(data => {
    },
    error /* istanbul ignore next */ => {
       // no matter what, cannot switch coverage off here
    });

@dcmwong
Copy link

dcmwong commented Oct 9, 2017

For es6 react app I just did this:

  const foo = /* istanbul ignore next */ () => {
      return bar;
  }

@MatteoGabriele
Copy link

MatteoGabriele commented Apr 12, 2018

Who's still waiting for this in 2018?

@designbyadrian
Copy link

The following works for my React class using the version of Istanbul that comes with Jest 22.4

/* istanbul ignore next */
componentWillReceiveProps(props) {
    // ...
}

@webia1
Copy link

webia1 commented May 18, 2018

waiting for

/* istanbul ignore function */
/* istanbul ignore file */
/* istanbul ignore start */
/* istanbul ignore end */

greetings from Istanbul,..
May 2018

@jimmycann
Copy link

/* istanbul ignore file */ working well for me.

Currently using nyc v11.9.0

@GitVitor
Copy link

2019 +1

@darioblanco
Copy link

+1 to

/* istanbul ignore function */

It would be amazing. Or just an /* istanbul ignore next */ that works. The workaround does not work for Vue SPC.

As a lot of time has already passed, what about /* constantinople ignore next */?

@thephilwells
Copy link

As a lot of time has already passed, what about /* constantinople ignore next */?

Why they'd change it, I can't say.

@Bekaxp
Copy link

Bekaxp commented Feb 6, 2019

Hi!
I've hit a similar issue... we are using Relay containers (ex. createPaginationContainer) and I am testing only the Component which this HOC wraps. Therefore I would like to ignore the HOC in the coverage.

Here is an example what doesn't work and what works:

This doesn't work:
/* istanbul ignore next */ export default createPaginationContainer( myComponent, { query: graphql '...' }, getVariables: () => (), ...

This works:
export default createPaginationContainer( myComponent, { query: /* istanbul ignore next */ graphql '...' }, getVariables: /* istanbul ignore next */ () => (), ...

The working example is not so nice to see and write... so my question is: Is there anyway to do it like in the first example? Or has the Istanbul team some plans to support such ignores?

Thank you

@alefi87
Copy link

alefi87 commented Feb 13, 2019

Is this issue even being monitored? @gotwarlost
+1

@brycepelletier
Copy link

/* istanbul ignore start */
/* istanbul ignore end */

These two are really all that would be left from the op. They would alleviate the need for convenience the other two file and function commands though. They would be fantastic to have and likely would have garnered more usefulness overall, imho.

/* istanbul ignore file */
/* istanbul ignore function */

These two already exist and work from my testing with my typescript, istanbul, mocha, chia, sinon instance.

@danielsss
Copy link

/* istanbul ignore start /
/
istanbul ignore end */

These two are really all that would be left from the op. They would alleviate the need for convenience the other two file and function commands though. They would be fantastic to have and likely would have garnered more usefulness overall, imho.

/* istanbul ignore file /
/
istanbul ignore function */

These two already exist and work from my testing with my typescript, istanbul, mocha, chia, sinon instance.

@brycepelletier /* istanbul ignore function */ didn't work for me.
what's your version ?

@raffaele-abramini
Copy link

...... 2020

@fr0
Copy link

fr0 commented Jan 10, 2020

...... 2020

I don't think this repo is updated anymore. The last commit was in 2017.

@MatteoGabriele
Copy link

It just became a tradition to come here once a year to check

@guntram
Copy link

guntram commented Jan 23, 2020

"karma-coverage-istanbul-reporter": "~2.0.1"

/* istanbul ignore next */ 
 private myFunction() {...}

works for me in an angular-cli 8 project...

EDIT:
oh, sry!
i just realized that karma-istanbul refers to istanbuljs
:D

@33percent
Copy link

+1 in 2020.

1 similar comment
@alolis
Copy link

alolis commented Apr 12, 2020

+1 in 2020.

@JKobrynski
Copy link

+1 2020

@darioblanco
Copy link

A lot of weird stuff happened in 2020, maybe implementing this issue is one of them 🤔

@MatteoGabriele
Copy link

I think that 2020 is weird enough

@bbehzadi
Copy link

If you are using TypeScript, make sure removeComments in tconfig.json is not set to true.

Oddly enough, when I had removeComments in tconfig.json set to true,

  • using tsc to generate JS file, the JS file still had /* istanbul ignore next */ and not removed
  • /* istanbul ignore next */ was ignored even in JS files which were not generated by tsc

@yasinkocak
Copy link

2021+

macbre added a commit to macbre/phantomas that referenced this issue Jun 2, 2021
@BUPTlhuanyu
Copy link

2021+

/* istanbul ignore next */ not work like this with jest:

  /* istanbul ignore next */
  super(eleNode);

@BUPTlhuanyu
Copy link

SitePen/remap-istanbul#106 (comment)

problem solved by change the target to 'esnext' in tsconfig.json

@lloydjatkinson
Copy link

lloydjatkinson commented Oct 11, 2021

This is also a problem when unit testing Vue component props. Testing the prop defaults is currently tricky with vue-test-utils as the docs are wrong (a separate conversation for their repo).

After much trial and error I figured out the correct magic place to put the /* istanbul ignore next */.

It does not work when placed in the line above, or above example, or above props. It has to go in between the default and the function next to it.

Hope this helps anyone else with Vue/objects containing functions.

export default {
    name: 'ExampleComponent',

    props: {
        example: {
            type: Array,
            required: false,
            default: /* istanbul ignore next */ () => [],
        },
    },
};

@matrunchyk
Copy link

Hello from 2022+, it's been short 7 years of our nice friendship in this topic.
Blessings to all of us, luck and love from Ukraine 🇺🇦 and I guess we'll check in again in a year (Hello to the future dude who'll be posting here on 2023)

@matthewjh
Copy link

Hello! Still having this problem.

@AndreyTheWeb
Copy link

2024

@ManuelRauber
Copy link

2024

@AndreyTheWeb

Just to mention: this version of Istanbul is deprecated, see the README file. So you should not expect that it will get fixed, but rather check the latest version.

@AndreyTheWeb
Copy link

2024

@AndreyTheWeb

Just to mention: this version of Istanbul is deprecated, see the README file. So you should not expect that it will get fixed, but rather check the latest version.

I have this code and I don't understand how to migrate this to NYC

  const coverageFiles = [
    ".cache/coverage/apps/a/coverage-final.json",
    ".cache/coverage/apps/b/coverage-final.json",
    ".cache/coverage/apps/c/coverage-final.json"
  ]
  const outputCoverageFile = ".cache/coverage/coverage.json"

  const mergeCommand = `npx istanbul-merge --out ${outputCoverageFile} ${coverageFiles.join(" ")}`
  execSync(mergeCommand)

Maybe you can explain it to me?

@AndreyTheWeb
Copy link

2024

@AndreyTheWeb

Just to mention: this version of Istanbul is deprecated, see the README file. So you should not expect that it will get fixed, but rather check the latest version.

And I receive a report simply using Jest, as far as I understand istanbul this is the default solution for Jest, I don’t know how to configure jest + nyc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests