@@ -1990,7 +1990,7 @@ describe('middleware', () => {
19901990
19911991 afterAll ( close ) ;
19921992
1993- it ( 'should return the "200" code for the "GET" request to "file.html "' , ( done ) => {
1993+ it ( 'should return the "200" code for the "GET" request to "file.phtml "' , ( done ) => {
19941994 request ( app )
19951995 . get ( '/file.phtml' )
19961996 . expect ( 'Content-Type' , 'application/octet-stream' )
@@ -2031,13 +2031,91 @@ describe('middleware', () => {
20312031
20322032 afterAll ( close ) ;
20332033
2034- it ( 'should return the "200" code for the "GET" request "file.html "' , ( done ) => {
2034+ it ( 'should return the "200" code for the "GET" request "file.phtml "' , ( done ) => {
20352035 request ( app )
20362036 . get ( '/file.phtml' )
20372037 . expect ( 'Content-Type' , 'text/html; charset=utf-8' )
20382038 . expect ( 200 , 'welcome' , done ) ;
20392039 } ) ;
20402040 } ) ;
2041+
2042+ describe ( 'should override value for "Content-Type" header for known MIME type' , ( ) => {
2043+ beforeAll ( ( done ) => {
2044+ const outputPath = path . resolve ( __dirname , './outputs/basic' ) ;
2045+ const compiler = getCompiler ( {
2046+ ...webpackConfig ,
2047+ output : {
2048+ filename : 'bundle.js' ,
2049+ path : outputPath ,
2050+ } ,
2051+ } ) ;
2052+
2053+ instance = middleware ( compiler , {
2054+ mimeTypes : {
2055+ jpg : 'application/octet-stream' ,
2056+ } ,
2057+ } ) ;
2058+
2059+ app = express ( ) ;
2060+ app . use ( instance ) ;
2061+
2062+ listen = listenShorthand ( done ) ;
2063+
2064+ instance . context . outputFileSystem . mkdirSync ( outputPath , {
2065+ recursive : true ,
2066+ } ) ;
2067+ instance . context . outputFileSystem . writeFileSync (
2068+ path . resolve ( outputPath , 'file.jpg' ) ,
2069+ 'welcome'
2070+ ) ;
2071+ } ) ;
2072+
2073+ afterAll ( close ) ;
2074+
2075+ it ( 'should return the "200" code for the "GET" request "file.jpg"' , ( done ) => {
2076+ request ( app )
2077+ . get ( '/file.jpg' )
2078+ . expect ( 'Content-Type' , / a p p l i c a t i o n \/ o c t e t - s t r e a m / )
2079+ . expect ( 200 , done ) ;
2080+ } ) ;
2081+ } ) ;
2082+
2083+ describe ( 'should set "Content-Type" header for route not from outputFileSystem' , ( ) => {
2084+ beforeAll ( ( done ) => {
2085+ const outputPath = path . resolve ( __dirname , './outputs/basic' ) ;
2086+ const compiler = getCompiler ( {
2087+ ...webpackConfig ,
2088+ output : {
2089+ filename : 'bundle.js' ,
2090+ path : outputPath ,
2091+ } ,
2092+ } ) ;
2093+
2094+ instance = middleware ( compiler , {
2095+ mimeTypes : {
2096+ jpg : 'application/octet-stream' ,
2097+ } ,
2098+ } ) ;
2099+
2100+ app = express ( ) ;
2101+ app . use ( instance ) ;
2102+
2103+ app . get ( '/file.jpg' , ( req , res ) => {
2104+ res . send ( 'welcome' ) ;
2105+ } ) ;
2106+
2107+ listen = listenShorthand ( done ) ;
2108+ } ) ;
2109+
2110+ afterAll ( close ) ;
2111+
2112+ it ( 'should return the "200" code for the "GET" request "file.jpg"' , ( done ) => {
2113+ request ( app )
2114+ . get ( '/file.jpg' )
2115+ . expect ( 'Content-Type' , / a p p l i c a t i o n \/ o c t e t - s t r e a m / )
2116+ . expect ( 200 , done ) ;
2117+ } ) ;
2118+ } ) ;
20412119 } ) ;
20422120
20432121 describe ( 'watchOptions option' , ( ) => {
@@ -2640,7 +2718,7 @@ describe('middleware', () => {
26402718 } ) ;
26412719
26422720 describe ( 'headers option' , ( ) => {
2643- beforeAll ( ( done ) => {
2721+ beforeEach ( ( done ) => {
26442722 const compiler = getCompiler ( webpackConfig ) ;
26452723
26462724 instance = middleware ( compiler , {
@@ -2653,7 +2731,7 @@ describe('middleware', () => {
26532731 listen = listenShorthand ( done ) ;
26542732 } ) ;
26552733
2656- afterAll ( close ) ;
2734+ afterEach ( close ) ;
26572735
26582736 it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , ( done ) => {
26592737 request ( app )
@@ -2662,6 +2740,17 @@ describe('middleware', () => {
26622740 . expect ( 'X-nonsense-2' , 'no' )
26632741 . expect ( 200 , done ) ;
26642742 } ) ;
2743+
2744+ it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem and return headers' , ( done ) => {
2745+ app . get ( '/file.jpg' , ( req , res ) => {
2746+ res . send ( 'welcome' ) ;
2747+ } ) ;
2748+ request ( app )
2749+ . get ( '/file.jpg' )
2750+ . expect ( 'X-nonsense-1' , 'yes' )
2751+ . expect ( 'X-nonsense-2' , 'no' )
2752+ . expect ( 200 , done ) ;
2753+ } ) ;
26652754 } ) ;
26662755
26672756 describe ( 'publicPath option' , ( ) => {
0 commit comments