Giter VIP home page Giter VIP logo

nx-cypress-angular-code-coverage's Introduction

NX-Cypress-Angular-Code-Coverage Example

This repo shows a minimal working example of generating Code Coverage for an Angular app withing a NX Monorepo.

Steps to follow

Install packages

npm i @cypress/code-coverage -D
npm i @jsdevtools/coverage-istanbul-loader -D

Adjust project.json of the tested app and create extenstion of webpack.

In project.json change the executor of build target to webpack-browser

"executor": "@nx/angular:webpack-browser",

And the executor of serve target to webpack-dev-server

 "executor": "@nx/angular:webpack-dev-server",

Add customWebpack to build target

"customWebpackConfig": {
    "path": "apps/myapp/webpack.config.js"
}

Create webpack.config.js in the app directory

module.exports = (webpackConfig) => {
  return {
    ...webpackConfig,

    module: {
      rules: [
        // Istanbul Instrumentation rule
        ...webpackConfig.module.rules,
        {
          test: /\.(js|ts)$/,
          loader: '@jsdevtools/coverage-istanbul-loader',
          options: { esModules: true },
          enforce: 'post',
          include: [require('path').join(__dirname, '/src')],
          exclude: [/\.(e2e|spec|cy)\.ts$/, /node_modules/, /(ngfactory|ngstyle)\.js/],
        },
      ],
    },
  }
}

Add cypress/coverage task to cypress.config.ts

import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';

export default defineConfig({
  e2e: nxE2EPreset(__dirname),
  e2e: {
    ...nxE2EPreset(__dirname),
    setupNodeEvents: (on, config) => {
      require('@cypress/code-coverage/task')(on, config)

      return config;
    },

  },
});

Import cypress/coverage in support/e2e.ts

import '@cypress/code-coverage/support'

Run tests with coverage

nx e2e myapp-e2e

After running tests the coverage output will be generated under apps/myapp-e2e/coverage

nx-cypress-angular-code-coverage's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.