reqover
Version:
Reqover is language agnostic tool that gives a picture about coverage of APIs based on Open API (Swagger).
109 lines (104 loc) • 2.56 kB
JavaScript
#! /usr/bin/env node
const { createCoverageReport } = require("./main");
const argv = require("yargs");
const { generateReport } = require("./report");
const { serveFolder } = require("./server");
const { record } = require("./recorder");
const { getConfig } = require("./config");
const reportDir = ".reqover/report";
argv
.command(
"generate",
"Generate coverage report",
(yargs) => {
yargs
.option("file", {
alias: "f",
demandOption: true,
describe: "Swagger JSON file",
})
.option("data", {
alias: "d",
demandOption: true,
describe: "Coverage data folder",
})
.option("output", {
alias: "o",
describe: "Coverage report file path",
default: ".reqover",
})
.option("basePath", {
alias: "p",
describe: "Base API path",
})
.option("distribution", {
alias: "v",
describe: "Report version",
default: "v0.0.3",
})
.option("html", {
describe: "HTML report",
})
.option("config", {
describe: "ignore config",
})
.option("debug", {
describe: "enable debug",
});
},
async (argv) => {
const config = getConfig(argv.config);
const jsonReportDestination = await createCoverageReport(
argv.file,
argv.data,
{
...config,
baseApiPath: argv.basePath,
reportFolder: argv.output,
enableDebug: argv.debug || false,
}
);
if (argv.html) {
generateReport(jsonReportDestination, reportDir);
console.log(
`HTML report saved to ${reportDir}. Run reqover serve to open browser`
);
}
}
)
.demandCommand()
.command(
"serve",
"Serve html report",
(yargs) => {
yargs.option("dir", {
alias: "d",
default: reportDir,
describe: "HTML report root folder path",
});
},
(argv) => {
serveFolder(argv.dir);
}
)
.demandCommand()
.command(
"record",
"Record coverage results",
(yargs) => {
yargs
.option("target", {
alias: "t",
demandOption: true,
describe: "Original API url",
})
.option("port", {
alias: "p",
default: 3000,
describe: "Proxy path port",
});
},
(argv) => {
record(argv.port, argv.target);
}
).argv;