7
7
8
8
const fs = require ( 'fs' )
9
9
const path = require ( 'path' )
10
- const proxyquire = require ( 'proxyquire' ) . noPreserveCache ( )
10
+ const proxyquire = require ( 'proxyquire' )
11
11
12
12
const { getPrepareStackTrace } = require ( '../js/stack-trace' )
13
13
const { getSourcePathAndLineFromSourceMaps } = require ( '../js/source-map' )
@@ -147,36 +147,45 @@ describe('getFilenameFromSourceMap', () => {
147
147
} )
148
148
149
149
describe ( 'getOriginalPathAndLineFromSourceMapFromSourceMap' , ( ) => {
150
- const sourceMapsMap = new Map ( )
151
- const setLRU = sinon . spy ( )
152
- const getLRU = sinon . spy ( )
153
- class LRU {
154
- set ( key , value ) {
155
- setLRU ( key , value )
156
- return sourceMapsMap . set ( key , value )
157
- }
150
+ let sourceMapsMap
151
+ let setLRU
152
+ let getLRU
153
+ let getOriginalPathAndLineFromSourceMap
154
+
155
+ beforeEach ( ( ) => {
156
+ sourceMapsMap = new Map ( )
157
+ setLRU = sinon . spy ( )
158
+ getLRU = sinon . spy ( )
159
+ class LRU {
160
+ set ( key , value ) {
161
+ setLRU ( key , value )
162
+ return sourceMapsMap . set ( key , value )
163
+ }
158
164
159
- get ( key ) {
160
- getLRU ( key )
161
- return sourceMapsMap . get ( key )
165
+ get ( key ) {
166
+ getLRU ( key )
167
+ return sourceMapsMap . get ( key )
168
+ }
162
169
}
163
- }
164
170
165
- const { getOriginalPathAndLineFromSourceMap } = proxyquire ( '../js/source-map' , {
166
- 'lru-cache' : LRU ,
167
- './node_source_map' : nodeSourceMap ,
168
- fs : {
169
- readFileSync : ( filename ) => {
170
- switch ( filename ) {
171
- case 'no-sourcemap' :
172
- return ''
173
- case 'error' :
174
- throw new Error ( 'errr' )
175
- default :
176
- return readFileSync ( filename )
171
+ const sourceMap = proxyquire ( '../js/source-map' , {
172
+ 'lru-cache' : LRU ,
173
+ './node_source_map' : nodeSourceMap ,
174
+ fs : {
175
+ readFileSync : ( filename ) => {
176
+ switch ( filename ) {
177
+ case 'no-sourcemap' :
178
+ return ''
179
+ case 'error' :
180
+ throw new Error ( 'errr' )
181
+ default :
182
+ return readFileSync ( filename )
183
+ }
177
184
}
178
185
}
179
- }
186
+ } )
187
+
188
+ getOriginalPathAndLineFromSourceMap = sourceMap . getOriginalPathAndLineFromSourceMap
180
189
} )
181
190
182
191
const fileName = 'test-inline.js'
@@ -185,13 +194,6 @@ describe('getOriginalPathAndLineFromSourceMapFromSourceMap', () => {
185
194
line : 5
186
195
}
187
196
188
- afterEach ( ( ) => {
189
- sinon . reset ( )
190
- setLRU . resetHistory ( )
191
- getLRU . resetHistory ( )
192
- sourceMapsMap . clear ( )
193
- } )
194
-
195
197
it ( 'should add SourceMap to cache' , ( ) => {
196
198
const pathAndLine = getOriginalPathAndLineFromSourceMap ( originalPathAndLine . path , originalPathAndLine . line , 12 )
197
199
0 commit comments