@@ -19,25 +19,43 @@ describe('Unit: Doctor Checks > Memory', function () {
19
19
20
20
expect ( checkMem . title ) . to . equal ( 'Checking memory availability' ) ;
21
21
expect ( checkMem . task ) . to . be . a ( 'function' ) ;
22
+ expect ( checkMem . enabled ) . to . a ( 'function' ) ;
22
23
expect ( checkMem . category ) . to . deep . equal ( [ 'install' , 'start' , 'update' ] ) ;
23
24
} ) ;
24
25
25
- it ( 'errors if not enough memory is available' , function ( ) {
26
+ it ( 'enabled is determined by check-mem argument' , function ( ) {
27
+ const memCheck = require ( modulePath ) ;
28
+ const ctx = {
29
+ argv : { 'check-mem' : false }
30
+ } ;
31
+
32
+ expect ( memCheck . enabled ( ctx ) ) . to . be . false ;
33
+ ctx . argv [ 'check-mem' ] = true ;
34
+ expect ( memCheck . enabled ( ctx ) ) . to . be . true ;
35
+ } ) ;
36
+
37
+ it ( 'fails if not enough memory is available' , function ( ) {
26
38
const osStub = sandbox . stub ( os , 'freemem' ) . returns ( 10 ) ;
27
39
const memCheck = require ( modulePath ) ;
40
+ const ctx = {
41
+ argv : { 'check-mem' : true }
42
+ } ;
28
43
29
- return memCheck . task ( ) . catch ( ( error ) => {
44
+ return memCheck . task ( ctx ) . catch ( ( error ) => {
30
45
expect ( error ) . to . be . an . instanceof ( errors . SystemError ) ;
31
46
expect ( error . message ) . to . match ( / M B o f m e m o r y a v a i l a b l e f o r s m o o t h o p e r a t i o n / ) ;
32
47
expect ( osStub . calledOnce ) . to . be . true ;
33
48
} ) ;
34
49
} ) ;
35
50
36
- it ( 'works if there is enough memory' , function ( ) {
51
+ it ( 'passes if there is enough memory' , function ( ) {
37
52
const osStub = sandbox . stub ( os , 'freemem' ) . returns ( 157286400 ) ;
38
53
const memCheck = require ( modulePath ) ;
54
+ const ctx = {
55
+ argv : { 'check-mem' : true }
56
+ } ;
39
57
40
- return memCheck . task ( ) . then ( ( ) => {
58
+ return memCheck . task ( ctx ) . then ( ( ) => {
41
59
expect ( osStub . calledOnce ) . to . be . true ;
42
60
} ) ;
43
61
} ) ;
0 commit comments