Skip to content

Feat: useAbsolutePath for lcov reports #62

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: true,
singleQuote: true,
trailingComma: 'none',
tabWidth: 4,
printWidth: 100
};
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ schedule(istanbulCoverage({
// What to do when the PR doesn't meet the minimum code coverage threshold
reportMode: "message", // || "warn" || "fail"

// Required for lcov reports which uses relative path.
useAbsolutePath: true, // || false

// Minimum coverage threshold percentages. Compared against the cumulative coverage of the reportFileSet.
threshold: {
statements: 100,
Expand All @@ -69,7 +72,7 @@ This plugin requires the 'json-summary' or 'lcov' report modes be enabled with I

### What test runners does this work with?

Anything that integrates with [Istanbul](https://www.npmjs.com/package/istanbul), or produces output in the (lcov)[https://linux.die.net/man/1/lcov] format. Istanbul is test runner agnostic, and can be integrated with anything written in node. Some test runners already integrate Istanbul, for instance [Jest](https://jestjs.io/docs/en/cli.html#coverage) bundles it internally. Helper integrations exists for [Jasmine](https://www.npmjs.com/package/jasmine-istanbul-reporter) and other libraries.
Anything that integrates with [Istanbul](https://www.npmjs.com/package/istanbul), or produces output in the (lcov)[https://linux.die.net/man/1/lcov] format. Istanbul is test runner agnostic, and can be integrated with anything written in node. Some test runners already integrate Istanbul, for instance [Jest](https://jestjs.io/docs/en/cli.html#coverage) bundles it internally. Helper integrations exists for [Jasmine](https://www.npmjs.com/package/jasmine-istanbul-reporter) and other libraries.

### Why should my team see code coverage stats in their PRs?

Expand Down
71 changes: 36 additions & 35 deletions src/config.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import { makeCompleteConfiguration } from "./config.model"
import { makeCompleteConfiguration } from './config.model';

describe("makeCompleteConfiguration", () => {
const base = {
coveragePaths: ["./coverage/coverage-summary.json"],
reportFileSet: "all",
reportMode: "message",
entrySortMethod: "alphabetically",
numberOfEntries: 10,
threshold: {
statements: 100,
branches: 100,
functions: 100,
lines: 100,
},
}
describe('makeCompleteConfiguration', () => {
const base = {
coveragePaths: ['./coverage/coverage-summary.json'],
reportFileSet: 'all',
reportMode: 'message',
entrySortMethod: 'alphabetically',
numberOfEntries: 10,
useAbsolutePath: true,
threshold: {
statements: 100,
branches: 100,
functions: 100,
lines: 100
}
};

it("returns a default configuration when sent undefined", () => {
const output = makeCompleteConfiguration()
expect(output).toEqual(base)
})
it('returns a default configuration when sent undefined', () => {
const output = makeCompleteConfiguration();
expect(output).toEqual(base);
});

it("overrides coveragePaths with the value from coveragePath", () => {
const output = makeCompleteConfiguration({
coveragePath: "some-other-path",
})
expect(output).toEqual({ ...base, coveragePaths: ["some-other-path"] })
})
it('overrides coveragePaths with the value from coveragePath', () => {
const output = makeCompleteConfiguration({
coveragePath: 'some-other-path'
});
expect(output).toEqual({ ...base, coveragePaths: ['some-other-path'] });
});

it("overrides a specific value from the default", () => {
const output = makeCompleteConfiguration({
reportMode: "warn",
})
expect(output).toEqual({
...base,
reportMode: "warn",
})
})
})
it('overrides a specific value from the default', () => {
const output = makeCompleteConfiguration({
reportMode: 'warn'
});
expect(output).toEqual({
...base,
reportMode: 'warn'
});
});
});
91 changes: 48 additions & 43 deletions src/config.model.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
export type ReportFileSet = "created" | "modified" | "createdOrModified" | "all"
export type ReportMode = "fail" | "warn" | "message"
export type ReportFileSet = 'created' | 'modified' | 'createdOrModified' | 'all';
export type ReportMode = 'fail' | 'warn' | 'message';
export type SortMethod =
| "alphabetically"
| "least-coverage"
| "most-coverage"
| "largest-file-size"
| "smallest-file-size"
| "uncovered-lines"
| 'alphabetically'
| 'least-coverage'
| 'most-coverage'
| 'largest-file-size'
| 'smallest-file-size'
| 'uncovered-lines';

export type SourceType = "json-summary" | "lcov"
export type SourceType = 'json-summary' | 'lcov';
export interface SourcePathExplicit {
path: string
type: SourceType
path: string;
type: SourceType;
}
export type SourcePath = string | SourcePathExplicit
export type SourcePath = string | SourcePathExplicit;

export interface CoverageThreshold {
statements: number
branches: number
functions: number
lines: number
statements: number;
branches: number;
functions: number;
lines: number;
}

export interface Config {
customSuccessMessage?: string
customFailureMessage?: string
numberOfEntries: number
entrySortMethod: SortMethod
coveragePath?: SourcePath
coveragePaths: SourcePath[]
reportFileSet: ReportFileSet
threshold: CoverageThreshold
reportMode: ReportMode
customSuccessMessage?: string;
customFailureMessage?: string;
numberOfEntries: number;
useAbsolutePath: boolean;
entrySortMethod: SortMethod;
coveragePath?: SourcePath;
coveragePaths: SourcePath[];
reportFileSet: ReportFileSet;
threshold: CoverageThreshold;
reportMode: ReportMode;
}

/**
Expand All @@ -40,23 +41,27 @@ export interface Config {
* @returns A complete configuration
*/
export function makeCompleteConfiguration(config?: Partial<Config>): Config {
const defaults: Config = {
coveragePaths: [],
reportFileSet: "all",
reportMode: "message",
entrySortMethod: "alphabetically",
numberOfEntries: 10,
threshold: {
statements: 100,
branches: 100,
functions: 100,
lines: 100,
},
}
const defaults: Config = {
coveragePaths: [],
reportFileSet: 'all',
reportMode: 'message',
entrySortMethod: 'alphabetically',
numberOfEntries: 10,
useAbsolutePath: true,
threshold: {
statements: 100,
branches: 100,
functions: 100,
lines: 100
}
};

const combined = config ? { ...defaults, ...config } : defaults
const coveragePath = combined.coveragePath ? combined.coveragePath : "./coverage/coverage-summary.json"
const coveragePaths = combined.coveragePaths.length === 0 ? [coveragePath] : combined.coveragePaths
delete combined.coveragePath
return { ...combined, coveragePaths }
const combined = config ? { ...defaults, ...config } : defaults;
const coveragePath = combined.coveragePath
? combined.coveragePath
: './coverage/coverage-summary.json';
const coveragePaths =
combined.coveragePaths.length === 0 ? [coveragePath] : combined.coveragePaths;
delete combined.coveragePath;
return { ...combined, coveragePaths };
}
Loading