-
Notifications
You must be signed in to change notification settings - Fork 0
/
measure.test.ts
201 lines (182 loc) · 5.85 KB
/
measure.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import {
assertEquals,
assertThrows,
} from "https://deno.land/[email protected]/assert/mod.ts";
import { performanceMeasurePolyfill } from "./measure.ts";
const cleanup = () => {
performance.clearMarks();
performance.clearMeasures();
};
Deno.test(
"1. If startOrMeasureOptions is a PerformanceMeasureOptions object and at least one of start, end, duration, and detail exist, run the following checks:",
async (t) => {
await t.step(
"1.1. If endMark is given, throw a TypeError. ",
() => {
assertThrows(
() =>
performanceMeasurePolyfill("measure", {
start: "start",
end: "end",
duration: 100,
}, "end"),
TypeError,
"If startOrMeasureOptions is an object, endMark cannot be provided.",
);
cleanup();
},
);
await t.step(
"1.2. If startOrMeasureOptions's start and end members are both omitted, throw a TypeError.",
() => {
assertThrows(
() => performanceMeasurePolyfill("measure", {}),
TypeError,
"Invalid startOrMeasureOptions.",
);
cleanup();
},
);
await t.step(
"1.3. If startOrMeasureOptions's start, duration, and end members all exist, throw a TypeError.",
() => {
assertThrows(
() =>
performanceMeasurePolyfill("measure", {
start: "start",
duration: 100,
end: "end",
}),
TypeError,
"Invalid startOrMeasureOptions.",
);
cleanup();
},
);
},
);
Deno.test(
"2. Compute end time as follows:",
async (t) => {
await t.step(
"2.2. Otherwise, if startOrMeasureOptions is a PerformanceMeasureOptions object, and if its end member exists, let end time be the value returned by running the convert a mark to a timestamp algorithm passing in startOrMeasureOptions's end.",
() => {
const start = performance.mark("start");
const end = performance.mark("end");
const { duration } = performanceMeasurePolyfill("measure", {
start: "start",
end: "end",
});
assertEquals(duration, end.startTime - start.startTime);
cleanup();
},
);
await t.step(
"2.3. Otherwise, if startOrMeasureOptions is a PerformanceMeasureOptions object, and if its start and duration members both exist",
() => {
performance.mark("start");
const { duration } = performanceMeasurePolyfill("measure", {
start: "start",
duration: 100,
});
assertEquals(duration, 100);
},
);
await t.step(
"2.4. Otherwise, let end time be the value that would be returned by the Performance object's now() method",
() => {
// TODO
cleanup();
},
);
},
);
Deno.test(
"3. Compute start time as follows:",
async (t) => {
await t.step(
"3.1. If startOrMeasureOptions is a PerformanceMeasureOptions object, and if its start member exists, let start time be the value returned by running the convert a mark to a timestamp algorithm passing in startOrMeasureOptions's start",
() => {
const start = performance.mark("start");
const { startTime } = performanceMeasurePolyfill("measure", {
start: "start",
});
assertEquals(start.startTime, startTime);
cleanup();
},
);
await t.step(
"3.2. Otherwise, if startOrMeasureOptions is a PerformanceMeasureOptions object, and if its duration and end members both exist",
() => {
const end = performance.mark("end");
const duration = 100;
const { startTime } = performanceMeasurePolyfill("measure", {
end: "end",
duration,
});
assertEquals(end.startTime - duration, startTime);
},
);
await t.step(
"3.3. Otherwise, if startOrMeasureOptions is a DOMString, let start time be the value returned by running the convert a mark to a timestamp algorithm passing in startOrMeasureOptions",
() => {
const start = performance.mark("start");
const { startTime } = performanceMeasurePolyfill("measure", "start");
assertEquals(start.startTime, startTime);
cleanup();
},
);
await t.step(
"3.4. Otherwise, let start time be 0",
() => {
const { startTime } = performanceMeasurePolyfill("measure");
assertEquals(startTime, 0);
cleanup();
},
);
},
);
Deno.test(
"4. Create a new PerformanceMeasure object (entry) with this's relevant realm.",
async (t) => {
const start = performance.mark("start");
const end = performance.mark("end");
const entry = performanceMeasurePolyfill("measure", {
start: "start",
end: "end",
});
await t.step(
"5. Set entry's name attribute to measureName.",
() => assertEquals(entry.name, "measure"),
);
await t.step(
`6. Set entry's entryType attribute to DOMString "measure"`,
() => assertEquals(entry.entryType, "measure"),
);
await t.step(
"7. Set entry's startTime attribute to start time.",
() => assertEquals(entry.startTime, start.startTime),
);
await t.step(
"8. Set entry's duration attribute to the duration from start time to end time. The resulting duration value MAY be negative.",
() => assertEquals(entry.duration, end.startTime - start.startTime),
);
await t.step(
"9. Set entry's detail attribute as follows:",
() => assertEquals(entry.detail, null),
);
await t.step(
"toJSON",
() => {
assertEquals(entry.toJSON(), {
name: "measure",
entryType: "measure",
startTime: start.startTime,
duration: end.startTime - start.startTime,
detail: null,
});
},
);
cleanup();
},
);