This works around an issue where using Istanbul with the noop instrumenter means it will try to parse your code with a hard-coded Babel config that may not work (especially if the code it's trying to parse is TypeScript).
This kludges the problem away by using patch-package in a post-install script to patch
istanbul-lib-instrument to look for an environment variable pointing to your Babel config file, and a one-line patch to
nyc to make it pass the filename when calling the patched functions in
istanbul-lib-instrment (otherwise it will fail if your babel config includes
To use this, setup patch-package as shown in their README, then make a
patches directory in your repo and drop these two patch files into it. Then just running
npm install) should be enough to do the patching. Then you just have to make sure that
$ISTANBUL_BABEL_CONFIG is set to the path to your babel config file when you run your tests.
yarn add -DW patch-package jq '.scripts.postinstall = "patch-package"' package.json | sponge package.json mkdir patches curl -LO https://gist.github.com/jasonk/.../istanbul-lib-instrument+4.0.3.patch curl -LO https://gist.github.com/jasonk/.../nyc+15.1.0.patch # (Get the right URLs by right-clicking on the "Raw" buttons for each file below) cd .. yarn export ISTANBUL_BABEL_CONFIG="$(realpath -P ./babel.config.js)" # now you can run your tests or whatever...
Note that the patch files have package version embedded in them, so these patches will only work with those specific versions of the packages they patch.