1+ import interopRequireDefault from 'babel-runtime/helpers/interopRequireDefault' ;
12import forEachDescriptor from '../../src/traversal/forEachDescriptor' ;
23
34let mockComponents , mockVariations ;
@@ -7,19 +8,16 @@ jest.mock('../../src/helpers/getVariationProviders', () => jest.fn(() => mockVar
78
89describe ( 'forEachDescriptor' , ( ) => {
910 beforeEach ( ( ) => {
10- mockComponents = {
11- 'path/to/component' : { actualPath : 'path/to/component.js' , Module : { } } ,
12- } ;
13- mockVariations = {
14- 'path/to/VariationProvider' : jest . fn ( ) ,
15- } ;
1611 require ( '../../src/helpers/getComponents' ) . mockClear ( ) ;
1712 require ( '../../src/helpers/getVariationProviders' ) . mockClear ( ) ;
1813 mockComponents = {
1914 'path/to/component' : { actualPath : 'path/to/component.js' , Module : { } } ,
2015 } ;
2116 mockVariations = {
22- 'path/to/VariationProvider' : jest . fn ( ) ,
17+ 'path/to/VariationProvider' : {
18+ Module : interopRequireDefault ( jest . fn ( ) ) ,
19+ actualPath : '/full/path/to/VariationProvider.jsx' ,
20+ } ,
2321 } ;
2422 } ) ;
2523
@@ -56,7 +54,13 @@ describe('forEachDescriptor', () => {
5654 expect ( getComponents ) . toHaveBeenCalledWith ( mockProjectConfig , expect . any ( String ) ) ;
5755
5856 expect ( getVariationProviders ) . toHaveBeenCalledTimes ( 1 ) ;
59- expect ( getVariationProviders ) . toHaveBeenCalledWith ( mockProjectConfig , expect . any ( String ) ) ;
57+ expect ( getVariationProviders ) . toHaveBeenCalledWith (
58+ mockProjectConfig ,
59+ expect . any ( String ) ,
60+ expect . objectContaining ( {
61+ fileMapOnly : true ,
62+ } ) ,
63+ ) ;
6064 } ) ;
6165
6266 describe ( 'traversal function' , ( ) => {
@@ -106,11 +110,17 @@ describe('forEachDescriptor', () => {
106110 it ( 'iterates variations' , ( ) => {
107111 const a = jest . fn ( ) ;
108112 const b = jest . fn ( ) ;
109- const variationPathA = ' path/to/a' ;
110- const variationPathB = ' path/to/b' ;
113+ const variationPathA = ` ${ projectRoot } / path/to/a` ;
114+ const variationPathB = ` ${ projectRoot } / path/to/b` ;
111115 mockVariations = {
112- [ variationPathA ] : a ,
113- [ variationPathB ] : b ,
116+ [ variationPathA ] : {
117+ Module : interopRequireDefault ( a ) ,
118+ actualPath : `${ variationPathA } .extA` ,
119+ } ,
120+ [ variationPathB ] : {
121+ Module : interopRequireDefault ( b ) ,
122+ actualPath : `${ variationPathB } .extB` ,
123+ } ,
114124 } ;
115125 const traverse = forEachDescriptor ( mockProjectConfig , {
116126 getExtras,
@@ -147,12 +157,30 @@ describe('forEachDescriptor', () => {
147157
148158 expect ( callback ) . toHaveBeenCalledTimes ( 2 ) ;
149159 const [ first , second ] = callback . mock . calls ;
150- expect ( first ) . toEqual ( [ descriptor , { variationPath : variationPathA } ] ) ;
151- expect ( second ) . toEqual ( [ descriptor , { variationPath : variationPathB } ] ) ;
160+ expect ( first ) . toEqual ( [ descriptor , {
161+ variationProvider : {
162+ hierarchy : 'path/to/a' ,
163+ path : variationPathA ,
164+ resolvedPath : mockVariations [ variationPathA ] . actualPath
165+ } ,
166+ variationPath : variationPathA ,
167+ } ] ) ;
168+ expect ( second ) . toEqual ( [ descriptor , {
169+ variationProvider : {
170+ hierarchy : 'path/to/b' ,
171+ path : variationPathB ,
172+ resolvedPath : mockVariations [ variationPathB ] . actualPath
173+ } ,
174+ variationPath : variationPathB ,
175+ } ] ) ;
152176 } ) ;
153177
154178 it ( 'throws when the provider is not a function' , ( ) => {
155- mockVariations = { 'path/to/a' : true } ;
179+ mockVariations = {
180+ 'path/to/a' : {
181+ Module : interopRequireDefault ( true ) ,
182+ } ,
183+ } ;
156184 const traverse = forEachDescriptor ( mockProjectConfig , {
157185 getExtras,
158186 getDescriptor,
@@ -165,7 +193,12 @@ describe('forEachDescriptor', () => {
165193
166194 it ( 'provides a default `getExtras`' , ( ) => {
167195 const a = jest . fn ( ) ;
168- mockVariations = { 'path/to/a' : a } ;
196+ mockVariations = {
197+ 'path/to/a' : {
198+ Module : interopRequireDefault ( a ) ,
199+ actualPath : 'path/to/a.extension' ,
200+ } ,
201+ } ;
169202 const traverse = forEachDescriptor ( mockProjectConfig , {
170203 getDescriptor,
171204 projectRoot,
0 commit comments