11var expect = require ( 'chai' ) . expect
2- var os = require ( 'os' )
3- var fs = require ( 'fs' )
42var EventEmitter = require ( 'events' ) . EventEmitter
53
6- var heapdump = require ( '../../../optionalDependencies/heapdump ' )
4+ var v8profiler = require ( '../../../optionalDependencies/v8-profiler ' )
75
86var MemoryProfiler = require ( './' )
97
@@ -13,32 +11,34 @@ describe('The Memory Profiler module', function () {
1311 var collectorApi = {
1412 sendMemorySnapshot : this . sandbox . spy ( )
1513 }
16-
17- var snapShotContent = 'very- snapshot'
14+ var deleteSnapshotSpy = this . sandbox . spy ( )
15+ var snapshotContent = 'snapshot'
1816 var now = 1234
1917
2018 var profiler = MemoryProfiler . create ( {
2119 collectorApi : collectorApi ,
2220 controlBus : msgBus
2321 } )
2422
25- this . sandbox . stub ( heapdump , 'writeSnapshot' , function ( path , cb ) {
26- cb ( )
23+ this . sandbox . stub ( v8profiler , 'takeSnapshot' , function ( ) {
24+ return {
25+ export : function ( cb ) {
26+ cb ( null , snapshotContent )
27+ } ,
28+ delete : deleteSnapshotSpy
29+ }
2730 } )
2831
2932 this . sandbox . stub ( Date , 'now' , function ( ) {
3033 return now
3134 } )
3235
33- this . sandbox . stub ( fs , 'readFile' , function ( path , encoding , cb ) {
34- cb ( null , snapShotContent )
35- } )
36-
3736 profiler . sendSnapshot ( )
3837
3938 expect ( collectorApi . sendMemorySnapshot ) . to . be . calledWith ( {
40- heapSnapshot : snapShotContent ,
39+ heapSnapshot : snapshotContent ,
4140 time : now
4241 } )
42+ expect ( deleteSnapshotSpy ) . to . be . called
4343 } )
4444} )
0 commit comments