summaryrefslogtreecommitdiff
path: root/tests/unit/performance_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/performance_test.ts')
-rw-r--r--tests/unit/performance_test.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/unit/performance_test.ts b/tests/unit/performance_test.ts
index 93af641ad..fa056c7f5 100644
--- a/tests/unit/performance_test.ts
+++ b/tests/unit/performance_test.ts
@@ -2,6 +2,7 @@
import {
assert,
assertEquals,
+ assertNotEquals,
assertNotStrictEquals,
assertStringIncludes,
assertThrows,
@@ -36,6 +37,41 @@ Deno.test(function performanceToJSON() {
assertEquals(Object.keys(json).length, 1);
});
+Deno.test(function clearMarks() {
+ performance.mark("a");
+ performance.mark("a");
+ performance.mark("b");
+ performance.mark("c");
+
+ const marksNum = performance.getEntriesByType("mark").length;
+
+ performance.clearMarks("a");
+ assertEquals(performance.getEntriesByType("mark").length, marksNum - 2);
+
+ performance.clearMarks();
+ assertEquals(performance.getEntriesByType("mark").length, 0);
+});
+
+Deno.test(function clearMeasures() {
+ performance.measure("from-start");
+ performance.mark("a");
+ performance.measure("from-mark-a", "a");
+ performance.measure("from-start");
+ performance.measure("from-mark-a", "a");
+ performance.mark("b");
+ performance.measure("between-a-and-b", "a", "b");
+
+ const measuresNum = performance.getEntriesByType("measure").length;
+
+ performance.clearMeasures("from-start");
+ assertEquals(performance.getEntriesByType("measure").length, measuresNum - 2);
+
+ performance.clearMeasures();
+ assertEquals(performance.getEntriesByType("measure").length, 0);
+
+ performance.clearMarks();
+});
+
Deno.test(function performanceMark() {
const mark = performance.mark("test");
assert(mark instanceof PerformanceMark);
@@ -127,6 +163,25 @@ Deno.test(function performanceMeasure() {
});
});
+Deno.test(function performanceMeasureUseMostRecentMark() {
+ const markName1 = "mark1";
+ const measureName1 = "measure1";
+ const mark1 = performance.mark(markName1);
+ return new Promise((resolve, reject) => {
+ setTimeout(() => {
+ try {
+ const laterMark1 = performance.mark(markName1);
+ const measure1 = performance.measure(measureName1, markName1);
+ assertNotEquals(mark1.startTime, measure1.startTime);
+ assertEquals(laterMark1.startTime, measure1.startTime);
+ } catch (e) {
+ return reject(e);
+ }
+ resolve();
+ }, 100);
+ });
+});
+
Deno.test(function performanceCustomInspectFunction() {
assertStringIncludes(Deno.inspect(performance), "Performance");
assertStringIncludes(