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

Vite-plugin-istanbul "requireEnv: false" causes react-unity-webgl stop working.

dmorenoAN opened this issue · comments

Hi, i have been in a trouble with the thing mentioned in title. This plugin has conflicts with "react-unity-webgl".

Not working code

export default defineConfig({
  plugins: [react(), svgr(), istanbul({ cypress: true, requireEnv: false })],
  server: {
    port: 8000,
    host: "0.0.0.0",
  },
});

Working code

export default defineConfig({
  plugins: [react(), svgr(), istanbul({ cypress: true, requireEnv: true})],
  server: {
    port: 8000,
    host: "0.0.0.0",
  },
});

Anyone knows why setting requireEnv to true makes "react-unity-webgl" works? It is a bit annoying.

Thanks.

Hi @dmorenoAN, thanks for the issue!

I don't think the plugin has any conflict with the package mentioned, as it does not jack into Vite as a plugin.

I see that you are using the switch cypress: true which changes the required coverage variable from VITE_COVERAGE to CYPRESS_COVERAGE. requireEnv is really only used to require the environment variable to be set in order to actually do any instrumentation.

The plugin has multiple checks done to prevent instrumentations when building with Vite to only instrument when the dev server is run. Link to the code referenced.

If the plugin is not instrumenting with running with requireEnv: true but with requireEnv: false the case might be that the env variable used for coverage (in this case CYPRESS_COVERAGE) gets set to "false". So this sounds more like a setup issue rather than a bug in the plugin.

If you could, please provide more information about your project setup, or even better a link to a repository so i can replicate the issue. Otherwise i'm afraid that i can't really say for sure whats causing this behaviour.

Thanks!

Hi @iFaxity, i hope so!

I did a basic configuration or none configuration for both plugins, so, i don't think it is a setup bug related.

I reproduced the error in a clean project too with 0 configuration. I deleted it but i can tell you the steps..

Install vite 3.2.3 and initialize a project (react + ts)
Install vite-plugin-istanbul and use it as described in vite.config.ts
Install react-unity-webgl and load the WebGL Unity compilation that i provide you attached (its just an empty example)

App.tsx
const { unityProvider, isLoaded, loadingProgression, requestFullscreen, sendMessage, } = useUnityContext({ loaderUrl: "WebGLExample/Build/build.loader.js", dataUrl: "WebGLExample/Build/build.data", frameworkUrl: "WebGLExample/Build/build.framework.js", codeUrl: "WebGLExample/Build/build.wasm", streamingAssetsUrl: "WebGLExample/StreamingAssets", });

Render
<Unity unityProvider={unityProvider} />

If "requireEnv: false" it won't load, it will get stuck in 90% and will show errors in console. (Unity cannot find any files)

I created an issue in react-unity-webgl too, because i don't know where the error is. There are reproduction steps:
jeffreylanters/react-unity-webgl#465

Thanks mate! 👍
WebGLExample.zip

Closed due to inactivity.