Skip to content

Commit

Permalink
fix(ext/node): add APIs perf_hook.performance (denoland#21192)
Browse files Browse the repository at this point in the history
Required for Next.js.
  • Loading branch information
bartlomieju committed Nov 14, 2023
1 parent 8866521 commit cf6673b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cli/tests/unit_node/perf_hooks_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ Deno.test({
assertEquals(perfHooks.performance.clearMarks, performance.clearMarks);
assertEquals(perfHooks.performance.mark, performance.mark);
assertEquals(perfHooks.performance.now, performance.now);
assertEquals(
perfHooks.performance.getEntriesByName,
performance.getEntriesByName,
);
assertEquals(
perfHooks.performance.getEntriesByType,
performance.getEntriesByType,
);
// @ts-ignore toJSON is not in Performance interface
assertEquals(perfHooks.performance.toJSON, performance.toJSON);
perfHooks.performance.measure("test");
perfHooks.performance.mark("test");
perfHooks.performance.clearMarks("test");
perfHooks.performance.now();
assertEquals(perfHooks.performance.getEntriesByName("event", "mark"), []);
assertEquals(perfHooks.performance.getEntriesByType("mark"), []);
// @ts-ignore toJSON is not in Performance interface
perfHooks.performance.toJSON();
},
Expand Down
5 changes: 4 additions & 1 deletion ext/node/polyfills/perf_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const constants = {};
const performance:
& Omit<
Performance,
"clearMeasures" | "getEntries" | "getEntriesByName" | "getEntriesByType"
"clearMeasures" | "getEntries"
>
& {
// deno-lint-ignore no-explicit-any
Expand Down Expand Up @@ -58,6 +58,9 @@ const performance:
// deno-lint-ignore no-explicit-any
return (shimPerformance as any).timeOrigin;
},
getEntriesByName: (name, type) =>
shimPerformance.getEntriesByName(name, type),
getEntriesByType: (type) => shimPerformance.getEntriesByType(type),
markResourceTiming: () => {},
// @ts-ignore waiting on update in `deno`, but currently this is
// a circular dependency
Expand Down

0 comments on commit cf6673b

Please sign in to comment.