From c09b67b232f83c6083588fd00c50ece121a1833a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Tue, 3 Jun 2025 19:31:53 +0200 Subject: [PATCH] docs: Document how to generate and visualize test coverage locally (no-changelog) (#15385) --- .vscode/extensions.json | 1 + CONTRIBUTING.md | 11 ++++++++++- jest.config.js | 2 +- packages/@n8n/vitest-config/frontend.mjs | 25 ++++++++++++++---------- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 0c5abcba47..b2d8e78fe3 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -7,6 +7,7 @@ "EditorConfig.EditorConfig", "esbenp.prettier-vscode", "mjmlio.vscode-mjml", + "ryanluker.vscode-coverage-gutters", "Vue.volar", "vitest.explorer" ] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9985ca3e1e..962e978255 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,9 +19,14 @@ Great that you are here and you want to contribute to n8n - [Actual n8n setup](#actual-n8n-setup) - [Start](#start) - [Development cycle](#development-cycle) - - [Community PR Guidelines](#community-pr-guidelines) + - [Community PR Guidelines](#community-pr-guidelines) + - [**1. Change Request/Comment**](#1-change-requestcomment) + - [**2. General Requirements**](#2-general-requirements) + - [**3. PR Specific Requirements**](#3-pr-specific-requirements) + - [**4. Workflow Summary for Non-Compliant PRs**](#4-workflow-summary-for-non-compliant-prs) - [Test suite](#test-suite) - [Unit tests](#unit-tests) + - [Code Coverage](#code-coverage) - [E2E tests](#e2e-tests) - [Releasing](#releasing) - [Create custom nodes](#create-custom-nodes) @@ -253,6 +258,10 @@ tests of all packages. If you made a change which requires an update on a `.test.ts.snap` file, pass `-u` to the command to run tests or press `u` in watch mode. +#### Code Coverage +We track coverage for all our code on [Codecov](https://app.codecov.io/gh/n8n-io/n8n). +But when you are working on tests locally, we recommend running your tests with env variable `COVERAGE_ENABLED` set to `true`. You can then view the code coverage in the `coverage` folder, or you can use [this VSCode extension](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters) to visualize the coverage directly in VSCode. + #### E2E tests ⚠️ You have to run `pnpm cypress:install` to install cypress before running the tests for the first time and to update cypress. diff --git a/jest.config.js b/jest.config.js index 08f7b93e90..de892145e1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -31,11 +31,11 @@ const config = { setupFilesAfterEnv: ['jest-expect-message'], collectCoverage: isCoverageEnabled, coverageReporters: ['text-summary', 'lcov', 'html-spa'], - collectCoverageFrom: ['src/**/*.ts'], workerIdleMemoryLimit: '1MB', }; if (process.env.CI === 'true') { + config.collectCoverageFrom = ['src/**/*.ts']; config.reporters = ['default', 'jest-junit']; config.coverageReporters = ['cobertura']; } diff --git a/packages/@n8n/vitest-config/frontend.mjs b/packages/@n8n/vitest-config/frontend.mjs index 5e68f23f7a..b2684b4efa 100644 --- a/packages/@n8n/vitest-config/frontend.mjs +++ b/packages/@n8n/vitest-config/frontend.mjs @@ -11,16 +11,12 @@ export const vitestConfig = defineVitestConfig({ globals: true, environment: 'jsdom', setupFiles: ['./src/__tests__/setup.ts'], - ...(process.env.COVERAGE_ENABLED === 'true' - ? { - coverage: { - enabled: true, - provider: 'v8', - reporter: process.env.CI === 'true' ? 'cobertura' : 'text-summary', - all: true, - }, - } - : {}), + coverage: { + enabled: false, + all: false, + provider: 'v8', + reporter: ['text-summary', 'lcov', 'html-spa'], + }, css: { modules: { classNameStrategy: 'non-scoped', @@ -28,3 +24,12 @@ export const vitestConfig = defineVitestConfig({ }, }, }); + +if (process.env.COVERAGE_ENABLED === 'true') { + const { coverage } = vitestConfig.test; + coverage.enabled = true; + if (process.env.CI === 'true') { + coverage.all = true; + coverage.reporter = ['cobertura']; + } +}