Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-coverage): add tool command, nx helper #495

Merged
merged 7 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ jobs:
cache: npm
- name: Install dependencies
run: npm ci
- name: Collect unit test coverage (temporary due to coverage plugin)
run: npx nx run-many -t unit-test --coverage
- name: Collect Code PushUp report
run: npx nx run-collect
- name: Upload Code PushUp report to portal
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ jobs:
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
npx nx run-many -t=deploy --exclude=plugin-lighthouse,nx-plugin
- name: Collect unit test coverage (temporary due to coverage plugin)
run: npx nx run-many -t unit-test --coverage
- name: Collect and upload Code PushUp report
run: npx nx run-autorun
env:
Expand Down
61 changes: 19 additions & 42 deletions code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
packageJsonPerformanceGroupRef,
packageJsonPlugin,
} from './dist/examples/plugins';
import coveragePlugin from './dist/packages/plugin-coverage';
import coveragePlugin, {
getNxCoveragePaths,
} from './dist/packages/plugin-coverage';
import eslintPlugin, {
eslintConfigFromNxProjects,
} from './dist/packages/plugin-eslint';
Expand Down Expand Up @@ -49,33 +51,20 @@ const config: CoreConfig = {

plugins: [
await eslintPlugin(await eslintConfigFromNxProjects()),
coveragePlugin({
reports: [
{
resultsPath: 'coverage/cli/unit-tests/lcov.info',
pathToProject: 'packages/cli',
},
{
resultsPath: 'coverage/core/unit-tests/lcov.info',
pathToProject: 'packages/core',
},
{
resultsPath: 'coverage/models/unit-tests/lcov.info',
pathToProject: 'packages/models',
},
{
resultsPath: 'coverage/utils/unit-tests/lcov.info',
pathToProject: 'packages/utils',
},
{
resultsPath: 'coverage/plugin-eslint/unit-tests/lcov.info',
pathToProject: 'packages/plugin-eslint',
},
{
resultsPath: 'coverage/plugin-coverage/unit-tests/lcov.info',
pathToProject: 'packages/plugin-coverage',
},
],
await coveragePlugin({
coverageToolCommand: {
command: 'npx',
args: [
'nx',
'run-many',
'-t',
'unit-test',
'integration-test',
'--coverage',
'--skipNxCache',
],
},
reports: await getNxCoveragePaths(['unit-test', 'integration-test']),
}),
fileSizePlugin({
directory: './dist/examples/react-todos-app',
Expand Down Expand Up @@ -114,21 +103,9 @@ const config: CoreConfig = {
title: 'Code coverage',
refs: [
{
type: 'audit',
plugin: 'coverage',
slug: 'function-coverage',
weight: 1,
},
{
type: 'audit',
plugin: 'coverage',
slug: 'branch-coverage',
weight: 1,
},
{
type: 'audit',
type: 'group',
plugin: 'coverage',
slug: 'line-coverage',
slug: 'coverage',
weight: 1,
},
],
Expand Down
19 changes: 3 additions & 16 deletions e2e/cli-e2e/mocks/fixtures/code-pushup.config.coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,16 @@ export default {
title: 'Code coverage',
refs: [
{
type: 'audit',
type: 'group',
plugin: 'coverage',
slug: 'function-coverage',
weight: 1,
},
{
type: 'audit',
plugin: 'coverage',
slug: 'branch-coverage',
weight: 1,
},
{
type: 'audit',
plugin: 'coverage',
slug: 'line-coverage',
slug: 'coverage',
weight: 1,
},
],
},
],
plugins: [
coveragePlugin({
coverageTypes: ['branch', 'function', 'line'],
await coveragePlugin({
reports: [
{
resultsPath: join('e2e', 'cli-e2e', 'mocks', 'fixtures', 'lcov.info'),
Expand Down
105 changes: 57 additions & 48 deletions e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,8 @@ exports[`CLI collect > should run Code coverage plugin and create report.json 1`
"refs": [
{
"plugin": "coverage",
"slug": "function-coverage",
"type": "audit",
"weight": 1,
},
{
"plugin": "coverage",
"slug": "branch-coverage",
"type": "audit",
"weight": 1,
},
{
"plugin": "coverage",
"slug": "line-coverage",
"type": "audit",
"slug": "coverage",
"type": "group",
"weight": 1,
},
],
Expand All @@ -33,91 +21,91 @@ exports[`CLI collect > should run Code coverage plugin and create report.json 1`
{
"audits": [
{
"description": "Branch coverage percentage on the project.",
"description": "Measures how many functions were called in at least one test.",
"details": {
"issues": [
{
"message": "2nd branch is not taken in any test case.",
"message": "Function formatReportScore is not called in any test case.",
"severity": "error",
"source": {
"file": "packages/cli/src/lib/partly-covered/utils.ts",
"position": {
"startLine": 6,
"startLine": 2,
},
},
},
{
"message": "2nd branch is not taken in any test case.",
"message": "Function sortReport is not called in any test case.",
"severity": "error",
"source": {
"file": "packages/cli/src/lib/partly-covered/utils.ts",
"file": "packages/cli/src/lib/not-covered/sorting.ts",
"position": {
"startLine": 10,
"startLine": 1,
},
},
},
],
},
"displayValue": "60 %",
"score": 0.6,
"slug": "function-coverage",
"title": "Function coverage",
"value": 60,
},
{
"description": "Measures how many branches were executed after conditional statements in at least one test.",
"details": {
"issues": [
{
"message": "1st branch is not taken in any test case.",
"message": "2nd branch is not taken in any test case.",
"severity": "error",
"source": {
"file": "packages/cli/src/lib/not-covered/sorting.ts",
"file": "packages/cli/src/lib/partly-covered/utils.ts",
"position": {
"startLine": 7,
"startLine": 6,
},
},
},
{
"message": "2nd branch is not taken in any test case.",
"severity": "error",
"source": {
"file": "packages/cli/src/lib/not-covered/sorting.ts",
"file": "packages/cli/src/lib/partly-covered/utils.ts",
"position": {
"startLine": 7,
"startLine": 10,
},
},
},
],
},
"displayValue": "76 %",
"score": 0.7647,
"slug": "branch-coverage",
"title": "Branch coverage",
"value": 76,
},
{
"description": "Function coverage percentage on the project.",
"details": {
"issues": [
{
"message": "Function formatReportScore is not called in any test case.",
"message": "1st branch is not taken in any test case.",
"severity": "error",
"source": {
"file": "packages/cli/src/lib/partly-covered/utils.ts",
"file": "packages/cli/src/lib/not-covered/sorting.ts",
"position": {
"startLine": 2,
"startLine": 7,
},
},
},
{
"message": "Function sortReport is not called in any test case.",
"message": "2nd branch is not taken in any test case.",
"severity": "error",
"source": {
"file": "packages/cli/src/lib/not-covered/sorting.ts",
"position": {
"startLine": 1,
"startLine": 7,
},
},
},
],
},
"displayValue": "60 %",
"score": 0.6,
"slug": "function-coverage",
"title": "Function coverage",
"value": 60,
"displayValue": "76 %",
"score": 0.7647,
"slug": "branch-coverage",
"title": "Branch coverage",
"value": 76,
},
{
"description": "Line coverage percentage on the project.",
"description": "Measures how many lines of code were executed in at least one test.",
"details": {
"issues": [
{
Expand Down Expand Up @@ -153,6 +141,27 @@ exports[`CLI collect > should run Code coverage plugin and create report.json 1`
],
"description": "Official Code PushUp code coverage plugin.",
"docsUrl": "https://www.npmjs.com/package/@code-pushup/coverage-plugin/",
"groups": [
{
"description": "Group containing all defined coverage types as audits.",
"refs": [
{
"slug": "function-coverage",
"weight": 6,
},
{
"slug": "branch-coverage",
"weight": 3,
},
{
"slug": "line-coverage",
"weight": 1,
},
],
"slug": "coverage",
"title": "Code coverage metrics",
},
],
"icon": "folder-coverage-open",
"packageName": "@code-pushup/coverage-plugin",
"slug": "coverage",
Expand Down
3 changes: 3 additions & 0 deletions examples/plugins/vite.config.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineConfig({
cache: {
dir: '../../node_modules/.vitest',
},
coverage: {
reporter: ['lcov'],
},
environment: 'node',
include: ['src/**/*.integration.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globalSetup: ['global-setup.ts'],
Expand Down
3 changes: 3 additions & 0 deletions examples/plugins/vite.config.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineConfig({
cache: {
dir: '../../node_modules/.vitest',
},
coverage: {
reporter: ['lcov'],
},
environment: 'node',
include: ['src/**/*.unit.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globalSetup: ['global-setup.ts'],
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/vite.config.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineConfig({
cache: {
dir: '../../node_modules/.vitest',
},
coverage: {
reporter: ['lcov'],
},
environment: 'node',
include: ['src/**/*.integration.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globalSetup: ['global-setup.ts'],
Expand Down
3 changes: 3 additions & 0 deletions packages/core/vite.config.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineConfig({
cache: {
dir: '../../node_modules/.vitest',
},
coverage: {
reporter: ['lcov'],
},
environment: 'node',
include: ['src/**/*.integration.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globalSetup: ['global-setup.ts'],
Expand Down
3 changes: 3 additions & 0 deletions packages/models/vite.config.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineConfig({
cache: {
dir: '../../node_modules/.vitest',
},
coverage: {
reporter: ['lcov'],
},
environment: 'node',
include: ['src/**/*.integration.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globalSetup: ['global-setup.ts'],
Expand Down
3 changes: 3 additions & 0 deletions packages/nx-plugin/vite.config.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineConfig({
cache: {
dir: '../../node_modules/.vitest',
},
coverage: {
reporter: ['lcov'],
},
environment: 'node',
include: ['src/**/*.integration.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
setupFiles: [
Expand Down
3 changes: 3 additions & 0 deletions packages/nx-plugin/vite.config.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineConfig({
cache: {
dir: '../../node_modules/.vitest',
},
coverage: {
reporter: ['lcov'],
},
environment: 'node',
include: ['src/**/*.unit.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
setupFiles: [
Expand Down
Loading