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

WIP: feat: add platform-conditional ignore hints #619

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

isaacs
Copy link
Contributor

@isaacs isaacs commented Jul 29, 2021

This adds the ability to create ignore hints that are only effective
on specific platforms, so that we can ignore some test branches that
are only relevant to specific platforms by using a hint like:

/* istanbul ignore next platform!=win32 */
/* istanbul ignore else platform=linux */

and so on.

No tests yet.

This adds the ability to create ignore hints that are only effective
on specific platforms, so that we can ignore some test branches that
are only relevant to specific platforms by using a hint like:

/* istanbul ignore next platform!=win32 */
/* istanbul ignore else platform=linux */
and so on.

No tests yet.
@isaacs
Copy link
Contributor Author

isaacs commented Jul 30, 2021

I don't know if this is something that would be acceptable, or if it should be somehow abstracted to look at navigator.userAgent in web browsers? The syntax is an attractive bikeshed, I tried to keep it as simple as possible to meet the needs I have.

@ljharb
Copy link

ljharb commented Jul 30, 2021

Maybe instead of hardcoding “platform”, conditional ignores could be generic - ie, you put whatever condition name you want in the comment, and the config/command-line invocation would determine whether that condition name is undefined, true, or false, and it’d be a noop when undefined?

@isaacs
Copy link
Contributor Author

isaacs commented Aug 3, 2021

To avoid a breaking change, maybe the syntax could be:

/* istanbul ignore-conditional (file|if|else|next) (condition(s)...) comment */

So the first item that isn't a conditional means the rest is just comment, and users can always use -- to separate out the comment section.

Ignore hint will be valid if ALL conditions are met. (To OR the conditions, use multiple hints.)

Conditions:

  • key=value true if the key is exactly equal to the value specified
  • key!=value true if the key is not exactly equal to the value specified
  • key~=value true if the key contains the value
  • key!~=value true if the key does not contain the value

Some thoughts on extending this to more generic/unbounded set of keys and values might look like this.

Keys and values may be double-quoted, so env.FOO="this is env foo" is valid. Quotes in quoted values may be escaped, so env.QUOTED="this \" contains \" quotes" is valid as well.

Keys available:

  • platform compared with process.platform, or "" if process or process.platform not available.
  • arch compared with process.arch, or "" if process or process.arch not available.
  • env.${KEY} compared with relevant field in process.env, or "" if not available.
  • argv[n] compared with process.argv[n], or "" if not available.

I'm not sure how to go about doing ignores for browsers. Would that entail some kind of run-time handling? Or is instanbul itself sometimes run within a browser context?

The downside of having open-ended values (instead of process.platform or process.arch, which have a small number of possible values) is that the parsing gets more involved, since environment variables and arguments may contain spaces, quotes, and escape characters.

@ljharb
Copy link

ljharb commented Aug 3, 2021

env values can be provided pretty easily by bundlers to browsers, so that might be sufficient?

@bcoe
Copy link
Member

bcoe commented Sep 13, 2021

Just started looking at this repo a little bit again 👍 will make an effort to give this review.

@isaacs
Copy link
Contributor Author

isaacs commented Sep 13, 2021

Just started looking at this repo a little bit again 👍 will make an effort to give this review.

@bcoe awesome! Feel free to ping me on the various slacks if you have any feedback on it.

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

Successfully merging this pull request may close these issues.

None yet

3 participants