11/* eslint-disable no-useless-escape, no-unused-vars */
2- import fileLoader from '../src' ;
2+ import loader from '../src' ;
33
44const run = function run ( resourcePath , query , content = new Buffer ( '1234' ) ) {
55 let file = null ;
66
77 const context = {
88 resourcePath,
9- query : `?${ query } ` ,
9+ query : `?${ query || '' } ` ,
1010 options : {
1111 context : '/this/is/the/context' ,
1212 } ,
@@ -16,7 +16,7 @@ const run = function run(resourcePath, query, content = new Buffer('1234')) {
1616 } ,
1717 } ;
1818
19- const result = fileLoader . call ( context , content ) ;
19+ const result = loader . call ( context , content ) ;
2020
2121 return {
2222 file,
@@ -29,8 +29,8 @@ function runWithOptions(resourcePath, options, content = new Buffer('1234')) {
2929
3030 const context = {
3131 resourcePath,
32+ query : options ,
3233 options : {
33- fileLoader : options ,
3434 context : '/this/is/the/context' ,
3535 } ,
3636 emitFile ( url , content2 ) {
@@ -39,7 +39,7 @@ function runWithOptions(resourcePath, options, content = new Buffer('1234')) {
3939 } ,
4040 } ;
4141
42- const result = fileLoader . call ( context , content ) ;
42+ const result = loader . call ( context , content ) ;
4343
4444 return {
4545 file,
@@ -57,6 +57,7 @@ describe('correct-filename', () => {
5757 test ( '81dc9bdb52d04dc20036dbd8313ed055.txt' , 'file.txt' , '' ) ;
5858 test ( '81dc9bdb52d04dc20036dbd8313ed055.bin' , '' , '' ) ;
5959 } ) ;
60+
6061 it ( 'should process name correctly' , ( ) => {
6162 test ( 'file.txt' , '/file.txt' , 'name=[name].[ext]' ) ;
6263 test ( 'file.png' , '/file.png' , 'name=[name].[ext]' ) ;
@@ -71,9 +72,11 @@ describe('correct-filename', () => {
7172 test ( '_/_/dir/sub/file.txt' , '/this/is/dir/sub/file.txt' , 'name=[path][name].[ext]' ) ;
7273 test ( 'dir/sub/file.txt' , '/this/is/dir/sub/file.txt' , 'name=[path][name].[ext]&context=/this/is' ) ;
7374 } ) ;
75+
7476 it ( 'should process hash correctly' , ( ) => {
7577 test ( 'd93591bdf7860e1e4ee2fca799911215.txt' , '/file.txt' , '' , new Buffer ( '4321' ) ) ;
7678 } ) ;
79+
7780 it ( 'should process hash options correctly' , ( ) => {
7881 test ( '81dc9.txt' , '/file.txt' , 'name=[hash:5].[ext]' ) ;
7982 test ( 'd4045.txt' , '/file.txt' , 'name=[sha512:hash:5].[ext]' ) ;
@@ -90,11 +93,13 @@ describe('publicPath option', () => {
9093 'export default "http://cdn/81dc9bdb52d04dc20036dbd8313ed055.txt";' ,
9194 ) ;
9295 } ) ;
96+
9397 it ( 'should override public path when given empty string' , ( ) => {
9498 expect ( run ( '/file.txt' , 'publicPath=' ) . result ) . toEqual (
9599 'export default "81dc9bdb52d04dc20036dbd8313ed055.txt";' ,
96100 ) ;
97101 } ) ;
102+
98103 it ( 'should use webpack public path when not set' , ( ) => {
99104 expect ( run ( '/file.txt' ) . result ) . toEqual (
100105 'export default __webpack_public_path__ + "81dc9bdb52d04dc20036dbd8313ed055.txt";' ,
@@ -107,12 +112,15 @@ describe('useRelativePath option', () => {
107112 expect ( run ( '/this/is/the/context/file.txt' , 'useRelativePath=true' ) . result ) . toEqual (
108113 'export default __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";' ,
109114 ) ;
115+
110116 expect ( run ( '/this/is/file.txt' , 'useRelativePath=true' ) . result ) . toEqual (
111117 'export default __webpack_public_path__ + \"../../81dc9bdb52d04dc20036dbd8313ed055.txt\";' ,
112118 ) ;
119+
113120 expect ( run ( '/this/file.txt' , 'context=/this/is/the/&useRelativePath=true' ) . result ) . toEqual (
114121 'export default __webpack_public_path__ + \"../../81dc9bdb52d04dc20036dbd8313ed055.txt\";' ,
115122 ) ;
123+
116124 expect ( run ( '/this/file.txt' , 'context=/&useRelativePath=true' ) . result ) . toEqual (
117125 'export default __webpack_public_path__ + \"this/81dc9bdb52d04dc20036dbd8313ed055.txt\";' ,
118126 ) ;
@@ -121,20 +129,23 @@ describe('useRelativePath option', () => {
121129
122130describe ( 'outputPath function' , ( ) => {
123131 it ( 'should be supported' , ( ) => {
124- const outputFunc = value => '/path/set/by/func' ;
125132 const options = { } ;
126- options . outputPath = outputFunc ;
127- expect ( runWithOptions ( '/this/is/the/context/file.txt' , options ) . result ) . toEqual (
128- 'export default __webpack_public_path__ + \"/path/set/by/func\";' ,
129- ) ;
133+ options . outputPath = value => '/path/set/by/func' ;
134+
135+ expect ( runWithOptions ( '/this/is/the/context/file.txt' , options ) . result )
136+ . toEqual (
137+ 'export default __webpack_public_path__ + \"/path/set/by/func\";' ,
138+ ) ;
130139 } ) ;
140+
131141 it ( 'should be ignored if you set useRelativePath' , ( ) => {
132- const outputFunc = value => '/path/set/by/func' ;
133142 const options = { } ;
134- options . outputPath = outputFunc ;
143+ options . outputPath = value => '/path/set/by/func' ;
135144 options . useRelativePath = true ;
136- expect ( runWithOptions ( '/this/is/the/context/file.txt' , options ) . result ) . toEqual (
137- 'export default __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";' ,
138- ) ;
145+
146+ expect ( runWithOptions ( '/this/is/the/context/file.txt' , options ) . result )
147+ . toEqual (
148+ 'export default __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";' ,
149+ ) ;
139150 } ) ;
140151} ) ;
0 commit comments