UNPKG

cypress-load-balancer

Version:

A simple load balancer for Cypress tests.

72 lines (71 loc) 3.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_fs_1 = __importDefault(require("node:fs")); const glob_1 = require("glob"); const utils_1 = __importDefault(require("../../utils")); const merge_1 = __importDefault(require("../../merge")); exports.default = { command: "merge", description: "Merges load balancing map files together back to an original map.", //@ts-expect-error Need to fix type builder: function (yargs) { return (yargs .option("original", { alias: "og", description: `The JSON file path of the original load balancing map into which to merge other files.\n` + `Defaulted to exist within the current working directory at "./cypress_load_balancer/spec-map.json"`, type: "string", default: utils_1.default.MAIN_LOAD_BALANCING_MAP_FILE_PATH }) .option("files", { alias: "F", description: "A list of other files to load and merge back to the original", type: "array", default: [] }) .option("glob", { alias: "G", description: "One or more glob patterns to match for load balancing maps to merge." + "Make sure to wrap in quotes for the glob to work correctly", type: "array", default: [] }) .option("output", { alias: "o", description: "An output file path to which to save. If not provided, uses the original file path", type: "string" }) //@ts-expect-error Need to fix type .check(function (argv) { if ([argv.files.length, argv.glob.length].every((length) => length === 0)) { throw Error("At least one file path or a glob pattern must be provided."); } return true; })); }, //@ts-expect-error Need to fix type handler: function (argv) { const loadFile = (fileName) => { const data = JSON.parse(node_fs_1.default.readFileSync(fileName).toString()); others.push(data); }; const orig = JSON.parse(node_fs_1.default.readFileSync(argv.original).toString()); const others = []; //Collect data from files found by glob (0, glob_1.globSync)(argv.glob, { dot: true, absolute: true, ignore: argv.original }).map(loadFile); //Collect data from explicit file names argv.files.map(loadFile); utils_1.default.DEBUG("spec-maps to merge to original:", others); if (others.length > 0) { const merged = (0, merge_1.default)(orig, others); utils_1.default.saveMapFile(merged, argv.output); console.log("cypress load balancer map merge complete"); } else { console.warn("No input files found, so skipping merging"); } } };