@@ -51,28 +51,32 @@ describe('cli : domain : get-mocked-plugins', () => {
5151
5252 describe ( 'when setting up mocked plugins' , ( ) => {
5353 describe ( 'when componentsDir parameter is undefined' , ( ) => {
54- const joinStub = sinon . stub ( ) ;
54+ let getOcConfigMock ;
5555
5656 beforeEach ( ( ) => {
57- initialise ( { pathJoin : joinStub } ) ;
57+ getOcConfigMock = sinon . stub ( ) . returns ( { registries : [ ] , mocks : { plugins : { } } } ) ;
58+ initialise ( { getOcConfig : getOcConfigMock } ) ;
5859 getMockedPlugins ( logMock , undefined ) ;
5960 } ) ;
6061
6162 it ( 'should use . as default' , ( ) => {
62- expect ( joinStub . args [ 0 ] [ 0 ] ) . to . equal ( '.' ) ;
63+ expect ( getOcConfigMock . called ) . to . be . true ;
64+ expect ( getOcConfigMock . args [ 0 ] [ 0 ] ) . to . equal ( '.' ) ;
6365 } ) ;
6466 } ) ;
6567
6668 describe ( 'when componentsDir parameter is omitted' , ( ) => {
67- const joinStub = sinon . stub ( ) ;
69+ let getOcConfigMock ;
6870
6971 beforeEach ( ( ) => {
70- initialise ( { pathJoin : joinStub } ) ;
72+ getOcConfigMock = sinon . stub ( ) . returns ( { registries : [ ] , mocks : { plugins : { } } } ) ;
73+ initialise ( { getOcConfig : getOcConfigMock } ) ;
7174 getMockedPlugins ( logMock ) ;
7275 } ) ;
7376
7477 it ( 'should use . as default' , ( ) => {
75- expect ( joinStub . args [ 0 ] [ 0 ] ) . to . equal ( '.' ) ;
78+ expect ( getOcConfigMock . called ) . to . be . true ;
79+ expect ( getOcConfigMock . args [ 0 ] [ 0 ] ) . to . equal ( '.' ) ;
7680 } ) ;
7781 } ) ;
7882
@@ -90,65 +94,26 @@ describe('cli : domain : get-mocked-plugins', () => {
9094 const getOcConfigMock = sinon . stub ( ) . returns ( ocJsonComponent ) ;
9195
9296 beforeEach ( ( ) => {
93- initialise ( { fs : {
94- existsSync : sinon . stub ( ) . returns ( true ) ,
95- } , getOcConfig : getOcConfigMock } ) ;
97+ initialise ( { getOcConfig : getOcConfigMock } ) ;
9698 result = getMockedPlugins ( logMock , '/root/components/' ) ;
9799 } ) ;
98100
99- it ( 'should use components folder oc.json as default ' , ( ) => {
101+ it ( 'should return plugins from the provided components folder config ' , ( ) => {
100102 expect ( getOcConfigMock . calledOnce ) . to . be . true ;
101- expect ( getOcConfigMock . args [ 0 ] [ 0 ] ) . to . equal ( '/root/components/oc.json ' ) ;
103+ expect ( getOcConfigMock . args [ 0 ] [ 0 ] ) . to . equal ( '/root/components/' ) ;
102104 expect ( result . length ) . to . equal ( 2 ) ;
103105 } ) ;
104106 } ) ;
105107
106- describe ( 'when oc.json is in root folder' , ( ) => {
107- let result ;
108- const ocJsonComponent = {
109- registries : [ ] ,
110- development : {
111- plugins : {
112- static : { foo : 1 , bar : 2 }
113- }
114- }
115- } ;
116- const ocJsonRoot = {
117- registries : [ ] ,
118- development : {
119- plugins : {
120- static : { foo : 1 , bar : 2 , baz : 3 }
121- }
122- }
123- } ;
124-
125- const getOcConfigMock = sinon . stub ( ) ;
126- const existsMock = sinon . stub ( ) ;
127-
128- getOcConfigMock . withArgs ( '/root/components/oc.json' ) . returns ( ocJsonComponent ) ;
129- getOcConfigMock . withArgs ( '/root/oc.json' ) . returns ( ocJsonRoot ) ;
130-
131- existsMock . withArgs ( '/root/components/oc.json' ) . returns ( false ) ;
132- existsMock . withArgs ( '/root/oc.json' ) . returns ( true ) ;
133-
134- beforeEach ( ( ) => {
135- initialise ( { fs :{
136- existsSync : existsMock ,
137- } , getOcConfig : getOcConfigMock } ) ;
138- result = getMockedPlugins ( logMock , '/root/components/' ) ;
139- } ) ;
140-
141- it ( 'should use root oc.json' , ( ) => {
142- expect ( result . length ) . to . equal ( 3 ) ;
143- } ) ;
144- } ) ;
145108
146109 describe ( 'when oc.json is missing' , ( ) => {
147110 let result ;
148111 beforeEach ( ( ) => {
149- initialise ( { fs :{
150- existsSync : sinon . stub ( ) . returns ( false )
151- } } ) ;
112+ const getOcConfigMock = sinon . stub ( ) . returns ( {
113+ registries : [ ] ,
114+ development : { plugins : { } }
115+ } ) ;
116+ initialise ( { getOcConfig : getOcConfigMock } ) ;
152117 result = getMockedPlugins ( logMock , '/root/components/' ) ;
153118 } ) ;
154119
@@ -161,16 +126,13 @@ describe('cli : domain : get-mocked-plugins', () => {
161126 let result ;
162127 const ocJson = {
163128 registries : [ ] ,
164- mocks : {
129+ development : {
165130 plugins : { }
166131 }
167132 } ;
168133
169134 beforeEach ( ( ) => {
170- initialise ( { fs :{
171- existsSync : sinon . stub ( ) . returns ( true ) ,
172- readJsonSync : sinon . stub ( ) . returns ( ocJson )
173- } } ) ;
135+ initialise ( { getOcConfig : sinon . stub ( ) . returns ( ocJson ) } ) ;
174136 result = getMockedPlugins ( logMock , '/root/components/' ) ;
175137 } ) ;
176138
0 commit comments