@@ -1990,7 +1990,7 @@ describe('middleware', () => {
1990
1990
1991
1991
afterAll ( close ) ;
1992
1992
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 ) => {
1994
1994
request ( app )
1995
1995
. get ( '/file.phtml' )
1996
1996
. expect ( 'Content-Type' , 'application/octet-stream' )
@@ -2031,13 +2031,91 @@ describe('middleware', () => {
2031
2031
2032
2032
afterAll ( close ) ;
2033
2033
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 ) => {
2035
2035
request ( app )
2036
2036
. get ( '/file.phtml' )
2037
2037
. expect ( 'Content-Type' , 'text/html; charset=utf-8' )
2038
2038
. expect ( 200 , 'welcome' , done ) ;
2039
2039
} ) ;
2040
2040
} ) ;
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
+ } ) ;
2041
2119
} ) ;
2042
2120
2043
2121
describe ( 'watchOptions option' , ( ) => {
@@ -2640,7 +2718,7 @@ describe('middleware', () => {
2640
2718
} ) ;
2641
2719
2642
2720
describe ( 'headers option' , ( ) => {
2643
- beforeAll ( ( done ) => {
2721
+ beforeEach ( ( done ) => {
2644
2722
const compiler = getCompiler ( webpackConfig ) ;
2645
2723
2646
2724
instance = middleware ( compiler , {
@@ -2653,7 +2731,7 @@ describe('middleware', () => {
2653
2731
listen = listenShorthand ( done ) ;
2654
2732
} ) ;
2655
2733
2656
- afterAll ( close ) ;
2734
+ afterEach ( close ) ;
2657
2735
2658
2736
it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , ( done ) => {
2659
2737
request ( app )
@@ -2662,6 +2740,17 @@ describe('middleware', () => {
2662
2740
. expect ( 'X-nonsense-2' , 'no' )
2663
2741
. expect ( 200 , done ) ;
2664
2742
} ) ;
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
+ } ) ;
2665
2754
} ) ;
2666
2755
2667
2756
describe ( 'publicPath option' , ( ) => {
0 commit comments