Search code examples
expobabeljscypresscode-coverageistanbul

Unable to instrument expo app with istanbul or cypress/instrument


I have been trying this for a while now, without success.

I have an expo app and I am using cypress to test some use cases using the web version of the app (generated by expo).

However, I would like to generate some code coverage as well. I have read the official documentation for it, that recommends to babel-plugin-istanbul do to so, but it does not seem to work with expo.

I am not sure why this would not work.

Edit

I removed the files previously pointed here as they were not important.


Solution

  • Thanks for a wonderful documentation provided by a hero without a cape, I figured that my settings were wrong.

    All I needed to do was:

    1. install babel-plugin-istanbul
    2. Update babel.config.js
    module.exports = {
      presets: ['babel-preset-expo'],
      plugins: [
        'istanbul',
        [
          'module-resolver',
          {
            root: ['.'],
            extensions: [
              '.js',
            ],
            alias: {
              '@': './',
            },
          },
        ],
      ],
    };
    
    1. update cypress/support/index.js
    import '@cypress/code-coverage/support';
    
    
    1. update cypress/plugins/index.js
    module.exports = (on, config) => {
      require('@cypress/code-coverage/task')(on, config);
    
      // add other tasks to be registered here
    
      // IMPORTANT to return the config object
      // with the any changed environment variables
      return config;
    };
    

    and voilà!