Skip to content

Commit

Permalink
importMetricFromFiles can now set process.env and params
Browse files Browse the repository at this point in the history
  • Loading branch information
dmail committed Nov 20, 2023
1 parent 0dbe40a commit bf4fd16
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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)) {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/performance-impact/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 3 additions & 1 deletion packages/performance-impact/src/importMetricFromFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit bf4fd16

Please sign in to comment.