• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// This file may needs to be updated to wpt:
2// https://github.com/web-platform-tests/wpt
3
4import '../common/index.mjs';
5import assert from 'assert';
6
7import { performance } from 'perf_hooks';
8import { setTimeout } from 'timers/promises';
9
10// Order by startTime
11performance.mark('one');
12await setTimeout(50);
13performance.mark('two');
14await setTimeout(50);
15performance.mark('three');
16await setTimeout(50);
17performance.measure('three', 'three');
18await setTimeout(50);
19performance.measure('two', 'two');
20await setTimeout(50);
21performance.measure('one', 'one');
22const entries = performance.getEntriesByType('measure');
23assert.deepStrictEqual(entries.map((x) => x.name), ['one', 'two', 'three']);
24const allEntries = performance.getEntries();
25assert.deepStrictEqual(allEntries.map((x) => x.name), ['one', 'one', 'two', 'two', 'three', 'three']);
26
27performance.mark('a');
28await setTimeout(50);
29performance.measure('a', 'a');
30await setTimeout(50);
31performance.mark('a');
32await setTimeout(50);
33performance.measure('a', 'one');
34const entriesByName = performance.getEntriesByName('a');
35assert.deepStrictEqual(entriesByName.map((x) => x.entryType), ['measure', 'mark', 'measure', 'mark']);
36
37// getEntriesBy[Name|Type](undefined)
38performance.mark(undefined);
39assert.strictEqual(performance.getEntriesByName(undefined).length, 1);
40assert.strictEqual(performance.getEntriesByType(undefined).length, 0);
41assert.throws(() => performance.getEntriesByName(), {
42  name: 'TypeError',
43  message: 'The "name" argument must be specified',
44  code: 'ERR_MISSING_ARGS'
45});
46assert.throws(() => performance.getEntriesByType(), {
47  name: 'TypeError',
48  message: 'The "type" argument must be specified',
49  code: 'ERR_MISSING_ARGS'
50});
51