istanbuljs / babel-plugin-istanbul

A babel plugin that adds istanbul instrumentation to ES6 code
BSD 3-Clause "New" or "Revised" License
624 stars 73 forks source link

babel-plugin-istanbul no CSP compatibel #212

Closed msteller-connyun closed 4 years ago

msteller-connyun commented 5 years ago

Hey,

as soon I add the istanbul plugin to my babel configuration

      {
        test: /\.js$/,
        include: [/node_modules\/*\/src/, /src/],
        use: {
          loader: 'babel-loader',
           ...
            cacheDirectory: true,
            env: {
              test: {
                plugins: ['istanbul',]
              }
            }
          }
        }
      },

A new Function is added to the code:

  var global = new Function("return this")()

which violates our CSP rules.

coreyfarrell commented 5 years ago

This will ultimately be addressed via #208. This will allow options coverageGlobalScopeFunc: false, coverageGlobalScope: 'window' - which should cause the instrumented code to set global as follows:

var global = window
praveen7557 commented 1 year ago

Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval'".

getting the above error because of var global = new Function("return this")(), anyway to solve this?

just-toby commented 1 year ago

coverageGlobalScopeFunc: false, coverageGlobalScope: 'window'

setting these options causes another babel plugin (vanilla-extract) to fail with this error: ReferenceError: window is not defined. does anyone know a workaround?