@@ -4,7 +4,7 @@ const fs = require('graceful-fs')
44const { log, time } = require ( 'proc-log' )
55const tmock = require ( '../../fixtures/tmock' )
66
7- const mockTimers = ( t , options ) => {
7+ const mockTimers = ( t ) => {
88 const logs = log . LEVELS . reduce ( ( acc , l ) => {
99 acc [ l ] = [ ]
1010 return acc
@@ -14,40 +14,20 @@ const mockTimers = (t, options) => {
1414 }
1515 process . on ( 'log' , logHandler )
1616 const Timers = tmock ( t , '{LIB}/utils/timers' )
17- const timers = new Timers ( options )
17+ const timers = new Timers ( )
1818 t . teardown ( ( ) => {
1919 timers . off ( )
2020 process . off ( 'log' , logHandler )
2121 } )
2222 return { timers, logs }
2323}
2424
25- t . test ( 'listens/stops on process' , async ( t ) => {
26- const { timers } = mockTimers ( t )
27- time . start ( 'foo' )
28- time . start ( 'bar' )
29- time . end ( 'bar' )
30- t . match ( timers . unfinished , new Map ( [ [ 'foo' , Number ] ] ) )
31- t . match ( timers . finished , { bar : Number } )
32- timers . off ( )
33- time . start ( 'baz' )
34- t . notOk ( timers . unfinished . get ( 'baz' ) )
35- } )
36-
37- t . test ( 'initial timer is named npm' , async ( t ) => {
38- const { timers } = mockTimers ( t )
39- time . end ( 'npm' )
40- t . match ( timers . finished , { npm : Number } )
41- } )
42-
4325t . test ( 'logs timing events' , async ( t ) => {
44- const events = [ ]
45- const listener = ( ...args ) => events . push ( args )
46- const { timers, logs } = mockTimers ( t , { listener } )
26+ const { timers, logs } = mockTimers ( t )
4727 time . start ( 'foo' )
4828 time . start ( 'bar' )
4929 time . end ( 'bar' )
50- timers . off ( listener )
30+ timers . off ( )
5131 time . end ( 'foo' )
5232 t . equal ( logs . timing . length , 1 )
5333 t . match ( logs . timing [ 0 ] , / ^ b a r C o m p l e t e d i n [ 0 - 9 ] m s / )
@@ -64,14 +44,15 @@ t.test('writes file', async (t) => {
6444 const dir = t . testdir ( )
6545 time . start ( 'foo' )
6646 time . end ( 'foo' )
67- timers . load ( { path : resolve ( dir , `TIMING_FILE-` ) } )
68- timers . writeFile ( { some : 'data' } )
47+ time . start ( 'ohno' )
48+ timers . load ( { timing : true , path : resolve ( dir , `TIMING_FILE-` ) } )
49+ timers . finish ( { some : 'data' } )
6950 const data = JSON . parse ( fs . readFileSync ( resolve ( dir , 'TIMING_FILE-timing.json' ) ) )
7051 t . match ( data , {
7152 metadata : { some : 'data' } ,
72- timers : { foo : Number } ,
53+ timers : { foo : Number , npm : Number } ,
7354 unfinishedTimers : {
74- npm : [ Number , Number ] ,
55+ ohno : [ Number , Number ] ,
7556 } ,
7657 } )
7758} )
@@ -80,20 +61,18 @@ t.test('fails to write file', async (t) => {
8061 const { logs, timers } = mockTimers ( t )
8162 const dir = t . testdir ( )
8263
83- timers . load ( { path : join ( dir , 'does' , 'not' , 'exist' ) } )
84- timers . writeFile ( )
64+ timers . load ( { timing : true , path : join ( dir , 'does' , 'not' , 'exist' ) } )
65+ timers . finish ( )
8566
8667 t . match ( logs . warn , [ 'timing could not write timing file:' ] )
87- t . equal ( timers . file , null )
8868} )
8969
9070t . test ( 'no dir and no file' , async ( t ) => {
9171 const { logs, timers } = mockTimers ( t )
9272
9373 timers . load ( )
94- timers . writeFile ( )
74+ timers . finish ( )
9575
9676 t . strictSame ( logs . warn , [ ] )
9777 t . strictSame ( logs . silly , [ ] )
98- t . equal ( timers . file , null )
9978} )
0 commit comments