3
3
const common = require ( '../common.js' ) ;
4
4
const assert = require ( 'assert' ) ;
5
5
const path = require ( 'path' ) ;
6
-
7
- const options = {
8
- flags : [ '--expose-internals' ] ,
9
- } ;
6
+ const fs = require ( 'fs' ) ;
10
7
11
8
const bench = common . createBenchmark (
12
9
main ,
@@ -17,34 +14,29 @@ const bench = common.createBenchmark(
17
14
] ,
18
15
n : [ 1e5 ] ,
19
16
} ,
20
- options ,
21
17
) ;
22
18
23
19
function main ( { operation, n } ) {
24
20
const Module = require ( 'node:module' ) ;
25
21
26
- Module . setSourceMapsSupport ( true ) ;
22
+ Module . setSourceMapsSupport ( true , {
23
+ generatedCode : true ,
24
+ } ) ;
27
25
const validFileName = path . resolve (
28
26
__dirname ,
29
27
'../../test/fixtures/test-runner/source-maps/line-lengths/index.js' ,
30
28
) ;
31
29
32
- const sourceWithGeneratedSourceMap = `
33
- console.log("Hello from generated source");
34
- function test() {
35
- return 42;
36
- }
37
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUFDQTtBQUNBO0FBQ0EiLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKFwiSGVsbG8gZnJvbSBnZW5lcmF0ZWQgc291cmNlXCIpO1xuZnVuY3Rpb24gdGVzdCgpIHtcbiAgcmV0dXJuIDQyO1xufSJdfQ==
38
- //# sourceURL=test-generated-source.js
39
- ` ;
40
- const expectedUrl = `file://${ path . resolve ( 'test-generated-source.js' ) } ` ;
30
+ const fileContent = fs . readFileSync ( validFileName , 'utf8' ) ;
31
+ const sourceWithGeneratedSourceMap = fileContent + `\n//# sourceURL=${ validFileName } ` ;
32
+ const expectedUrl = `file://${ path . resolve ( validFileName ) } ` ;
41
33
42
34
let sourceMap ;
43
35
switch ( operation ) {
44
36
case 'findSourceMap-valid' :
45
37
require ( validFileName ) ;
46
- bench . start ( ) ;
47
38
39
+ bench . start ( ) ;
48
40
for ( let i = 0 ; i < n ; i ++ ) {
49
41
sourceMap = Module . findSourceMap ( validFileName ) ;
50
42
}
0 commit comments