@@ -92,10 +92,53 @@ describe('mode flags with config', () => {
9292 } ) ;
9393 } ) ;
9494
95- it ( 'should use mode from config over flags ' , ( ) => {
95+ it ( 'should use mode flag over config ' , ( ) => {
9696 const { stdout, stderr, exitCode } = run ( __dirname , [ '--mode' , 'production' , '-c' , 'webpack.config2.js' ] ) ;
9797 expect ( stderr ) . toBeFalsy ( ) ;
9898 expect ( exitCode ) . toEqual ( 0 ) ;
99+ expect ( stdout ) . toContain ( `mode: 'production'` ) ;
100+ } ) ;
101+
102+ it ( 'should use mode from flag over NODE_ENV' , ( ) => {
103+ const { stdout, stderr, exitCode } = run ( __dirname , [ '--mode' , 'none' , '-c' , 'webpack.config2.js' ] , false , [ ] , {
104+ NODE_ENV : 'production' ,
105+ } ) ;
106+ expect ( stderr ) . toBeFalsy ( ) ;
107+ expect ( exitCode ) . toEqual ( 0 ) ;
108+ expect ( stdout ) . toContain ( `mode: 'none'` ) ;
109+ } ) ;
110+
111+ it ( 'should use mode from config over NODE_ENV' , ( ) => {
112+ const { stdout, stderr, exitCode } = run ( __dirname , [ '-c' , 'webpack.config2.js' ] ) ;
113+ expect ( stderr ) . toBeFalsy ( ) ;
114+ expect ( exitCode ) . toEqual ( 0 ) ;
115+ expect ( stdout ) . toContain ( `mode: 'development'` ) ;
116+ } ) ;
117+
118+ it ( 'should use mode from config when multiple config are supplied' , ( ) => {
119+ const { stdout, stderr } = run ( __dirname , [ '-c' , 'webpack.config3.js' , '-c' , 'webpack.config2.js' ] ) ;
120+ expect ( stderr ) . toBeFalsy ( ) ;
121+ expect ( stdout ) . toContain ( `mode: 'development'` ) ;
122+ expect ( stdout . match ( new RegExp ( "mode: 'development'" , 'g' ) ) . length ) . toEqual ( 1 ) ;
123+ } ) ;
124+
125+ it ( 'mode flag should apply to all configs' , ( ) => {
126+ const { stdout, stderr, exitCode } = run ( __dirname , [ '--mode' , 'none' , '-c' , './webpack.config3.js' , '-c' , './webpack.config2.js' ] ) ;
127+ expect ( stderr ) . toBeFalsy ( ) ;
128+ expect ( exitCode ) . toEqual ( 0 ) ;
129+ expect ( stdout ) . toContain ( `mode: 'none'` ) ;
130+ expect ( stdout . match ( new RegExp ( "mode: 'none'" , 'g' ) ) . length ) . toEqual ( 2 ) ;
131+ } ) ;
132+
133+ it ( 'only config where mode is absent pick up from NODE_ENV' , ( ) => {
134+ const { stdout, stderr, exitCode } = run ( __dirname , [ '-c' , './webpack.config3.js' , '-c' , './webpack.config2.js' ] , false , [ ] , {
135+ NODE_ENV : 'production' ,
136+ } ) ;
137+ expect ( stderr ) . toBeFalsy ( ) ;
138+ expect ( exitCode ) . toEqual ( 0 ) ;
139+ expect ( stdout ) . toContain ( `mode: 'production'` ) ;
99140 expect ( stdout ) . toContain ( `mode: 'development'` ) ;
141+ expect ( stdout . match ( new RegExp ( "mode: 'production'" , 'g' ) ) . length ) . toEqual ( 1 ) ;
142+ expect ( stdout . match ( new RegExp ( "mode: 'development'" , 'g' ) ) . length ) . toEqual ( 1 ) ;
100143 } ) ;
101144} ) ;
0 commit comments