1
1
'use strict'
2
2
3
3
require ( '../../setup/mocha' )
4
+ const { NODE_MAJOR } = require ( '../../../../../version' )
4
5
5
6
const parsedSourceMap = {
6
7
version : 3 ,
@@ -94,13 +95,62 @@ describe('source map utils', function () {
94
95
} )
95
96
} )
96
97
98
+ describe ( 'no cache' , function ( ) {
99
+ function setup ( ) {
100
+ readFileSync = sinon . stub ( ) . returns ( rawSourceMap )
101
+ readFile = sinon . stub ( ) . resolves ( rawSourceMap )
102
+
103
+ const sourceMaps = proxyquire ( '../src/debugger/devtools_client/source-maps' , {
104
+ fs : { readFileSync } ,
105
+ 'fs/promises' : { readFile }
106
+ } )
107
+
108
+ loadSourceMap = sourceMaps . loadSourceMap
109
+ loadSourceMapSync = sourceMaps . loadSourceMapSync
110
+ }
111
+
112
+ before ( function ( ) {
113
+ if ( NODE_MAJOR > 18 ) this . skip ( )
114
+ } )
115
+
116
+ describe ( 'loadSourceMap' , function ( ) {
117
+ before ( setup )
118
+
119
+ it ( 'should read from disk on the fist call' , async function ( ) {
120
+ const sourceMap = await loadSourceMap ( dir , sourceMapURL )
121
+ expect ( sourceMap ) . to . deep . equal ( parsedSourceMap )
122
+ expect ( readFile . callCount ) . to . equal ( 1 )
123
+ } )
124
+
125
+ it ( 'should read from disk on the second call' , async function ( ) {
126
+ const sourceMap = await loadSourceMap ( dir , sourceMapURL )
127
+ expect ( sourceMap ) . to . deep . equal ( parsedSourceMap )
128
+ expect ( readFile . callCount ) . to . equal ( 2 )
129
+ } )
130
+ } )
131
+
132
+ describe ( 'loadSourceMapSync' , function ( ) {
133
+ before ( setup )
134
+
135
+ it ( 'should read from disk on the fist call' , function ( ) {
136
+ const sourceMap = loadSourceMapSync ( dir , sourceMapURL )
137
+ expect ( sourceMap ) . to . deep . equal ( parsedSourceMap )
138
+ expect ( readFileSync . callCount ) . to . equal ( 1 )
139
+ } )
140
+
141
+ it ( 'should read from disk on the second call' , function ( ) {
142
+ const sourceMap = loadSourceMapSync ( dir , sourceMapURL )
143
+ expect ( sourceMap ) . to . deep . equal ( parsedSourceMap )
144
+ expect ( readFileSync . callCount ) . to . equal ( 2 )
145
+ } )
146
+ } )
147
+ } )
148
+
97
149
describe ( 'cache' , function ( ) {
98
150
let clock
99
151
100
152
function setup ( ) {
101
- clock = sinon . useFakeTimers ( {
102
- toFake : [ 'setTimeout' ]
103
- } )
153
+ clock = sinon . useFakeTimers ( )
104
154
readFileSync = sinon . stub ( ) . returns ( rawSourceMap )
105
155
readFile = sinon . stub ( ) . resolves ( rawSourceMap )
106
156
@@ -117,6 +167,10 @@ describe('source map utils', function () {
117
167
clock . restore ( )
118
168
}
119
169
170
+ before ( function ( ) {
171
+ if ( NODE_MAJOR < 20 ) this . skip ( )
172
+ } )
173
+
120
174
describe ( 'loadSourceMap' , function ( ) {
121
175
before ( setup )
122
176
@@ -134,8 +188,8 @@ describe('source map utils', function () {
134
188
expect ( readFile . callCount ) . to . equal ( 1 )
135
189
} )
136
190
137
- it ( 'should clear cache after 10 seconds' , async function ( ) {
138
- clock . tick ( 10_000 )
191
+ it ( 'should clear cache after 5 seconds' , async function ( ) {
192
+ clock . tick ( 5_000 )
139
193
const sourceMap = await loadSourceMap ( dir , sourceMapURL )
140
194
expect ( sourceMap ) . to . deep . equal ( parsedSourceMap )
141
195
expect ( readFile . callCount ) . to . equal ( 2 )
@@ -159,8 +213,8 @@ describe('source map utils', function () {
159
213
expect ( readFileSync . callCount ) . to . equal ( 1 )
160
214
} )
161
215
162
- it ( 'should clear cache after 10 seconds' , function ( ) {
163
- clock . tick ( 10_000 )
216
+ it ( 'should clear cache after 5 seconds' , function ( ) {
217
+ clock . tick ( 5_000 )
164
218
const sourceMap = loadSourceMapSync ( dir , sourceMapURL )
165
219
expect ( sourceMap ) . to . deep . equal ( parsedSourceMap )
166
220
expect ( readFileSync . callCount ) . to . equal ( 2 )
0 commit comments