---
title: "Get Front-End Test Coverage With Cypress - API7.ai"
description: "Background In the article &quot;Stable Product Delivery with Cypress&quot;, we discussed why ..."
url: "https://api7.ai/blog/get-front-end-test-coverage-with-cypress"
---

[Blog](https://api7.ai/blog)

[Products](https://api7.ai/category/products)[Technology](https://api7.ai/category/technology)[Ecosystem](https://api7.ai/category/ecosystem)[Case Study](https://api7.ai/category/usercase)[Team & Community](https://api7.ai/category/community)

Search

⌘ + K

[Blog](https://api7.ai/blog)

Technology

# Get Front-End Test Coverage With Cypress

API7.ai

March 2, 2021

[Technology](https://api7.ai/category/technology)

## Background

In the article ["Stable Product Delivery with Cypress"](https://api7.ai/blog/stable-product-delivery-with-cypress), we discussed why we chose Cypress as our E2E testing framework. After spending nearly two months refining the test cases, we needed test coverage to quantify whether the test coverage was sufficient. This article will describe how to get APISIX Dashboard front-end E2E coverage using Cypress.

## What is code coverage

Code coverage is a metric in software testing that describes the proportion and extent to which the source code in a program is tested, and the resulting proportion is called code coverage. Test code coverage reflects the health of the code to a certain extent.

## Installation Dependencies & Configuration

To collect test coverage data, we need to put some probes in the original business code for Cypress to collect the data.

Cypress officially recommends two approaches, the first is to generate a temporary directory via `nyc` and run the code that has been written to the probe to collect test coverage data. The second way is to do the code conversion in real time through the code conversion pipeline, which eliminates the hassle of temporary folders and makes collecting test coverage data relatively refreshing. We choose the second way to collect front-end E2E coverage.

1. Installing Dependencies

```
yarn add  babel-plugin-istanbul --dev
```

2. Install the cypress plug-in

```
yarn add  @cypress/code-coverage --dev
```

3. Configuring babel

```
// web/config/config.ts
extraBabelPlugins: [
    ['babel-plugin-istanbul',  {
      "exclude": ["**/.umi", "**/locales"]
    }],
  ],
```

4. Configuring Cypress code coverage plugin

```
// web/cypress/plugins/index.js
module.exports = (on, config) => {
  require('@cypress/code-coverage/task')(on, config);
  return config;
};
```

```
// web/cypress/support/index.js
import '@cypress/code-coverage/support';
```

5. Get Test Coverage

After the configuration is done, we need to run the test case. After the test case is run, Cypress will generate `coverage` and `.nyc_output` folders, which contain the test coverage reports.

![1.png](https://static.api7.ai/2022/10/03/633a43f4bb6fd.png?imageMogr2/format/webp)

The test coverage information will appear in the console after executing the following command.

```
npx nyc report --reporter=text-summary
```

![2.png](https://static.api7.ai/2022/10/03/633a43447651f.png?imageMogr2/format/webp)

Under the coverage directory, a more detailed report page will be available, as shown here.

![3.png](https://static.api7.ai/2022/10/03/633a43f513e55.png?imageMogr2/format/webp)

- Statements indicates whether each statement was executed
- Branchs indicates whether each if block was executed
- Functions indicates whether each function is called
- Lines indicates whether each line was executed

## Summary

The test coverage rate reflects the quality of the project to a certain extent. At present, APISIX Dashboard front-end E2E coverage rate has reached 71.57%. We will continue to work with the [community](https://api7.ai/blog/community-over-code-doing-things-the-apache-way) to enhance the test coverage rate and provide more reliable and stable products for users.

Tags:

[APISIX Basics](https://api7.ai/tags/apisix-basics)

[Testing](https://api7.ai/tags/testing)

[Plugin](https://api7.ai/tags/plugin)

Share article link

Share

Related Posts

[![Transforming Log Plugins to Enhance Observability](https://static.api7.ai/uploads/2023/02/24/WZ4YTWDL_87.png)](https://api7.ai/blog/apisix-transforms-logs-for-observability)

## [Transforming Log Plugins to Enhance Observability](https://api7.ai/blog/apisix-transforms-logs-for-observability)

[![Apache APISIX Serverless Plugin for Event Hooks](https://static.api7.ai/uploads/2023/02/15/ssswbIY4_THUMBNAILS_FOR_SERVERLESS_WEBHOOK.png)](https://api7.ai/blog/serverless-plugin-for-event-hooks)

## [Apache APISIX Serverless Plugin for Event Hooks](https://api7.ai/blog/serverless-plugin-for-event-hooks)

Table of Contents

- [Background](#background)
- [What is code coverage](#what-is-code-coverage)
- [Installation Dependencies & Configuration](#installation-dependencies--configuration)
- [Summary](#summary)

## Related Posts

[![Custom Plugin Development For APISIX With Lua And ChatGPT](https://static.api7.ai/uploads/2024/12/25/MssMP69w_custom-plugin-development.png)](https://api7.ai/blog/plugin-development-with-lua-and-chatgpt)

Technology

June 12, 2023

#### [Custom Plugin Development For APISIX With Lua And ChatGPT](https://api7.ai/blog/plugin-development-with-lua-and-chatgpt)

This article will guide you through the process of developing a new custom plugin called file-proxy for APISIX using Lua and ChatGPT.

[API Gateway Concept](https://api7.ai/tags/api-gateway-concept)

[APISIX Basics](https://api7.ai/tags/apisix-basics)

[Plugin](https://api7.ai/tags/plugin)

[![Apache APISIX Authorization Policy: Protect Your APIs](https://static.api7.ai/uploads/2024/12/24/w5yfe0Nu_apisix-authorization-policy.png)](https://api7.ai/blog/apisix-permission-policy)

Technology

April 21, 2023

#### [Apache APISIX Authorization Policy: Protect Your APIs](https://api7.ai/blog/apisix-permission-policy)

The authorization control policies of Apache APISIX can protect the security of your APIs, and ensure your systems run safely and stably.

[APISIX Basics](https://api7.ai/tags/apisix-basics)

[Authentication & Authorization](https://api7.ai/tags/authentication-&-authorization)

[API Gateway Policy](https://api7.ai/tags/api-gateway-policy)

[![Exploring the Benefits of Using an API Gateway for Kafka](https://static.api7.ai/uploads/2023/03/27/mso78761_kafka.png)](https://api7.ai/blog/why-kafka-needs-an-api-gateway)

Technology

March 31, 2023

#### [Exploring the Benefits of Using an API Gateway for Kafka](https://api7.ai/blog/why-kafka-needs-an-api-gateway)

By implementing an API gateway layer in front of Kafka, Apache APISIX offers a range of benefits that enhance the security of Kafka's API while simultaneously reducing the overall cost for developers.

[APISIX Basics](https://api7.ai/tags/apisix-basics)

[Plugin](https://api7.ai/tags/plugin)
