|
1 | 1 | import { type PerformanceMarkOptions, performance } from 'node:perf_hooks'; |
2 | | -import { describe, expectTypeOf, it } from 'vitest'; |
| 2 | +import { describe, expect, expectTypeOf, it } from 'vitest'; |
3 | 3 |
|
4 | 4 | describe('perf-hooks definitions', () => { |
5 | 5 | it('PerformanceMarkOptions should be type safe', () => { |
6 | | - expectTypeOf<{ |
7 | | - startTime: number; |
8 | | - detail: { |
9 | | - devtools: { |
10 | | - dataType: 'marker'; |
11 | | - color: 'error'; |
| 6 | + expect(() => |
| 7 | + expectTypeOf<{ |
| 8 | + startTime: number; |
| 9 | + detail: { |
| 10 | + devtools: { |
| 11 | + dataType: 'marker'; |
| 12 | + color: 'error'; |
| 13 | + }; |
12 | 14 | }; |
13 | | - }; |
14 | | - }>().toMatchTypeOf<PerformanceMarkOptions>(); |
15 | | - expectTypeOf<{ |
16 | | - startTime: number; |
17 | | - detail: { |
18 | | - devtools: { |
19 | | - dataType: 'markerr'; |
| 15 | + }>().toMatchTypeOf<PerformanceMarkOptions>(), |
| 16 | + ).not.toThrow(); |
| 17 | + |
| 18 | + expect(() => |
| 19 | + expectTypeOf<{ |
| 20 | + startTime: number; |
| 21 | + detail: { |
| 22 | + devtools: { |
| 23 | + dataType: 'markerr'; |
| 24 | + }; |
20 | 25 | }; |
21 | | - }; |
22 | | - }>().not.toMatchTypeOf<PerformanceMarkOptions>(); |
| 26 | + }>().not.toMatchTypeOf<PerformanceMarkOptions>(), |
| 27 | + ).not.toThrow(); |
23 | 28 | }); |
24 | 29 |
|
25 | 30 | it('perf_hooks.mark should be type safe', () => { |
26 | | - performance.mark('name', { |
27 | | - detail: { |
28 | | - devtools: { |
29 | | - dataType: 'marker', |
30 | | - color: 'error', |
| 31 | + expect(() => |
| 32 | + performance.mark('name', { |
| 33 | + detail: { |
| 34 | + devtools: { |
| 35 | + dataType: 'marker', |
| 36 | + color: 'error', |
| 37 | + }, |
31 | 38 | }, |
32 | | - }, |
33 | | - }); |
| 39 | + }), |
| 40 | + ).not.toThrow(); |
34 | 41 |
|
35 | | - performance.mark('name', { |
36 | | - detail: { |
37 | | - devtools: { |
38 | | - /* @ts-expect-error - dataType should be marker | track */ |
39 | | - dataType: 'markerrr', |
40 | | - color: 'error', |
| 42 | + expect(() => |
| 43 | + performance.mark('name', { |
| 44 | + detail: { |
| 45 | + devtools: { |
| 46 | + // @ts-expect-error - dataType should be marker | track |
| 47 | + dataType: 'markerrr', |
| 48 | + color: 'error', |
| 49 | + }, |
41 | 50 | }, |
42 | | - }, |
43 | | - }); |
| 51 | + }), |
| 52 | + ).not.toThrow(); |
44 | 53 | }); |
45 | 54 |
|
46 | 55 | it('PerformanceMeasureOptions should be type safe', () => { |
47 | | - expectTypeOf<{ |
48 | | - start: string; |
49 | | - end: string; |
50 | | - detail: { |
51 | | - devtools: { |
52 | | - dataType: 'track-entry'; |
53 | | - track: 'test-track'; |
54 | | - color: 'primary'; |
| 56 | + expect(() => |
| 57 | + expectTypeOf<{ |
| 58 | + start: string; |
| 59 | + end: string; |
| 60 | + detail: { |
| 61 | + devtools: { |
| 62 | + dataType: 'track-entry'; |
| 63 | + track: 'test-track'; |
| 64 | + color: 'primary'; |
| 65 | + }; |
55 | 66 | }; |
56 | | - }; |
57 | | - }>().toMatchTypeOf<PerformanceMeasureOptions>(); |
| 67 | + }>().toMatchTypeOf<PerformanceMeasureOptions>(), |
| 68 | + ).not.toThrow(); |
58 | 69 | }); |
59 | 70 |
|
60 | 71 | it('perf_hooks.measure should be type safe', () => { |
61 | | - performance.measure('measure-name', 'start-mark', 'end-mark'); |
| 72 | + expect(() => |
| 73 | + performance.measure('measure-name', 'start-mark', 'end-mark'), |
| 74 | + ).not.toThrow(); |
62 | 75 |
|
63 | | - performance.measure('measure-name', { |
64 | | - start: 'start-mark', |
65 | | - end: 'end-mark', |
66 | | - detail: { |
67 | | - /* @ts-expect-error - track is required */ |
68 | | - devtools: { |
69 | | - dataType: 'track-entry', |
70 | | - color: 'primary', |
| 76 | + expect(() => |
| 77 | + performance.measure('measure-name', { |
| 78 | + start: 'start-mark', |
| 79 | + end: 'end-mark', |
| 80 | + detail: { |
| 81 | + // @ts-expect-error - track is required |
| 82 | + devtools: { |
| 83 | + dataType: 'track-entry', |
| 84 | + color: 'primary', |
| 85 | + }, |
71 | 86 | }, |
72 | | - }, |
73 | | - }); |
| 87 | + }), |
| 88 | + ).not.toThrow(); |
74 | 89 | }); |
75 | 90 | }); |
0 commit comments