From e3b5f1d918c8733cf3bd351d386d6265ebf3b940 Mon Sep 17 00:00:00 2001 From: Jeeva Ramachandran <120017870+JeevaRamu0104@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:43:31 +0530 Subject: [PATCH] chore: add cypress coverage (#443) --- .babelrc | 2 ++ .github/workflows/cypress-test.yml | 5 ++++- .gitignore | 4 +++- cypress.config.js | 7 ++++++- cypress/support/e2e.js | 1 + package.json | 4 ++++ webpack.common.js | 9 +++++++++ 7 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.babelrc b/.babelrc index 15af723b9..41c31bb8e 100644 --- a/.babelrc +++ b/.babelrc @@ -11,6 +11,8 @@ } } ], + "transform-class-properties", + "istanbul", "@babel/plugin-transform-async-to-generator" ] } diff --git a/.github/workflows/cypress-test.yml b/.github/workflows/cypress-test.yml index aa2de9652..42d9a0e46 100644 --- a/.github/workflows/cypress-test.yml +++ b/.github/workflows/cypress-test.yml @@ -1,7 +1,6 @@ name: Cypress Tests on: - merge_group: pull_request: jobs: @@ -46,3 +45,7 @@ jobs: install: false build: npm run build:test start: npm run test:start + + - name: Check Coverage Thresholds + run: | + npx nyc check-coverage --lines 50 --functions 50 --branches 50 --statements 50 diff --git a/.gitignore b/.gitignore index d2c865bb4..d42145633 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,6 @@ package-lock.json screenshots hyperswitch/ downloads -.env \ No newline at end of file +.env +.nyc_output +coverage \ No newline at end of file diff --git a/cypress.config.js b/cypress.config.js index 186b76c0f..e9d7519de 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -2,7 +2,12 @@ const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { - // implement node event listeners here + require("@cypress/code-coverage/task")(on, config); + // include any other plugin code... + + // It's IMPORTANT to return the config object + // with any changed environment variables + return config; }, }, env: { diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 3a2522438..f19936bde 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -14,6 +14,7 @@ // *********************************************************** // Import commands.js using ES2015 syntax: +import "@cypress/code-coverage/support"; import "./commands"; // Alternatively you can use CommonJS syntax: diff --git a/package.json b/package.json index a72de707c..e4cfa52ef 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,10 @@ } }, "devDependencies": { + "@cypress/code-coverage": "^3.12.24", "@eslint/create-config": "0.4.6", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.1", + "babel-plugin-istanbul": "^6.1.1", "copy-webpack-plugin": "^9.0.0", "css-loader": "^5.0.1", "css-minimizer-webpack-plugin": "^5.0.1", @@ -39,9 +41,11 @@ "eslint-plugin-react-hooks": "^4.6.0", "file-loader": "^6.2.0", "husky": "^8.0.3", + "istanbul-instrumenter-loader": "^3.0.1", "mini-css-extract-plugin": "^1.3.1", "monaco-editor-webpack-plugin": "^7.0.1", "node-fetch": "^2.6.1", + "nyc": "^15.1.0", "postcss": "^8.3.6", "postcss-loader": "^4.1.0", "postcss-preset-env": "^6.7.0", diff --git a/webpack.common.js b/webpack.common.js index bf5eed53d..fd69148cf 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -47,6 +47,15 @@ module.exports = (appName = "hyperswitch", publicPath = "auto") => { test: /\.ttf$/, use: ["file-loader"], }, + { + test: /\.js$/, + use: { + loader: "istanbul-instrumenter-loader", + options: { esModules: true }, + }, + enforce: "post", + exclude: /node_modules|\.spec\.js$/, + }, ], }, plugins: [