Skip to content
File

Blob: src/workerd/tests/performance-test.js

javascript39 lines
1// Copyright (c) 2023 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5if (typeof globalThis.performance === 'undefined') {
6 throw new Error('performance is not defined');
7}
8 
9if (globalThis.performance.timeOrigin !== 0.0) {
10 throw new Error('performance.timeOrigin is not 0.0');
11}
12 
13if (globalThis.performance.now() !== 0.0) {
14 throw new Error('performance.now() is not 0.0');
15}
16 
17if ('addEventListener' in globalThis.performance) {
18 throw new Error('performance.addEventListener should not be defined');
19}
20 
21// Performance class should not be available.
22if (typeof globalThis.Performance !== 'undefined') {
23 throw new Error('Performance should not be defined');
24}
25 
26export const test = {
27 async test(_ctrl, _env, _ctx) {
28 const start = performance.now();
29 // There should be at least some time elapsed.
30 if (start == 0.0) {
31 throw new Error('performance.now() is 0.0');
32 }
33 await scheduler.wait(500);
34 if (start == performance.now()) {
35 throw new Error('performance.now() is not increasing');
36 }
37 },
38};