Skip to content

Commit

Permalink
Merge branch 'split-coverage-e2e' into split-eslint-e2e
Browse files Browse the repository at this point in the history
# Conflicts:
#	e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap
#	e2e/cli-e2e/tests/collect.e2e.test.ts
#	nx.json
  • Loading branch information
BioPhoton committed Nov 18, 2024
2 parents fa90bcd + d165ddd commit d451294
Show file tree
Hide file tree
Showing 17 changed files with 655 additions and 495 deletions.
419 changes: 0 additions & 419 deletions e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions e2e/cli-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import {
type AuditReport,
type PluginReport,
Expand Down Expand Up @@ -49,59 +47,6 @@ describe('CLI collect', () => {
await cleanTestFolder('tmp/e2e/react-todos-app');
});

it('should run Code coverage plugin which collects passed results and creates report.json', async () => {
/**
* The stats passed in the fixture are as follows
* 3 files: one partially covered, one with no coverage, one with full coverage
* Functions: 2 + 1 + 2 found | 1 + 0 + 2 covered (60% coverage)
* Branches: 10 + 2 + 5 found | 8 + 0 + 5 covered (76% coverage)
* Lines: 10 + 5 + 10 found | 7 + 0 + 10 covered (68% coverage)
*/

const configPath = join(
fileURLToPath(dirname(import.meta.url)),
'..',
'mocks',
'fixtures',
'code-pushup.config.ts',
);

const { code, stderr } = await executeProcess({
command: 'code-pushup',
args: [
'collect',
'--no-progress',
`--config=${configPath}`,
'--persist.outputDir=tmp/e2e',
'--onlyPlugins=coverage',
],
});

expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile(join('tmp', 'e2e', 'report.json'));

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});

it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
args: ['collect', '--no-progress', '--onlyPlugins=coverage'],
cwd: 'examples/react-todos-app',
});

expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});

it('should create report.md', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
Expand Down
12 changes: 12 additions & 0 deletions e2e/plugin-coverage-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*", "code-pushup.config*.ts"],
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parserOptions": {
"project": ["e2e/plugin-coverage-e2e/tsconfig.*?.json"]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import coveragePlugin from '@code-pushup/coverage-plugin';

export default {
plugins: [
await coveragePlugin({
reports: ['coverage/lcov.info'],
coverageToolCommand: {
command: 'npm',
args: ['run', 'test'],
},
}),
],
categories: [
{
slug: 'code-coverage',
title: 'Code coverage',
refs: [
{
type: 'group',
plugin: 'coverage',
slug: 'coverage',
weight: 1,
},
],
},
],
};
13 changes: 13 additions & 0 deletions e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "coverage-e2e-env",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "npx vitest run --coverage"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {},
"description": ""
}
15 changes: 15 additions & 0 deletions e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/src/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function untested() {
console.log('This function is not tested');
}

export function get42() {
return 42;
}

export function isEven(num) {
if (num === undefined) {
return false;
}
const parsedNumber = parseInt(num, 10);
return parsedNumber % 2 === 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, expect, it } from 'vitest';
import { get42, isEven, untested } from './index.mjs';

describe('get42', () => {
it('should return 42', async () => {
expect(get42()).toBe(42);
});
});

describe('isEven', () => {
it('should return true for even number 42', async () => {
expect(isEven(42)).toBe(true);
});

it.todo('should return false for odd number 1');
});

describe.todo('untested', () => {});
25 changes: 25 additions & 0 deletions e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// <reference types="vitest" />
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite';

export default defineConfig({
root: fileURLToPath(dirname(import.meta.url)),
cacheDir: 'node_modules/.vite/coverage-e2e-env',

test: {
reporters: ['basic'],
globals: true,
cache: {
dir: 'node_modules/.vitest',
},
coverage: {
reporter: ['lcov', 'text'],
provider: 'v8',
reportsDirectory: 'coverage',
include: ['src/**/*.{js,mjs}'],
},
environment: 'node',
include: ['src/**/*.{test,spec}.{js,mjs}'],
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { join } from 'node:path';
import coveragePlugin from '@code-pushup/coverage-plugin';
import type { CoreConfig } from '@code-pushup/models';

export default {
plugins: [
await coveragePlugin({
reports: [join('coverage', 'lcov.info')],
}),
],
categories: [
{
slug: 'code-coverage',
title: 'Code coverage',
refs: [
{
type: 'group',
plugin: 'coverage',
slug: 'coverage',
weight: 1,
},
],
},
],
} satisfies CoreConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
TN:
SF:src\lib\partly-covered\utils.ts
FN:2,formatReportScore
FN:6,calcDuration
FNF:2
FNH:1
FNDA:0,formatReportScore
FNDA:6,calcDuration
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,0
DA:8,0
DA:9,0
DA:10,1
LF:10
LH:7
BRDA:1,0,0,6
BRDA:1,1,0,5
BRDA:2,4,0,1
BRDA:4,5,0,17
BRDA:5,6,0,4
BRDA:6,7,0,13
BRDA:6,10,1,0
BRDA:7,11,0,3
BRDA:10,12,0,12
BRDA:10,13,1,0
BRF:10
BRH:8
end_of_record
SF:src\lib\not-covered\sorting.ts
FN:1,sortReport
FNF:1
FNH:0
FNDA:0,sortReport
DA:1,0
DA:2,0
DA:3,0
DA:4,0
DA:5,0
LF:5
LH:0
BRDA:7,1,0,0
BRDA:7,2,1,0
BRF:2
BRH:0
end_of_record
TN:
SF:src\lib\fully-covered\scoring.ts
FN:2,scoreReport
FN:8,calculateScore
FNF:2
FNH:2
FNDA:3,scoreReport
FNDA:5,calculateScore
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,1
DA:8,1
DA:9,1
DA:10,1
LF:10
LH:10
BRDA:1,0,0,5
BRDA:2,1,0,1
BRDA:2,2,1,4
BRDA:2,3,2,3
BRDA:6,4,0,4
BRF:5
BRH:5
end_of_record
23 changes: 23 additions & 0 deletions e2e/plugin-coverage-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "plugin-coverage-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/plugin-coverage-e2e/src",
"projectType": "application",
"targets": {
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["e2e/plugin-coverage-e2e/**/*.ts"]
}
},
"e2e": {
"executor": "@nx/vite:test",
"options": {
"configFile": "e2e/plugin-coverage-e2e/vite.config.e2e.ts"
}
}
},
"implicitDependencies": ["cli", "plugin-coverage"],
"tags": ["scope:plugin", "type:e2e"]
}
Loading

0 comments on commit d451294

Please sign in to comment.