Skip to content

Commit

Permalink
Merge branch 'main' into history
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Mar 9, 2024
2 parents de4f5e4 + 09a7ab0 commit f3bb379
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 73 deletions.
2 changes: 1 addition & 1 deletion examples/plugins/src/lighthouse/src/lighthouse.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function runnerConfig(options: LighthouseCliOptions): RunnerConfig {
outputFile: outputPath,
outputTransform: (lighthouseOutput: unknown) =>
lhrToAuditOutputs(lighthouseOutput as Result),
} satisfies RunnerConfig;
};
}

function lhrToAuditOutputs(lhr: Result): AuditOutputs {
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/src/package-json/src/integration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function baseAuditOutput(slug: string): AuditOutput {
score: 1,
value: 0,
displayValue: pluralizePackage(),
} satisfies AuditOutput;
};
}

export function filterSeverityError(issue: Issue): boolean {
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/lib/autorun/autorun-command.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { vol } from 'memfs';
import { describe, expect, it, vi } from 'vitest';
import { PortalUploadArgs, uploadToPortal } from '@code-pushup/portal-client';
import { uploadToPortal } from '@code-pushup/portal-client';
import { collectAndPersistReports, readRcByPath } from '@code-pushup/core';
import { MEMFS_VOLUME, MINIMAL_REPORT_MOCK } from '@code-pushup/test-utils';
import { DEFAULT_CLI_CONFIGURATION } from '../../../mocks/constants';
Expand Down Expand Up @@ -58,7 +58,9 @@ describe('autorun-command', () => {
);

// values come from CORE_CONFIG_MOCK returned by readRcByPath mock
expect(uploadToPortal).toHaveBeenCalledWith({
expect(uploadToPortal).toHaveBeenCalledWith<
Parameters<typeof uploadToPortal>
>({
apiKey: 'dummy-api-key',
server: 'https://example.com/api',
data: {
Expand All @@ -72,6 +74,6 @@ describe('autorun-command', () => {
project: 'cli',
commit: expect.any(String),
},
} satisfies PortalUploadArgs);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
PERSIST_FILENAME,
PERSIST_FORMAT,
PERSIST_OUTPUT_DIR,
PersistConfig,
UploadConfig,
} from '@code-pushup/models';
import { CORE_CONFIG_MOCK, MINIMAL_CONFIG_MOCK } from '@code-pushup/test-utils';
import { yargsCli } from '../yargs-cli';
Expand Down Expand Up @@ -58,7 +60,7 @@ describe('parsing values from CLI and middleware', () => {
},
).parseAsync();

expect(persist).toEqual({
expect(persist).toEqual<PersistConfig>({
filename: PERSIST_FILENAME,
format: PERSIST_FORMAT,
outputDir: PERSIST_OUTPUT_DIR,
Expand All @@ -79,7 +81,7 @@ describe('parsing values from CLI and middleware', () => {
},
).parseAsync();

expect(persist).toEqual({
expect(persist).toEqual<PersistConfig>({
filename: 'cli-filename',
format: ['md'],
outputDir: 'cli-outputDir',
Expand All @@ -95,7 +97,7 @@ describe('parsing values from CLI and middleware', () => {
},
).parseAsync();

expect(persist).toEqual({
expect(persist).toEqual<PersistConfig>({
filename: 'rc-filename',
format: ['json', 'md'],
outputDir: 'rc-outputDir',
Expand All @@ -116,7 +118,7 @@ describe('parsing values from CLI and middleware', () => {
},
).parseAsync();

expect(persist).toEqual({
expect(persist).toEqual<PersistConfig>({
filename: 'cli-filename',
format: ['md'],
outputDir: 'cli-outputDir',
Expand All @@ -135,7 +137,7 @@ describe('parsing values from CLI and middleware', () => {
},
).parseAsync();

expect(persist).toEqual({
expect(persist).toEqual<PersistConfig>({
filename: 'rc-filename',
format: PERSIST_FORMAT,
outputDir: 'cli-outputdir',
Expand Down Expand Up @@ -163,7 +165,7 @@ describe('parsing values from CLI and middleware', () => {
},
).parseAsync();

expect(upload).toStrictEqual({
expect(upload).toStrictEqual<UploadConfig>({
organization: 'code-pushup',
project: 'portal',
apiKey: 'dummy-api-key',
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/lib/upload/upload-command.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { vol } from 'memfs';
import { describe, expect, it } from 'vitest';
import { PortalUploadArgs, uploadToPortal } from '@code-pushup/portal-client';
import { uploadToPortal } from '@code-pushup/portal-client';
import { readRcByPath } from '@code-pushup/core';
import {
ISO_STRING_REGEXP,
Expand Down Expand Up @@ -52,7 +52,9 @@ describe('upload-command-object', () => {
);

// values come from CORE_CONFIG_MOCK returned by readRcByPath mock
expect(uploadToPortal).toHaveBeenCalledWith({
expect(uploadToPortal).toHaveBeenCalledWith<
Parameters<typeof uploadToPortal>
>({
apiKey: 'dummy-api-key',
server: 'https://example.com/api',
data: {
Expand All @@ -66,6 +68,6 @@ describe('upload-command-object', () => {
project: 'cli',
commit: expect.any(String),
},
} satisfies PortalUploadArgs);
});
});
});
4 changes: 2 additions & 2 deletions packages/cli/src/lib/yargs-cli.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { CoreConfig } from '@code-pushup/models';
import { CoreConfig, Format } from '@code-pushup/models';
import {
PersistConfigCliOptions,
UploadConfigCliOptions,
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('yargsCli', () => {
['--persist.format=md', '--persist.format=json'],
{ options },
).parseAsync();
expect(parsedArgv.persist?.format).toEqual(['md', 'json']);
expect(parsedArgv.persist?.format).toEqual<Format[]>(['md', 'json']);
});

it('should throw for an invalid persist format', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/implementation/execute-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function executePlugin(
...(description && { description }),
...(docsUrl && { docsUrl }),
...(groups && { groups }),
} satisfies PluginReport;
};
}

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/lib/upload.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { vol } from 'memfs';
import { describe, expect } from 'vitest';
import { PortalUploadArgs, uploadToPortal } from '@code-pushup/portal-client';
import { uploadToPortal } from '@code-pushup/portal-client';
import {
ISO_STRING_REGEXP,
MEMFS_VOLUME,
Expand Down Expand Up @@ -37,7 +37,9 @@ describe('upload', () => {

expect(result).toEqual({ url: expect.stringContaining('code-pushup/cli') });

expect(uploadToPortal).toHaveBeenCalledWith({
expect(uploadToPortal).toHaveBeenCalledWith<
Parameters<typeof uploadToPortal>
>({
apiKey: 'dummy-api-key',
server: 'https://example.com/api',
data: {
Expand All @@ -51,7 +53,7 @@ describe('upload', () => {
project: 'cli',
commit: expect.any(String),
},
} satisfies PortalUploadArgs);
});
});

it('should throw for missing upload configuration', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-coverage/src/lib/config.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe('coveragePluginConfigSchema', () => {
expect(() => coveragePluginConfigSchema.parse(config)).not.toThrow();

const { coverageTypes } = coveragePluginConfigSchema.parse(config);
expect(coverageTypes).toEqual([
expect(coverageTypes).toEqual<CoverageType[]>([
'function',
'branch',
'line',
] satisfies CoverageType[]);
]);
});

it('throws for empty coverage type array', () => {
Expand Down
46 changes: 33 additions & 13 deletions packages/plugin-coverage/src/lib/runner/lcov/transform.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LCOVRecord } from 'parse-lcov';
import { describe, it } from 'vitest';
import { AuditOutput, Issue } from '@code-pushup/models';
import type { AuditOutput, Issue } from '@code-pushup/models';
import {
lcovCoverageToAuditOutput,
lcovReportToBranchStat,
Expand Down Expand Up @@ -28,7 +28,7 @@ describe('lcovReportToFunctionStat', () => {
details: [{ line: 12, name: 'yargsCli', hit: 6 }],
},
}),
).toEqual({ totalHit: 1, totalFound: 1, issues: [] } satisfies LCOVStat);
).toEqual<LCOVStat>({ totalHit: 1, totalFound: 1, issues: [] });
});

it('should transform an empty LCOV function report to LCOV stat', () => {
Expand All @@ -37,7 +37,11 @@ describe('lcovReportToFunctionStat', () => {
...lcovRecordMock,
functions: { hit: 0, found: 0, details: [] },
}),
).toEqual({ totalHit: 0, totalFound: 0, issues: [] } satisfies LCOVStat);
).toEqual<LCOVStat>({
totalHit: 0,
totalFound: 0,
issues: [],
});
});

it('should transform details from function report to issues', () => {
Expand Down Expand Up @@ -101,7 +105,11 @@ describe('lcovReportToLineStat', () => {
details: [{ line: 1, hit: 6 }],
},
}),
).toEqual({ totalHit: 1, totalFound: 1, issues: [] } satisfies LCOVStat);
).toEqual<LCOVStat>({
totalHit: 1,
totalFound: 1,
issues: [],
});
});

it('should transform an empty LCOV line report to LCOV stat', () => {
Expand All @@ -110,7 +118,11 @@ describe('lcovReportToLineStat', () => {
...lcovRecordMock,
lines: { hit: 0, found: 0, details: [] },
}),
).toEqual({ totalHit: 0, totalFound: 0, issues: [] } satisfies LCOVStat);
).toEqual<LCOVStat>({
totalHit: 0,
totalFound: 0,
issues: [],
});
});

it('should transform details from line report to issues', () => {
Expand Down Expand Up @@ -210,7 +222,11 @@ describe('lcovReportToBranchStat', () => {
details: [{ line: 12, taken: 6, branch: 0, block: 0 }],
},
}),
).toEqual({ totalHit: 1, totalFound: 1, issues: [] } satisfies LCOVStat);
).toEqual<LCOVStat>({
totalHit: 1,
totalFound: 1,
issues: [],
});
});

it('should transform an empty LCOV branch report to LCOV stat', () => {
Expand All @@ -219,7 +235,11 @@ describe('lcovReportToBranchStat', () => {
...lcovRecordMock,
branches: { hit: 0, found: 0, details: [] },
}),
).toEqual({ totalHit: 0, totalFound: 0, issues: [] } satisfies LCOVStat);
).toEqual<LCOVStat>({
totalHit: 0,
totalFound: 0,
issues: [],
});
});

it('should transform details from branch report to issues', () => {
Expand Down Expand Up @@ -279,12 +299,12 @@ describe('lcovCoverageToAudit', () => {
{ totalHit: 56, totalFound: 56, issues: [] },
'branch',
),
).toEqual({
).toEqual<AuditOutput>({
slug: 'branch-coverage',
score: 1,
value: 100,
displayValue: '100 %',
} satisfies AuditOutput);
});
});

it('should transform an empty function coverage to audit output', () => {
Expand All @@ -293,12 +313,12 @@ describe('lcovCoverageToAudit', () => {
{ totalHit: 0, totalFound: 0, issues: [] },
'function',
),
).toEqual({
).toEqual<AuditOutput>({
slug: 'function-coverage',
score: 1,
value: 100,
displayValue: '100 %',
} satisfies AuditOutput);
});
});

it('should transform a partial line coverage to audit output', () => {
Expand All @@ -317,7 +337,7 @@ describe('lcovCoverageToAudit', () => {
},
'line',
),
).toEqual({
).toEqual<AuditOutput>({
slug: 'line-coverage',
score: 0.9,
value: 90,
Expand All @@ -331,6 +351,6 @@ describe('lcovCoverageToAudit', () => {
},
],
},
} satisfies AuditOutput);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ describe('createRunnerConfig', () => {
coverageTypes: ['branch'],
perfectScoreThreshold: 85,
});
expect(runnerConfig).toStrictEqual({
expect(runnerConfig).toStrictEqual<RunnerConfig>({
command: 'node',
args: ['executeRunner.ts'],
outputTransform: expect.any(Function),
outputFile: expect.stringContaining('runner-output.json'),
} satisfies RunnerConfig);
});
});

it('should provide plugin config to runner in JSON file', async () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin-coverage/src/lib/utils.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ describe('applyMaxScoreAboveThreshold', () => {
slug: 'branch-coverage',
value: 75,
score: 0.75,
} satisfies AuditOutput,
},
],
0.7,
),
).toEqual([
).toEqual<AuditOutput[]>([
{
slug: 'branch-coverage',
value: 75,
score: 1,
} satisfies AuditOutput,
},
]);
});

Expand All @@ -32,16 +32,16 @@ describe('applyMaxScoreAboveThreshold', () => {
slug: 'line-coverage',
value: 60,
score: 0.6,
} satisfies AuditOutput,
},
],
0.7,
),
).toEqual([
).toEqual<AuditOutput[]>([
{
slug: 'line-coverage',
value: 60,
score: 0.6,
} satisfies AuditOutput,
},
]);
});
});
Loading

0 comments on commit f3bb379

Please sign in to comment.