skylock / cypress-angular-coverage-example

31 stars 7 forks source link

Provider alternative for istanbul-instrumenter-loader #6

Open stahloss opened 4 years ago

stahloss commented 4 years ago

istanbul-instrumenter-loader uses really old istanbul-lib-instrument

Please provide an alternative or a way to use a recent version of istanbul-lib-instrument.

stahloss commented 4 years ago

I just got babel-plugin-istanbul working using babel-loader. Maybe it's an idea to update this example?

My coverage.webpack.js:

module.exports = {
    module: {
      rules: [
        {
            test: /\.(js|ts)$/,
            use: {
              loader: 'babel-loader',
              options: {
                // presets: ['@babel/preset-env'],
                plugins: ['babel-plugin-istanbul']
              }
            },
            enforce: 'post',
            include: [
                require('path').join(__dirname, '..', "beheer", 'src', 'app'),
            ],
            exclude: [
                /\.(e2e|spec)\.ts$/,
                /node_modules/,
                /(ngfactory|ngstyle)\.js/
              ]
          }
      ]
    }
  };
jameseg commented 4 years ago

@D0rmouse do you have a working example repo?

stahloss commented 4 years ago

Nope, but just swap the webpack config with the one I posted here and it will work. You need to add the babel-plugin-istanbul devDependency too, of course.

bjuergens commented 2 years ago

can confirm this works.

for me the entire diff for this change looks like like this

--- a/coverage.webpack.js
+++ b/coverage.webpack.js
@@ -7,10 +7,14 @@ module.exports = {
     rules: [
       {
         test: /\.(js|ts)$/,
-        loader: 'istanbul-instrumenter-loader',
-        options: { esModules: true },
+        use: {
+          loader: 'babel-loader',
+          options: {
+            plugins: ['babel-plugin-istanbul']
+          }
+        },
         enforce: 'post',
        include: require('path').join(__dirname, '..', 'src'),
         exclude: [
           /\.(e2e|spec|module|mock)\.ts$/,
           /node_modules/,

and

--- a/package.json
+++ b/package.json
@@ -59,8 +59,8 @@
     "@angular/language-service": "^11.2.14",
     "@types/fingerprintjs2": "^2.0.0",
     "@types/jasmine": "~3.9.0",
+    "babel-plugin-istanbul": "^6.1.1",
     "codelyzer": "^6.0.0",
-    "istanbul-instrumenter-loader": "^3.0.1",
     "jasmine-core": "~3.9.0",
     "jasmine-spec-reporter": "~7.0.0",
     "karma": "~6.3.4",