@@ -10,7 +10,7 @@ const sourcemap = require('source-map')
10
10
const assert = require ( 'assert' )
11
11
12
12
require ( 'tap' ) . mochaGlobals ( )
13
- require ( 'should' )
13
+ const should = require ( 'should' )
14
14
15
15
describe ( 'V8ToIstanbul' , async ( ) => {
16
16
describe ( 'constructor' , ( ) => {
@@ -22,6 +22,8 @@ describe('V8ToIstanbul', async () => {
22
22
v8ToIstanbul . covSources [ 0 ] . source . lines . length . should . equal ( 48 )
23
23
v8ToIstanbul . covSources . length . should . equal ( 1 )
24
24
v8ToIstanbul . wrapperLength . should . equal ( 0 ) // common-js header.
25
+
26
+ v8ToIstanbul . destroy ( )
25
27
} )
26
28
27
29
it ( 'handles ESM style paths' , async ( ) => {
@@ -33,6 +35,8 @@ describe('V8ToIstanbul', async () => {
33
35
v8ToIstanbul . covSources [ 0 ] . source . lines . length . should . equal ( 48 )
34
36
v8ToIstanbul . covSources . length . should . equal ( 1 )
35
37
v8ToIstanbul . wrapperLength . should . equal ( 0 ) // ESM header.
38
+
39
+ v8ToIstanbul . destroy ( )
36
40
} )
37
41
38
42
it ( 'handles source maps with sourceRoot' , async ( ) => {
@@ -60,6 +64,8 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
60
64
await v8ToIstanbul . load ( )
61
65
62
66
v8ToIstanbul . path . should . equal ( absoluteSourceFilePath )
67
+
68
+ v8ToIstanbul . destroy ( )
63
69
} )
64
70
65
71
it ( 'handles sourceContent' , async ( ) => {
@@ -91,6 +97,8 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
91
97
// if the source is transpiled and since we didn't inline the source map into the transpiled source file
92
98
// that means it was bale to access the content via the provided sources object
93
99
v8ToIstanbul . sourceTranspiled . should . not . be . undefined ( )
100
+
101
+ v8ToIstanbul . destroy ( )
94
102
} )
95
103
96
104
it ( 'should clamp line source column >= 0' , async ( ) => {
@@ -121,6 +129,8 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
121
129
endOffset : matchedNewLineChar + 10
122
130
} ]
123
131
} ] )
132
+
133
+ v8ToIstanbul . destroy ( )
124
134
} )
125
135
126
136
it ( 'should exclude files when passing excludePath' , async ( ) => {
@@ -139,6 +149,8 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
139
149
} ]
140
150
} ] )
141
151
Object . keys ( v8ToIstanbul . toIstanbul ( ) ) . should . eql ( [ '/src/index.ts' , '/src/utils.ts' ] . map ( path . normalize ) )
152
+
153
+ v8ToIstanbul . destroy ( )
142
154
} )
143
155
} )
144
156
@@ -157,6 +169,7 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
157
169
0
158
170
)
159
171
await v8ToIstanbul . load ( )
172
+ v8ToIstanbul . destroy ( )
160
173
} )
161
174
162
175
it ( 'should handle relative sourceRoots correctly' , async ( ) => {
@@ -166,6 +179,7 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
166
179
)
167
180
await v8ToIstanbul . load ( )
168
181
assert ( v8ToIstanbul . path . includes ( path . normalize ( 'v8-to-istanbul/test/fixtures/one-up/relative-source-root.js' ) ) )
182
+ v8ToIstanbul . destroy ( )
169
183
} )
170
184
171
185
it ( 'should handles source maps with multiple sources' , async ( ) => {
@@ -177,9 +191,25 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
177
191
178
192
v8ToIstanbul . covSources . length . should . equal ( 3 )
179
193
Object . keys ( v8ToIstanbul . toIstanbul ( ) ) . should . eql ( [ '/webpack/bootstrap' , '/src/index.ts' , '/src/utils.ts' ] . map ( path . normalize ) )
194
+
195
+ v8ToIstanbul . destroy ( )
180
196
} )
181
197
} )
182
198
199
+ it ( 'destroy cleans up source map' , async ( ) => {
200
+ const v8ToIstanbul = new V8ToIstanbul (
201
+ pathToFileURL ( require . resolve ( './fixtures/scripts/empty.compiled.js' ) ) . href
202
+ )
203
+ await v8ToIstanbul . load ( )
204
+ // assertion only to check test data and setup - source map must be loaded,
205
+ // otherwise destroy would have no effect anyway
206
+ assert ( v8ToIstanbul . sourceMap !== undefined , 'Test fixture must load a source map' )
207
+
208
+ v8ToIstanbul . destroy ( )
209
+
210
+ should . not . exist ( v8ToIstanbul . sourceMap )
211
+ } )
212
+
183
213
// execute JavaScript files in fixtures directory; these
184
214
// files contain the raw v8 output along with a set of
185
215
// assertions. the original scripts can be found in the
0 commit comments