UNPKG

@n8n/n8n-benchmark

Version:

Cli for running benchmark tests for n8n

88 lines 3.88 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScenarioLoader = void 0; const fs = __importStar(require("node:fs")); const path = __importStar(require("path")); const node_crypto_1 = require("node:crypto"); class ScenarioLoader { loadAll(pathToScenarios) { pathToScenarios = path.resolve(pathToScenarios); const scenarioFolders = fs .readdirSync(pathToScenarios, { withFileTypes: true }) .filter((dirent) => dirent.isDirectory()) .map((dirent) => dirent.name); const scenarios = []; for (const folder of scenarioFolders) { const scenarioPath = path.join(pathToScenarios, folder); const manifestFileName = `${folder}.manifest.json`; const scenarioManifestPath = path.join(pathToScenarios, folder, manifestFileName); if (!fs.existsSync(scenarioManifestPath)) { console.warn(`Scenario at ${scenarioPath} is missing the ${manifestFileName} file`); continue; } const [scenario, validationErrors] = this.loadAndValidateScenarioManifest(scenarioManifestPath); if (validationErrors) { console.warn(`Scenario at ${scenarioPath} has the following validation errors: ${validationErrors.join(', ')}`); continue; } scenarios.push({ ...scenario, id: this.formScenarioId(scenarioPath), scenarioDirPath: scenarioPath, }); } return scenarios; } loadAndValidateScenarioManifest(scenarioManifestPath) { const [scenario, error] = this.loadScenarioManifest(scenarioManifestPath); if (!scenario) { return [null, [error]]; } const validationErrors = []; if (!scenario.name) { validationErrors.push(`Scenario at ${scenarioManifestPath} is missing a name`); } if (!scenario.description) { validationErrors.push(`Scenario at ${scenarioManifestPath} is missing a description`); } return validationErrors.length === 0 ? [scenario, null] : [null, validationErrors]; } loadScenarioManifest(scenarioManifestPath) { try { const scenario = JSON.parse(fs.readFileSync(scenarioManifestPath, 'utf8')); return [scenario, null]; } catch (error) { const message = error instanceof Error ? error.message : JSON.stringify(error); return [null, `Failed to parse manifest ${scenarioManifestPath}: ${message}`]; } } formScenarioId(scenarioPath) { return (0, node_crypto_1.createHash)('sha256').update(scenarioPath).digest('hex'); } } exports.ScenarioLoader = ScenarioLoader; //# sourceMappingURL=scenarioLoader.js.map