Skip to content

Commit 7a80f85

Browse files
committed
polish integration tests
1 parent da133e9 commit 7a80f85

File tree

12 files changed

+166
-351
lines changed

12 files changed

+166
-351
lines changed

e2e/plugin-doc-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

Lines changed: 0 additions & 201 deletions
This file was deleted.

e2e/plugin-doc-coverage-e2e/tests/collect.e2e.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import {
88
E2E_ENVIRONMENTS_DIR,
99
TEST_OUTPUT_DIR,
1010
omitVariableReportData,
11+
removeColorCodes,
1112
} from '@code-pushup/test-utils';
12-
import { executeProcess, readJsonFile } from '@code-pushup/utils';
13+
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
1314

1415
describe('PLUGIN collect report with doc-coverage-plugin NPM package', () => {
1516
const fixturesDir = path.join(
@@ -47,19 +48,33 @@ describe('PLUGIN collect report with doc-coverage-plugin NPM package', () => {
4748
});
4849

4950
it('should run Doc Coverage plugin for Angular example dir and create report.json', async () => {
50-
const { code } = await executeProcess({
51+
const { code, stdout } = await executeProcess({
5152
command: 'npx',
5253
args: ['@code-pushup/cli', 'collect', '--no-progress'],
5354
cwd: angularDir,
5455
});
5556

5657
expect(code).toBe(0);
5758

59+
expect(removeColorCodes(stdout)).toMatchFileSnapshot(
60+
'__snapshots__/report.txt',
61+
);
62+
5863
const report = await readJsonFile(
5964
path.join(angularOutputDir, 'report.json'),
6065
);
6166

6267
expect(() => reportSchema.parse(report)).not.toThrow();
63-
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
68+
expect(
69+
JSON.stringify(omitVariableReportData(report as Report), null, 2),
70+
).toMatchFileSnapshot('__snapshots__/report.json');
71+
72+
const reportMd = await readTextFile(
73+
path.join(angularOutputDir, 'report.md'),
74+
);
75+
76+
expect(reportMd.replace(/## About\.*/gm, '')).toMatchFileSnapshot(
77+
'__snapshots__/report.md',
78+
);
6479
});
6580
});

packages/plugin-doc-coverage/mocks/fixtures/filled-documentation/properties-coverage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export class ExampleWithProperties {
44
* Internal identifier that can only be accessed within this class
55
* @private
66
*/
7-
private readonly internalId = '123';
7+
private readonly exampleProperty = '123';
88
}

packages/plugin-doc-coverage/mocks/fixtures/missing-documentation/methods-coverage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
export class Container {
1+
/**
2+
* A class that serves as an example for documentation coverage testing
3+
*/
4+
export class ExampleClass {
25
exampleMethod(): string {
36
return 'exampleMethod';
47
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* A class that serves as an example for documentation coverage testing
3+
*/
14
export class ExampleWithProperties {
2-
private readonly internalId = '123';
5+
private readonly exampleProperty = '123';
36
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {SyntaxKind,} from 'ts-morph';
2+
import type {CoverageType} from '../src/lib/runner/models.js';
3+
4+
export function nodeMock(options: {
5+
coverageType: CoverageType;
6+
line: number;
7+
file: string;
8+
isCommented: boolean;
9+
}) {
10+
return {
11+
getKind: () => getKindFromCoverageType(options.coverageType),
12+
getJsDocs: () => (options.isCommented ? ['Comment'] : []),
13+
getName: () => 'test',
14+
getStartLineNumber: () => options.line,
15+
getDeclarations: () => [],
16+
// Only for classes
17+
getMethods: () => [],
18+
getProperties: () => [],
19+
};
20+
}
21+
22+
function getKindFromCoverageType(coverageType: CoverageType): SyntaxKind {
23+
switch (coverageType) {
24+
case 'classes':
25+
return SyntaxKind.ClassDeclaration;
26+
case 'methods':
27+
return SyntaxKind.MethodDeclaration;
28+
case 'functions':
29+
return SyntaxKind.FunctionDeclaration;
30+
case 'interfaces':
31+
return SyntaxKind.InterfaceDeclaration;
32+
case 'enums':
33+
return SyntaxKind.EnumDeclaration;
34+
case 'variables':
35+
return SyntaxKind.VariableDeclaration;
36+
case 'properties':
37+
return SyntaxKind.PropertyDeclaration;
38+
case 'types':
39+
return SyntaxKind.TypeAliasDeclaration;
40+
default:
41+
throw new Error(`Unsupported syntax kind: ${coverageType}`);
42+
}
43+
}

packages/plugin-doc-coverage/mocks/source-files-mock.generator.ts renamed to packages/plugin-doc-coverage/mocks/source-files.mock.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
VariableStatement,
1010
} from 'ts-morph';
1111
import type { CoverageType } from '../src/lib/runner/models.js';
12+
import {nodeMock} from "./node.mock";
1213

1314
export function sourceFileMock(
1415
file: string,
@@ -39,44 +40,3 @@ export function sourceFileMock(
3940
createNodeGetter<VariableStatement>('variables', nodes.variables),
4041
} as SourceFile;
4142
}
42-
43-
export function nodeMock(options: {
44-
coverageType: CoverageType;
45-
line: number;
46-
file: string;
47-
isCommented: boolean;
48-
}) {
49-
return {
50-
getKind: () => getKindFromCoverageType(options.coverageType),
51-
getJsDocs: () => (options.isCommented ? ['Comment'] : []),
52-
getName: () => 'test',
53-
getStartLineNumber: () => options.line,
54-
getDeclarations: () => [],
55-
// Only for classes
56-
getMethods: () => [],
57-
getProperties: () => [],
58-
};
59-
}
60-
61-
function getKindFromCoverageType(coverageType: CoverageType): SyntaxKind {
62-
switch (coverageType) {
63-
case 'classes':
64-
return SyntaxKind.ClassDeclaration;
65-
case 'methods':
66-
return SyntaxKind.MethodDeclaration;
67-
case 'functions':
68-
return SyntaxKind.FunctionDeclaration;
69-
case 'interfaces':
70-
return SyntaxKind.InterfaceDeclaration;
71-
case 'enums':
72-
return SyntaxKind.EnumDeclaration;
73-
case 'variables':
74-
return SyntaxKind.VariableDeclaration;
75-
case 'properties':
76-
return SyntaxKind.PropertyDeclaration;
77-
case 'types':
78-
return SyntaxKind.TypeAliasDeclaration;
79-
default:
80-
throw new Error(`Unsupported syntax kind: ${coverageType}`);
81-
}
82-
}

0 commit comments

Comments
 (0)