iFaxity / vite-plugin-istanbul

A Vite plugin to instrument code for nyc/istanbul code coverage. In similar way as the Webpack Loader istanbul-instrumenter-loader. Only intended for use in development.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not honor package.json nyc settings

reintroducing opened this issue · comments

I'm migrating from webpack to Vite and using this plugin which instruments the code properly. Unfortunately something I noticed is that it does not support settings set through the nyc key in package.json. Previously, I had this:

"nyc": {
    "exclude": [
        ".storybook",
        "**/stories/*"
    ]
},

When migrating, that no longer works. I think that I can use the exclude option in the plugin config, but it would be great if this plugin also supported the standard nyc key in package.json that is common in a lot of plugins these days. Any chance that this gets added?

Hello @reintroducing!

Absolutely, this didn't really cross my mind when adding the options. I will look into this and add support for the options the plugin supports. As this plugin really supports include, exclude and extension options that nyc uses.

The nyc CLI is both an instrumenter and reporter while this plugin is mearly an instrumenter and relies on Cypress or any other alternative for generating the reports.

After all this plugin is really more like the Webpack plugin istanbul-instrumenter-loader rather than nyc.

@iFaxity Thank you, that would be much appreciated, and thank you in general for this plugin. I certainly appreciate that work that goes into open sourcing code.

The nyc CLI is both an instrumenter and reporter while this plugin is mearly an instrumenter and relies on Cypress or any other alternative for generating the reports.

Ah, that was actually going to be my next question :) I saw a drop in coverage after migrating for the same exact codebase and was wondering why that happened, so it makes sense that in webpack the instrumentation and reporting for my Cypress tests was going through nyc but using this its probably using Cypress itself for half of that process (if I'm understanding correctly). It seems like prior, the Statements coverage was what was being considered to report 100% coverage, whereas now its a combination of Statements, Branches, Functions, and Lines (or some combination of that which I can't figure out, hah). Not sure if there is a way/setting/option to get it to only read Statements again, but some coverage is better than no coverage I suppose.

@reintroducing It is possible to merge different reports together into one.

For example if you have Unit and Integration tests in Jest or Mocha running with nyc on the backend. Also E2E testing in Cypress which uses the Backend API. You can generate 2 reports (one for backend, one for frontend API with Cypress and API). to different directories. Then you can combine them into one report with nyc's CLI.

There are articles out there that can show you this better than I can explain it.

Regarding this issue I have implemented a fix and will be testing it. Hopefully it will be up before next week, I might have to run the testing. If you would be interested I can push the fix in a branch and you could independently test if it is working in your environment as well.

@iFaxity Sure, I'd be glad to help test this in my environment. Just let me know where you put it and I'll give it a go. Thank you.

Here we go @reintroducing, i've created a pull request (#26) for the branch feature/config/nycrc.

Let me know the results of your independent tests.

@iFaxity I tried using it but got the following when running my tests:

Your pluginsFile is invalid: /Users/mprzybylski/Work/fe-coat/cypress/plugins/index.js

It threw an error when required, check the stack trace below:

Error: Cannot find module '/Users/mprzybylski/Work/fe-coat/node_modules/vite-plugin-istanbul/dist/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:353:19)
    at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/mprzybylski/Work/fe-coat/node_modules/@patientpattern/hal/vite/plugins/istanbul.js:1:24)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/mprzybylski/Work/fe-coat/node_modules/@patientpattern/hal/cypress/plugins.js:9:18)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

My package.json has the following:

"vite-plugin-istanbul": "iFaxity/vite-plugin-istanbul#feature/config/nycrc",

Is there some other way I should be pulling it?

Hi @reintroducing, there is not really a way for npm to pull down a package from GitHub without there being a tag (which requires a build from my end and push to the repo).

It would be easier to clone the repo and link it with npm link, then link the package in the project by using npm link vite-plugin-istanbul. Reference: https://docs.npmjs.com/cli/v8/commands/npm-link

Or use file: links. However this also requires cloning the branch and manually build. Then you cna link the module to your project. Reference: https://docs.npmjs.com/cli/v7/configuring-npm/package-json#local-paths