@@ -19,6 +19,16 @@ chai.use(require('sinon-chai'));
1919
2020const expect = chai . expect ;
2121
22+ class ChunkMock {
23+ constructor ( modules ) {
24+ this . _modules = modules ;
25+ }
26+
27+ forEachModule ( fn ) {
28+ _ . forEach ( this . _modules , fn ) ;
29+ }
30+ }
31+
2232describe ( 'packExternalModules' , ( ) => {
2333 let sandbox ;
2434 let baseModule ;
@@ -90,34 +100,32 @@ describe('packExternalModules', () => {
90100 {
91101 compilation : {
92102 chunks : [
93- {
94- modules : [
95- {
96- identifier : _ . constant ( '"crypto"' )
97- } ,
98- {
99- identifier : _ . constant ( '"uuid/v4"' )
100- } ,
101- {
102- identifier : _ . constant ( 'external "eslint"' )
103- } ,
104- {
105- identifier : _ . constant ( '"mockery"' )
106- } ,
107- {
108- identifier : _ . constant ( '"@scoped/vendor/module1"' )
109- } ,
110- {
111- identifier : _ . constant ( 'external "@scoped/vendor/module2"' )
112- } ,
113- {
114- identifier : _ . constant ( 'external "uuid/v4"' )
115- } ,
116- {
117- identifier : _ . constant ( 'external "bluebird"' )
118- } ,
119- ]
120- }
103+ new ChunkMock ( [
104+ {
105+ identifier : _ . constant ( '"crypto"' )
106+ } ,
107+ {
108+ identifier : _ . constant ( '"uuid/v4"' )
109+ } ,
110+ {
111+ identifier : _ . constant ( 'external "eslint"' )
112+ } ,
113+ {
114+ identifier : _ . constant ( '"mockery"' )
115+ } ,
116+ {
117+ identifier : _ . constant ( '"@scoped/vendor/module1"' )
118+ } ,
119+ {
120+ identifier : _ . constant ( 'external "@scoped/vendor/module2"' )
121+ } ,
122+ {
123+ identifier : _ . constant ( 'external "uuid/v4"' )
124+ } ,
125+ {
126+ identifier : _ . constant ( 'external "bluebird"' )
127+ } ,
128+ ] )
121129 ] ,
122130 compiler : {
123131 outputPath : '/my/Service/Path/.webpack/service'
@@ -131,22 +139,20 @@ describe('packExternalModules', () => {
131139 {
132140 compilation : {
133141 chunks : [
134- {
135- modules : [
136- {
137- identifier : _ . constant ( '"crypto"' )
138- } ,
139- {
140- identifier : _ . constant ( '"uuid/v4"' )
141- } ,
142- {
143- identifier : _ . constant ( '"mockery"' )
144- } ,
145- {
146- identifier : _ . constant ( '"@scoped/vendor/module1"' )
147- } ,
148- ]
149- }
142+ new ChunkMock ( [
143+ {
144+ identifier : _ . constant ( '"crypto"' )
145+ } ,
146+ {
147+ identifier : _ . constant ( '"uuid/v4"' )
148+ } ,
149+ {
150+ identifier : _ . constant ( '"mockery"' )
151+ } ,
152+ {
153+ identifier : _ . constant ( '"@scoped/vendor/module1"' )
154+ } ,
155+ ] )
150156 ] ,
151157 compiler : {
152158 outputPath : '/my/Service/Path/.webpack/service'
@@ -160,37 +166,35 @@ describe('packExternalModules', () => {
160166 {
161167 compilation : {
162168 chunks : [
163- {
164- modules : [
165- {
166- identifier : _ . constant ( '"crypto"' )
167- } ,
168- {
169- identifier : _ . constant ( '"uuid/v4"' )
170- } ,
171- {
172- identifier : _ . constant ( 'external "eslint"' )
173- } ,
174- {
175- identifier : _ . constant ( '"mockery"' )
176- } ,
177- {
178- identifier : _ . constant ( '"@scoped/vendor/module1"' )
179- } ,
180- {
181- identifier : _ . constant ( 'external "@scoped/vendor/module2"' )
182- } ,
183- {
184- identifier : _ . constant ( 'external "uuid/v4"' )
185- } ,
186- {
187- identifier : _ . constant ( 'external "localmodule"' )
188- } ,
189- {
190- identifier : _ . constant ( 'external "bluebird"' )
191- } ,
192- ]
193- }
169+ new ChunkMock ( [
170+ {
171+ identifier : _ . constant ( '"crypto"' )
172+ } ,
173+ {
174+ identifier : _ . constant ( '"uuid/v4"' )
175+ } ,
176+ {
177+ identifier : _ . constant ( 'external "eslint"' )
178+ } ,
179+ {
180+ identifier : _ . constant ( '"mockery"' )
181+ } ,
182+ {
183+ identifier : _ . constant ( '"@scoped/vendor/module1"' )
184+ } ,
185+ {
186+ identifier : _ . constant ( 'external "@scoped/vendor/module2"' )
187+ } ,
188+ {
189+ identifier : _ . constant ( 'external "uuid/v4"' )
190+ } ,
191+ {
192+ identifier : _ . constant ( 'external "localmodule"' )
193+ } ,
194+ {
195+ identifier : _ . constant ( 'external "bluebird"' )
196+ } ,
197+ ] )
194198 ] ,
195199 compiler : {
196200 outputPath : '/my/Service/Path/.webpack/service'
@@ -332,7 +336,7 @@ describe('packExternalModules', () => {
332336
333337 sandbox . stub ( process , 'cwd' ) . returns ( path . join ( '/my/Service/Path' ) ) ;
334338 mockery . registerMock ( path . join ( process . cwd ( ) , 'locals' , 'package.json' ) , packageLocalRefMock ) ;
335-
339+
336340 return expect ( module . packExternalModules ( ) ) . to . be . fulfilled
337341 . then ( ( ) => BbPromise . all ( [
338342 // The module package JSON and the composite one should have been stored
@@ -859,7 +863,39 @@ describe('packExternalModules', () => {
859863 } ;
860864
861865 const dependencyGraph = require ( './data/npm-ls-peerdeps.json' ) ;
862- const peerDepStats = require ( './data/stats-peerdeps.js' ) ;
866+ const peerDepStats = {
867+ stats : [
868+ {
869+ compilation : {
870+ chunks : [
871+ new ChunkMock ( [
872+ {
873+ identifier : _ . constant ( '"crypto"' )
874+ } ,
875+ {
876+ identifier : _ . constant ( '"uuid/v4"' )
877+ } ,
878+ {
879+ identifier : _ . constant ( '"mockery"' )
880+ } ,
881+ {
882+ identifier : _ . constant ( '"@scoped/vendor/module1"' )
883+ } ,
884+ {
885+ identifier : _ . constant ( 'external "bluebird"' )
886+ } ,
887+ {
888+ identifier : _ . constant ( 'external "request-promise"' )
889+ }
890+ ] )
891+ ] ,
892+ compiler : {
893+ outputPath : '/my/Service/Path/.webpack/service'
894+ }
895+ }
896+ }
897+ ]
898+ } ;
863899
864900 module . webpackOutputPath = 'outputPath' ;
865901 fsExtraMock . pathExists . yields ( null , false ) ;
0 commit comments