@@ -104,6 +104,42 @@ describe('"url" option', () => {
104
104
expect ( getErrors ( stats ) ) . toMatchSnapshot ( 'errors' ) ;
105
105
} ) ;
106
106
107
+ it ( 'should resolve "file" protocol path' , async ( ) => {
108
+ // Create the file with absolute path
109
+ const fileDirectory = path . resolve ( __dirname , 'fixtures' , 'url' ) ;
110
+ const file = path . resolve ( fileDirectory , 'url-file-protocol.css' ) ;
111
+ const absolutePath = path
112
+ . resolve ( fileDirectory , 'img.png' )
113
+ . replace ( / \\ / g, '/' ) ;
114
+ const code = `
115
+ .background {
116
+ background: url(file://${ absolutePath } );
117
+ }
118
+
119
+ .background-other {
120
+ background: url(file://${ absolutePath . replace ( / e / g, '%65' ) } );
121
+ }
122
+
123
+ .background-other {
124
+ background: url('file://${ absolutePath . replace ( / e / g, '\\\ne' ) } ');
125
+ }
126
+ ` ;
127
+
128
+ fs . writeFileSync ( file , code ) ;
129
+
130
+ const compiler = getCompiler ( './url/url-file-protocol.js' ) ;
131
+ const stats = await compile ( compiler ) ;
132
+
133
+ expect (
134
+ getModuleSource ( './url/url-file-protocol.css' , stats )
135
+ ) . toMatchSnapshot ( 'module' ) ;
136
+ expect ( getExecutedCode ( 'main.bundle.js' , compiler , stats ) ) . toMatchSnapshot (
137
+ 'result'
138
+ ) ;
139
+ expect ( getWarnings ( stats ) ) . toMatchSnapshot ( 'warnings' ) ;
140
+ expect ( getErrors ( stats ) ) . toMatchSnapshot ( 'errors' ) ;
141
+ } ) ;
142
+
107
143
it ( 'should throw an error on unresolved import' , async ( ) => {
108
144
const compiler = getCompiler ( './url/url-unresolved.js' ) ;
109
145
const stats = await compile ( compiler ) ;
0 commit comments