Skip to content

Commit e193161

Browse files
committed
fix test isolation in stack_trace.spec.js
1 parent e11a03e commit e193161

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

test/stack_trace.spec.js

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
const fs = require('fs')
99
const path = require('path')
10-
const proxyquire = require('proxyquire').noPreserveCache()
10+
const proxyquire = require('proxyquire')
1111

1212
const { getPrepareStackTrace } = require('../js/stack-trace')
1313
const { getSourcePathAndLineFromSourceMaps } = require('../js/source-map')
@@ -147,36 +147,45 @@ describe('getFilenameFromSourceMap', () => {
147147
})
148148

149149
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+
}
158164

159-
get (key) {
160-
getLRU(key)
161-
return sourceMapsMap.get(key)
165+
get (key) {
166+
getLRU(key)
167+
return sourceMapsMap.get(key)
168+
}
162169
}
163-
}
164170

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+
}
177184
}
178185
}
179-
}
186+
})
187+
188+
getOriginalPathAndLineFromSourceMap = sourceMap.getOriginalPathAndLineFromSourceMap
180189
})
181190

182191
const fileName = 'test-inline.js'
@@ -185,13 +194,6 @@ describe('getOriginalPathAndLineFromSourceMapFromSourceMap', () => {
185194
line: 5
186195
}
187196

188-
afterEach(() => {
189-
sinon.reset()
190-
setLRU.resetHistory()
191-
getLRU.resetHistory()
192-
sourceMapsMap.clear()
193-
})
194-
195197
it('should add SourceMap to cache', () => {
196198
const pathAndLine = getOriginalPathAndLineFromSourceMap(originalPathAndLine.path, originalPathAndLine.line, 12)
197199

0 commit comments

Comments
 (0)