From bf4fd16cc0539eb4630580925099886581a964c2 Mon Sep 17 00:00:00 2001 From: dmail Date: Mon, 20 Nov 2023 11:20:25 +0100 Subject: [PATCH] importMetricFromFiles can now set process.env and params --- .../dynamic-import-worker/src/worker_collecting_one_export.js | 4 ++-- packages/performance-impact/package.json | 2 +- packages/performance-impact/src/importMetricFromFiles.js | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/dynamic-import-worker/src/worker_collecting_one_export.js b/packages/dynamic-import-worker/src/worker_collecting_one_export.js index de77967..c9da54d 100644 --- a/packages/dynamic-import-worker/src/worker_collecting_one_export.js +++ b/packages/dynamic-import-worker/src/worker_collecting_one_export.js @@ -1,6 +1,6 @@ import { parentPort, workerData } from "node:worker_threads"; -const { url, exportName } = workerData; +const { url, exportName, params } = workerData; const namespace = await import(url); if (!Object.prototype.hasOwnProperty.call(namespace, exportName)) { @@ -9,7 +9,7 @@ if (!Object.prototype.hasOwnProperty.call(namespace, exportName)) { const exportValue = namespace[exportName]; if (typeof exportValue === "function") { - const metrics = await exportValue(); + const metrics = await exportValue(params); parentPort.postMessage(metrics); } else { const metrics = exportValue; diff --git a/packages/performance-impact/package.json b/packages/performance-impact/package.json index 101301e..a64695e 100644 --- a/packages/performance-impact/package.json +++ b/packages/performance-impact/package.json @@ -1,6 +1,6 @@ { "name": "@jsenv/performance-impact", - "version": "4.1.4", + "version": "4.2.0", "description": "Report pull request impacts on performance metrics", "license": "MIT", "author": { diff --git a/packages/performance-impact/src/importMetricFromFiles.js b/packages/performance-impact/src/importMetricFromFiles.js index 8a9919f..4b6e0c2 100644 --- a/packages/performance-impact/src/importMetricFromFiles.js +++ b/packages/performance-impact/src/importMetricFromFiles.js @@ -24,13 +24,15 @@ export const importMetricFromFiles = async ({ const metricsDescription = metricsDescriptions[metricName]; const { file, + env, + params, iterations, msToWaitBetweenEachIteration = 100, } = metricsDescription; const url = new URL(file, directoryUrl).href; const measure = async () => { - const metrics = await importOneExportFromFile(url); + const metrics = await importOneExportFromFile(url, { env, params }); assertMetrics(metrics, `in ${file}`); return metrics; };