Skip to content

Commit ef77df0

Browse files
committed
chore(plugin-doc-coverage): fix tests, fully remove unnecessary await
1 parent 24468cc commit ef77df0

File tree

7 files changed

+67
-30
lines changed

7 files changed

+67
-30
lines changed

code-pushup.preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export const docCoverageCoreConfig = async (
144144
config: DocCoveragePluginConfig,
145145
): Promise<CoreConfig> => {
146146
return {
147-
plugins: [await docCoveragePlugin(config)],
147+
plugins: [docCoveragePlugin(config)],
148148
categories: getDocCoverageCategories(config),
149149
};
150150
};

packages/plugin-doc-coverage/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Measured documentation types are mapped to Code PushUp audits in the following w
4444
// ...
4545
plugins: [
4646
// ...
47-
await docCoveragePlugin({
47+
docCoveragePlugin({
4848
sourceGlob: ['**/*.ts'],
4949
}),
5050
],
@@ -105,7 +105,7 @@ The plugin accepts the following parameters:
105105
Required parameter. The `sourceGlob` option accepts an array of strings that define patterns to include or exclude files. You can use glob patterns to match files and the `!` symbol to exclude specific patterns. Example:
106106

107107
```js
108-
await docCoveragePlugin({
108+
docCoveragePlugin({
109109
sourceGlob: [
110110
'src/**/*.ts', // include all TypeScript files in src
111111
'!src/**/*.{spec,test}.ts', // exclude test files
@@ -119,7 +119,7 @@ await docCoveragePlugin({
119119
Optional parameter. The `onlyAudits` option allows you to specify which documentation types you want to measure. Only the specified audits will be included in the results. Example:
120120

121121
```js
122-
await docCoveragePlugin({
122+
docCoveragePlugin({
123123
sourceGlob: ['src/**/*.ts'],
124124
onlyAudits: [
125125
'classes-coverage',
@@ -133,7 +133,7 @@ await docCoveragePlugin({
133133
Optional parameter. The `skipAudits` option allows you to exclude specific documentation types from measurement. All other types will be included in the results.
134134

135135
```js
136-
await docCoveragePlugin({
136+
docCoveragePlugin({
137137
sourceGlob: ['src/**/*.ts'],
138138
skipAudits: [
139139
'variables-coverage',

packages/plugin-doc-coverage/src/lib/config.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('DocCoveragePlugin Configuration', () => {
9191
docCoveragePluginConfigSchema.parse({
9292
onlyAudits: [123, true],
9393
}),
94-
).toThrow('Expected string');
94+
).toThrow('Expected string, received number');
9595
});
9696
});
9797

packages/plugin-doc-coverage/src/lib/doc-coverage-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const PLUGIN_DOCS_URL =
2828
* // ... core config ...
2929
* plugins: [
3030
* // ... other plugins ...
31-
* await docCoveragePlugin({
32-
* sourceGlob: 'src&#47;**&#47;*.{ts,tsx}',
31+
* docCoveragePlugin({
32+
* sourceGlob: ['src&#47;**&#47;*.{ts,tsx}']
3333
* })
3434
* ]
3535
* }

packages/plugin-doc-coverage/src/lib/doc-coverage-plugin.unit.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ vi.mock('./runner/runner.js', () => ({
2222
}));
2323

2424
describe('docCoveragePlugin', () => {
25-
it('should create a valid plugin config', async () => {
26-
await expect(
25+
it('should create a valid plugin config', () => {
26+
expect(
2727
docCoveragePlugin({
2828
sourceGlob: ['src/**/*.ts', '!**/*.spec.ts', '!**/*.test.ts'],
2929
}),
30-
).resolves.toStrictEqual(
30+
).toStrictEqual(
3131
expect.objectContaining({
3232
slug: PLUGIN_SLUG,
3333
title: PLUGIN_TITLE,
@@ -41,32 +41,32 @@ describe('docCoveragePlugin', () => {
4141
);
4242
});
4343

44-
it('should throw for invalid plugin options', async () => {
45-
await expect(
44+
it('should throw for invalid plugin options', () => {
45+
expect(() =>
4646
docCoveragePlugin({
4747
// @ts-expect-error testing invalid config
4848
sourceGlob: 123,
4949
}),
50-
).rejects.toThrow('Expected array, received number');
50+
).toThrow('Expected array, received number');
5151
});
5252

53-
it('should filter groups', async () => {
53+
it('should filter groups', () => {
5454
const config = { sourceGlob: ['src/**/*.ts'] };
55-
await docCoveragePlugin(config);
55+
docCoveragePlugin(config);
5656

5757
expect(filterGroupsByOnlyAudits).toHaveBeenCalledWith(groups, config);
5858
});
5959

6060
it('should filter audits', async () => {
6161
const config = { sourceGlob: ['src/**/*.ts'] };
62-
await docCoveragePlugin(config);
62+
docCoveragePlugin(config);
6363

6464
expect(filterAuditsByPluginConfig).toHaveBeenCalledWith(config);
6565
});
6666

6767
it('should forward options to runner function', async () => {
6868
const config = { sourceGlob: ['src/**/*.ts'] };
69-
await docCoveragePlugin(config);
69+
docCoveragePlugin(config);
7070

7171
expect(createRunnerFunction).toHaveBeenCalledWith(config);
7272
});

packages/plugin-doc-coverage/src/lib/runner/doc-processer.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ export function processDocCoverage(
5353
return getDocumentationReport(project.getSourceFiles());
5454
}
5555

56+
export function getAllNodesFromASourceFile(sourceFile: SourceFile) {
57+
const classes = sourceFile.getClasses();
58+
return [
59+
...sourceFile.getFunctions(),
60+
...classes,
61+
...getClassNodes(classes),
62+
...sourceFile.getTypeAliases(),
63+
...sourceFile.getEnums(),
64+
...sourceFile.getInterfaces(),
65+
...getVariablesInformation(sourceFile.getVariableStatements()),
66+
];
67+
}
68+
5669
/**
5770
* Gets the documentation coverage report from the source files
5871
* @param sourceFiles - The source files to process
@@ -64,23 +77,12 @@ export function getDocumentationReport(
6477
const unprocessedCoverageReport = sourceFiles.reduce(
6578
(coverageReportOfAllFiles, sourceFile) => {
6679
const filePath = sourceFile.getFilePath();
67-
const classes = sourceFile.getClasses();
68-
69-
const allNodesFromFile = [
70-
...sourceFile.getFunctions(),
71-
...classes,
72-
...getClassNodes(classes),
73-
...sourceFile.getTypeAliases(),
74-
...sourceFile.getEnums(),
75-
...sourceFile.getInterfaces(),
76-
...getVariablesInformation(sourceFile.getVariableStatements()),
77-
];
80+
const allNodesFromFile = getAllNodesFromASourceFile(sourceFile);
7881

7982
const coverageReportOfCurrentFile = allNodesFromFile.reduce(
8083
(acc, node) => {
8184
const nodeType = getCoverageTypeFromKind(node.getKind());
8285
const currentTypeReport = acc[nodeType];
83-
8486
const updatedIssues =
8587
node.getJsDocs().length === 0
8688
? [

packages/plugin-doc-coverage/src/lib/runner/doc-processer.unit.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
sourceFileMock,
55
} from '../../../mocks/source-files-mock.generator';
66
import {
7+
getAllNodesFromASourceFile,
78
getClassNodes,
89
getDocumentationReport,
910
getVariablesInformation,
@@ -276,3 +277,37 @@ describe('getVariablesInformation', () => {
276277
expect(result).toHaveLength(0);
277278
});
278279
});
280+
281+
describe('getAllNodesFromASourceFile', () => {
282+
it('should combine all node types from a source file', () => {
283+
const mockSourceFile = sourceFileMock('test.ts', {
284+
functions: { 1: true },
285+
classes: { 2: false },
286+
types: { 3: true },
287+
enums: { 4: false },
288+
interfaces: { 5: true },
289+
});
290+
291+
const result = getAllNodesFromASourceFile(mockSourceFile);
292+
293+
expect(result).toHaveLength(5);
294+
});
295+
296+
it('should handle empty source file', () => {
297+
const mockSourceFile = sourceFileMock('empty.ts', {});
298+
299+
const result = getAllNodesFromASourceFile(mockSourceFile);
300+
301+
expect(result).toHaveLength(0);
302+
});
303+
304+
it('should handle source file with only functions', () => {
305+
const mockSourceFile = sourceFileMock('functions.ts', {
306+
functions: { 1: true, 2: false, 3: true },
307+
});
308+
309+
const result = getAllNodesFromASourceFile(mockSourceFile);
310+
311+
expect(result).toHaveLength(3);
312+
});
313+
});

0 commit comments

Comments
 (0)