@@ -127,3 +127,124 @@ describe('when applied with `publicPath` option', () => {
127127 expect ( { assets, source } ) . toMatchSnapshot ( ) ;
128128 } ) ;
129129} ) ;
130+
131+ describe ( 'when applied with `publicPath` and `prefixPublicPathWithWebpackPublicPath` options' , ( ) => {
132+ it ( 'matches snapshot for `{String}` value' , async ( ) => {
133+ const config = {
134+ loader : {
135+ test : / ( p n g | j p g | s v g ) / ,
136+ options : {
137+ publicPath : 'public_path/' ,
138+ prefixPublicPathWithWebpackPublicPath : true ,
139+ } ,
140+ } ,
141+ } ;
142+
143+ const stats = await webpack ( 'fixture.js' , config ) ;
144+ const [ module ] = stats . toJson ( ) . modules ;
145+ const { assets, source } = module ;
146+
147+ expect ( { assets, source } ) . toMatchSnapshot ( ) ;
148+ } ) ;
149+
150+ it ( 'matches snapshot for `{String}` value without trailing slash' , async ( ) => {
151+ const config = {
152+ loader : {
153+ test : / ( p n g | j p g | s v g ) / ,
154+ options : {
155+ publicPath : 'public_path' ,
156+ prefixPublicPathWithWebpackPublicPath : true ,
157+ } ,
158+ } ,
159+ } ;
160+
161+ const stats = await webpack ( 'fixture.js' , config ) ;
162+ const [ module ] = stats . toJson ( ) . modules ;
163+ const { assets, source } = module ;
164+
165+ expect ( { assets, source } ) . toMatchSnapshot ( ) ;
166+ } ) ;
167+
168+ // notice that this case will produce invalid urls if __webpack_public_path__ is set to an absolute url
169+ it ( 'matches snapshot for `{String}` value as URL' , async ( ) => {
170+ const config = {
171+ loader : {
172+ test : / ( p n g | j p g | s v g ) / ,
173+ options : {
174+ publicPath : 'https://cdn.com/' ,
175+ prefixPublicPathWithWebpackPublicPath : true ,
176+ } ,
177+ } ,
178+ } ;
179+
180+ const stats = await webpack ( 'fixture.js' , config ) ;
181+ const [ module ] = stats . toJson ( ) . modules ;
182+ const { assets, source } = module ;
183+
184+ expect ( { assets, source } ) . toMatchSnapshot ( ) ;
185+ } ) ;
186+
187+ it ( 'matches snapshot for `{Function}` value' , async ( ) => {
188+ const config = {
189+ loader : {
190+ test : / ( p n g | j p g | s v g ) / ,
191+ options : {
192+ publicPath ( url ) {
193+ return `public_path/${ url } ` ;
194+ } ,
195+ prefixPublicPathWithWebpackPublicPath : true ,
196+ } ,
197+ } ,
198+ } ;
199+
200+ const stats = await webpack ( 'fixture.js' , config ) ;
201+ const [ module ] = stats . toJson ( ) . modules ;
202+ const { assets, source } = module ;
203+
204+ expect ( { assets, source } ) . toMatchSnapshot ( ) ;
205+ } ) ;
206+
207+ it ( 'matches snapshot for `{Function}` value and pass `resourcePath`' , async ( ) => {
208+ const config = {
209+ loader : {
210+ test : / ( p n g | j p g | s v g ) / ,
211+ options : {
212+ publicPath ( url , resourcePath ) {
213+ expect ( resourcePath ) . toMatch ( 'file.png' ) ;
214+
215+ return `public_path/${ url } ` ;
216+ } ,
217+ prefixPublicPathWithWebpackPublicPath : true ,
218+ } ,
219+ } ,
220+ } ;
221+
222+ const stats = await webpack ( 'fixture.js' , config ) ;
223+ const [ module ] = stats . toJson ( ) . modules ;
224+ const { assets, source } = module ;
225+
226+ expect ( { assets, source } ) . toMatchSnapshot ( ) ;
227+ } ) ;
228+
229+ it ( 'matches snapshot for `{Function}` value and pass `context`' , async ( ) => {
230+ const config = {
231+ loader : {
232+ test : / ( p n g | j p g | s v g ) / ,
233+ options : {
234+ publicPath ( url , resourcePath , context ) {
235+ expect ( context ) . toMatch ( 'fixtures' ) ;
236+
237+ return `public_path/${ url } ` ;
238+ } ,
239+ prefixPublicPathWithWebpackPublicPath : true ,
240+ } ,
241+ } ,
242+ } ;
243+
244+ const stats = await webpack ( 'fixture.js' , config ) ;
245+ const [ module ] = stats . toJson ( ) . modules ;
246+ const { assets, source } = module ;
247+
248+ expect ( { assets, source } ) . toMatchSnapshot ( ) ;
249+ } ) ;
250+ } ) ;
0 commit comments