@@ -13,7 +13,7 @@ const localExtensions = [
13
13
] ;
14
14
15
15
describe ( 'Unit: Utils > find-extensions' , function ( ) {
16
- let findExtensions , findStub ;
16
+ let findExtensions , findStub , existsStub ;
17
17
18
18
beforeEach ( ( ) => {
19
19
findStub = sinon . stub ( ) . returns ( [
@@ -28,13 +28,17 @@ describe('Unit: Utils > find-extensions', function () {
28
28
}
29
29
] ) ;
30
30
31
+ existsStub = sinon . stub ( ) ;
32
+
31
33
findExtensions = proxyquire ( modulePath , {
32
34
'find-plugins' : findStub ,
33
- 'global-modules' : '.'
35
+ 'global-modules' : '.' ,
36
+ fs : { existsSync : existsStub }
34
37
} ) ;
35
38
} ) ;
36
39
37
40
it ( 'calls find-plugins with proper args' , function ( ) {
41
+ existsStub . returns ( true ) ;
38
42
findExtensions ( ) ;
39
43
expect ( findStub . calledOnce ) . to . be . true ;
40
44
const args = findStub . args [ 0 ] [ 0 ] ;
@@ -53,7 +57,28 @@ describe('Unit: Utils > find-extensions', function () {
53
57
expect ( args ) . to . deep . equal ( expected ) ;
54
58
} ) ;
55
59
60
+ it ( 'uses process.cwd() when global modules dir doesn\'t exist' , function ( ) {
61
+ existsStub . returns ( false ) ;
62
+ findExtensions ( ) ;
63
+ expect ( findStub . calledOnce ) . to . be . true ;
64
+ const args = findStub . args [ 0 ] [ 0 ] ;
65
+
66
+ const expected = {
67
+ keyword : 'ghost-cli-extension' ,
68
+ configName : 'ghost-cli' ,
69
+ scanAllDirs : true ,
70
+ dir : process . cwd ( ) ,
71
+ sort : true
72
+ } ;
73
+
74
+ const extensions = args . include . map ( ( ext ) => ext . split ( 'extensions/' ) [ 1 ] ) ;
75
+ delete args . include ;
76
+ expect ( extensions ) . to . deep . equal ( localExtensions ) ;
77
+ expect ( args ) . to . deep . equal ( expected ) ;
78
+ } ) ;
79
+
56
80
it ( 'generates proper extension names' , function ( ) {
81
+ existsStub . returns ( true ) ;
57
82
const names = findExtensions ( ) . map ( ( ext ) => ext . name ) ;
58
83
const expectedNames = [ 'test' , 'rest' , undefined ] ;
59
84
expect ( names ) . to . deep . equal ( expectedNames ) ;
0 commit comments