UNPKG

@dapplion/benchmark

Version:

Ensures that new code does not introduce performance regressions with CI. Tracks:

67 lines (65 loc) 2.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131 const yargs_1 = __importDefault(require("yargs")); const mochaCliExports_js_1 = require("./utils/mochaCliExports.js"); const options_js_1 = require("./options.js"); const run_js_1 = require("./run.js"); /** * Common factory for running the CLI and running integration tests * The CLI must actually be executed in a different script */ const argv = process.argv.slice(2); const args = (0, mochaCliExports_js_1.loadOptions)(argv); void (0, yargs_1.default)() .env("BENCHMARK") .scriptName("benchmark") .command({ command: ["$0 [spec..]", "inspect"], describe: "Run benchmarks", handler: async (argv) => { // Copied from mocha source to load ts-node properly. // It's on the CLI middleware of mocha so it does not get run when calling mocha programatically // https://github.com/mochajs/mocha/blob/014e47a8b07809e73b1598c7abeafe7a3b57a8f7/lib/cli/run.js#L353 const plugins = await (0, mochaCliExports_js_1.handleRequires)(argv.require); Object.assign(argv, plugins); await (0, run_js_1.run)({ threshold: options_js_1.optionsDefault.threshold, ...argv }); }, }) .parserConfiguration({ // As of yargs v16.1.0 dot-notation breaks strictOptions() // Manually processing options is typesafe tho more verbose "dot-notation": false, // From mocha "combine-arrays": true, "short-option-groups": false, "strip-aliased": true, }) .options(options_js_1.options) .usage(`Benchmark runner to track performance. benchmark --local 'test/**/*.perf.ts' `) .epilogue("For more information, check the CLI reference _TBD_") // DO NOT USE "h", "v" aliases. Those break the --help functionality // .alias("h", "help") // .alias("v", "version") .recommendCommands() .fail((msg, err) => { if (msg) { // Show command help message when no command is provided if (msg.includes("Not enough non-option arguments")) { yargs_1.default.showHelp(); // eslint-disable-next-line no-console console.log("\n"); } } const errorMessage = err ? err.stack || err.message : msg || "Unknown error"; // eslint-disable-next-line no-console console.error(` ✖ ${errorMessage}\n`); process.exit(1); }) .config(args) .parse(args._);