2
2
3
3
const common = require ( '../common.js' ) ;
4
4
const assert = require ( 'assert' ) ;
5
- const fs = require ( 'fs' ) ;
6
- const path = require ( 'path' ) ;
5
+ const fixtures = require ( '../../test/common/fixtures' ) ;
7
6
8
7
const bench = common . createBenchmark (
9
8
main ,
@@ -24,19 +23,14 @@ function main({ operation, n }) {
24
23
const { SourceMap } = require ( 'node:module' ) ;
25
24
26
25
const samplePayload = JSON . parse (
27
- fs . readFileSync (
28
- path . resolve ( __dirname , '../../test/fixtures/source-map/no-source.js.map' ) ,
29
- 'utf8' ,
30
- ) ,
26
+ fixtures . readSync ( 'source-map/no-source.js.map' , 'utf8' ) ,
31
27
) ;
32
28
const sectionedPayload = JSON . parse (
33
- fs . readFileSync (
34
- path . resolve ( __dirname , '../../test/fixtures/source-map/disk-index.map' ) ,
35
- 'utf8' ,
36
- ) ,
29
+ fixtures . readSync ( 'source-map/disk-index.map' , 'utf8' ) ,
37
30
) ;
38
31
39
32
let sourceMap ;
33
+ let sourceMapMethod ;
40
34
switch ( operation ) {
41
35
case 'parse' :
42
36
bench . start ( ) ;
@@ -58,36 +52,40 @@ function main({ operation, n }) {
58
52
sourceMap = new SourceMap ( samplePayload ) ;
59
53
bench . start ( ) ;
60
54
for ( let i = 0 ; i < n ; i ++ ) {
61
- sourceMap . findEntry ( i , i ) ;
55
+ sourceMapMethod = sourceMap . findEntry ( i , i ) ;
62
56
}
63
57
bench . end ( n ) ;
58
+ assert . ok ( sourceMapMethod ) ;
64
59
break ;
65
60
66
61
case 'findEntry-sectioned' :
67
62
sourceMap = new SourceMap ( sectionedPayload ) ;
68
63
bench . start ( ) ;
69
64
for ( let i = 0 ; i < n ; i ++ ) {
70
- sourceMap . findEntry ( i , i ) ;
65
+ sourceMapMethod = sourceMap . findEntry ( i , i ) ;
71
66
}
72
67
bench . end ( n ) ;
68
+ assert . ok ( sourceMapMethod ) ;
73
69
break ;
74
70
75
71
case 'findOrigin' :
76
72
sourceMap = new SourceMap ( samplePayload ) ;
77
73
bench . start ( ) ;
78
74
for ( let i = 0 ; i < n ; i ++ ) {
79
- sourceMap . findOrigin ( i , i ) ;
75
+ sourceMapMethod = sourceMap . findOrigin ( i , i ) ;
80
76
}
81
77
bench . end ( n ) ;
78
+ assert . ok ( sourceMapMethod ) ;
82
79
break ;
83
80
84
81
case 'findOrigin-sectioned' :
85
82
sourceMap = new SourceMap ( sectionedPayload ) ;
86
83
bench . start ( ) ;
87
84
for ( let i = 0 ; i < n ; i ++ ) {
88
- sourceMap . findOrigin ( i , i ) ;
85
+ sourceMapMethod = sourceMap . findOrigin ( i , i ) ;
89
86
}
90
87
bench . end ( n ) ;
88
+ assert . ok ( sourceMapMethod ) ;
91
89
break ;
92
90
93
91
default :
0 commit comments