istanbuljs / babel-plugin-istanbul

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

babel-plugin-istanbul not following CSP directive, Refused to evaluate a string as JavaScript because 'unsafe-eval' #281

Open praveen7557 opened 1 year ago

praveen7557 commented 1 year ago

I am getting the error 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'" while adding babel-plugin-istanbul to a chrome extension which uses manifest v3 which doesn't allow eval function.

But, the package adds var global = new Function("return this")() to the background.js file. Is there any way to solve this?

just-toby commented 1 year ago

i'm also having trouble getting this working with my setup.

coverageGlobalScopeFunc: false, coverageGlobalScope: 'window'

setting these options fixes the CSP error, but causes another babel plugin (vanilla-extract) to fail with this error: ReferenceError: window is not defined.

babel-plugin-istanbul seems to be adding instrumentation to my vanilla extract css.ts files. when i exclude these files in the istanbul options, it avoids most of the files, but not all for some reason. this is my setup:

  babel: {
    plugins: [
      [
        'istanbul',
        {
          coverageGlobalScopeFunc: false,
          coverageGlobalScope: 'window',
          'report-dir': 'coverage',
          all: true,
          useInlineSourceMaps: false,
          extends: '@istanbuljs/nyc-config-typescript',
          include: ['src/**/*.tsx', 'src/**/*.ts'],
          exclude: [
            'src/**/*.css',
            'src/**/*.css.ts',
            'src/**/*.test.ts',
            'src/**/*.test.tsx',
            'src/**/*.spec.ts',
            'src/**/*.spec.tsx',
            'src/**/graphql/**/*',
            'src/**/*.d.ts',
          ],
        },
      ],
    ],
  },