feat: add better error message when the coverageFile is not found
This commit is contained in:
parent
8e9cbcd396
commit
e20a3d3747
1 changed files with 23 additions and 3 deletions
26
src/index.ts
26
src/index.ts
|
|
@ -1,5 +1,6 @@
|
|||
import yargs from "yargs";
|
||||
import type { Options } from "yargs";
|
||||
import fs from "fs";
|
||||
import type { Options, Arguments } from "yargs";
|
||||
import { hideBin } from "yargs/helpers";
|
||||
import exec from "./exec";
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ const parseDiff = require("./diff-parser");
|
|||
const parseLcov = require("./lcov-parser");
|
||||
|
||||
export const error = (message: string) => {
|
||||
console.error(message);
|
||||
console.error("[ERROR] " + message);
|
||||
};
|
||||
|
||||
const options: { [key: string]: Options } = {
|
||||
|
|
@ -22,8 +23,27 @@ const options: { [key: string]: Options } = {
|
|||
},
|
||||
};
|
||||
|
||||
type Argv = Arguments<
|
||||
Partial<{
|
||||
coverageFile: string;
|
||||
}>
|
||||
>;
|
||||
|
||||
export const validate = async (argv: Argv) => {
|
||||
if (!fs.existsSync(argv.coverageFile || "")) {
|
||||
return new Error(
|
||||
`Lcov file must be a valid file '${argv.coverageFile}' provided. ` +
|
||||
`Please ensure you have run tests with coverage enabled.`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const run = async (argv = process.argv) => {
|
||||
const parsed: any = yargs(hideBin(argv)).options(options).argv;
|
||||
const parsed: Argv = await yargs(hideBin(argv)).options(options).argv;
|
||||
const validationError = await validate(parsed);
|
||||
if (validationError instanceof Error) {
|
||||
return error(validationError.message);
|
||||
}
|
||||
|
||||
const diffText = await exec(`git diff origin/HEAD...HEAD`);
|
||||
if (diffText.code > 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue