@vercel/devlow-bench 0.1.4 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -86,12 +86,12 @@ describe(
86
86
  import { measureTime, reportMeasurement } from "devlow-bench";
87
87
 
88
88
  // Measure a time
89
- measureTime("name of the timing", {
89
+ await measureTime("name of the timing", {
90
90
  /* optional options */
91
91
  });
92
92
 
93
93
  // Report some other measurement
94
- reportMeasurement("name of the measurement", value, unit, {
94
+ await reportMeasurement("name of the measurement", value, unit, {
95
95
  /* optional options */
96
96
  });
97
97
  ```
package/dist/browser.js CHANGED
@@ -71,21 +71,21 @@ async function withRequestMetrics(metricName, page, fn) {
71
71
  await Promise.all(activePromises);
72
72
  let totalDownload = 0;
73
73
  for (const [extension, size] of sizeByExtension.entries()) {
74
- reportMeasurement(`${metricName}/responseSizes/${extension}`, size, "bytes");
74
+ await reportMeasurement(`${metricName}/responseSizes/${extension}`, size, "bytes");
75
75
  totalDownload += size;
76
76
  }
77
- reportMeasurement(`${metricName}/responseSizes`, totalDownload, "bytes");
77
+ await reportMeasurement(`${metricName}/responseSizes`, totalDownload, "bytes");
78
78
  let totalRequests = 0;
79
79
  for (const [extension, count] of requestsByExtension.entries()) {
80
- reportMeasurement(`${metricName}/requests/${extension}`, count, "requests");
80
+ await reportMeasurement(`${metricName}/requests/${extension}`, count, "requests");
81
81
  totalRequests += count;
82
82
  }
83
- reportMeasurement(`${metricName}/requests`, totalRequests, "requests");
84
- reportMeasurement(`${metricName}/console/logs`, logCount, "messages");
85
- reportMeasurement(`${metricName}/console/warnings`, warningCount, "messages");
86
- reportMeasurement(`${metricName}/console/errors`, errorCount, "messages");
87
- reportMeasurement(`${metricName}/console/uncaught`, uncaughtCount, "messages");
88
- reportMeasurement(`${metricName}/console`, logCount + warningCount + errorCount + uncaughtCount, "messages");
83
+ await reportMeasurement(`${metricName}/requests`, totalRequests, "requests");
84
+ await reportMeasurement(`${metricName}/console/logs`, logCount, "messages");
85
+ await reportMeasurement(`${metricName}/console/warnings`, warningCount, "messages");
86
+ await reportMeasurement(`${metricName}/console/errors`, errorCount, "messages");
87
+ await reportMeasurement(`${metricName}/console/uncaught`, uncaughtCount, "messages");
88
+ await reportMeasurement(`${metricName}/console`, logCount + warningCount + errorCount + uncaughtCount, "messages");
89
89
  }
90
90
  finally {
91
91
  page.off("response", responseHandler);
@@ -11,9 +11,9 @@ export declare function measureTime(name: string, options?: {
11
11
  scenario?: string;
12
12
  props?: Record<string, string | number | null>;
13
13
  offset?: number;
14
- }): void;
14
+ }): Promise<void>;
15
15
  export declare function reportMeasurement(name: string, value: number, unit: string, options?: {
16
16
  relativeTo?: string | typeof PREVIOUS;
17
17
  scenario?: string;
18
18
  props?: Record<string, string | number | null>;
19
- }): void;
19
+ }): Promise<void>;
package/dist/describe.js CHANGED
@@ -56,14 +56,32 @@ export function withCurrent(current, fn) {
56
56
  });
57
57
  }
58
58
  export const PREVIOUS = Symbol("previous measurement with that unit");
59
- export function measureTime(name, options = {}) {
59
+ export async function measureTime(name, options = {}) {
60
60
  const end = Date.now() - (options.offset || 0);
61
- reportMeasurement(name, end, "ms", { relativeTo: PREVIOUS, ...options });
61
+ await reportMeasurement(name, end, "ms", {
62
+ relativeTo: PREVIOUS,
63
+ ...options,
64
+ });
62
65
  }
63
- export function reportMeasurement(name, value, unit, options = {}) {
66
+ export async function reportMeasurement(name, value, unit, options = {}) {
64
67
  if (!currentScenario) {
65
68
  throw new Error("reportMeasurement() must be called inside of describe()");
66
69
  }
70
+ if (typeof name !== "string") {
71
+ throw new Error("reportMeasurement() must be called with a name that is a string");
72
+ }
73
+ if (typeof value !== "number") {
74
+ throw new Error("reportMeasurement() must be called with a value that is a number");
75
+ }
76
+ if (isNaN(value)) {
77
+ throw new Error("reportMeasurement() must be called with a value that is not NaN");
78
+ }
79
+ if (!isFinite(value)) {
80
+ throw new Error("reportMeasurement() must be called with a value that is finite");
81
+ }
82
+ if (typeof unit !== "string") {
83
+ throw new Error("reportMeasurement() must be called with a unit that is a string");
84
+ }
67
85
  let { relativeTo, scenario, props } = options;
68
86
  if (relativeTo === PREVIOUS) {
69
87
  relativeTo = "previous";
@@ -83,12 +101,12 @@ export function reportMeasurement(name, value, unit, options = {}) {
83
101
  if (!prev) {
84
102
  throw new Error(`No measurement named ${relativeTo} found`);
85
103
  }
86
- if (prev.unit !== "ms") {
104
+ if (prev.unit !== unit) {
87
105
  throw new Error(`Measurement ${relativeTo} is not a "${unit}" measurement`);
88
106
  }
89
107
  reportedValue -= prev.value;
90
108
  }
91
- currentScenario.iface.measurement(scenario ?? currentScenario.scenario.scenario.name, props
109
+ await currentScenario.iface.measurement(scenario ?? currentScenario.scenario.scenario.name, props
92
110
  ? {
93
111
  ...currentScenario.scenario.props,
94
112
  ...props,
package/dist/shell.js CHANGED
@@ -91,7 +91,7 @@ class CommandImpl {
91
91
  .filter((x) => x)
92
92
  .map((x) => x.memory)
93
93
  .reduce((a, b) => a + b, 0);
94
- reportMeasurement(metricName, memUsage, "bytes", options);
94
+ await reportMeasurement(metricName, memUsage, "bytes", options);
95
95
  }
96
96
  catch (e) {
97
97
  // ignore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/devlow-bench",
3
- "version": "0.1.4",
3
+ "version": "0.2.4",
4
4
  "description": "Benchmarking tool for the developer workflow",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -25,7 +25,8 @@
25
25
  "@types/inquirer": "^9.0.3",
26
26
  "@types/minimist": "^1.2.2",
27
27
  "@types/node": "^20.3.0",
28
- "@types/split2": "^4.2.0"
28
+ "@types/split2": "^4.2.0",
29
+ "@turbo/eslint-config": "0.0.0"
29
30
  },
30
31
  "dependencies": {
31
32
  "@datadog/datadog-api-client": "^1.13.0",
@@ -38,6 +39,7 @@
38
39
  "tree-kill": "^1.2.2"
39
40
  },
40
41
  "scripts": {
42
+ "lint": "eslint src/",
41
43
  "prerelease": "pnpm run build:ts",
42
44
  "build:ts": "tsc"
43
45
  }