@@ -9,8 +9,9 @@ function mockTrace(unit) {
99 const moduleId = unit . moduleId ;
1010 const shim = unit . shim ;
1111
12- if ( unit . moduleId === 'ext:css' ) {
12+ if ( unit . moduleId === 'ext:css' || unit . path . endsWith ( '.css' ) ) {
1313 // don't mock ext:css trace
14+ // don't mock css file
1415 return trace ( unit ) ;
1516 }
1617
@@ -758,18 +759,18 @@ test('Bundler traces files, split bundles, continuously update bundles in watch
758759 . then ( t . end ) ;
759760} ) ;
760761
761- test ( 'Bundler supports inject css' , t => {
762+ test ( 'Bundler supports inject css by default ' , t => {
762763 const fakeFs = {
763764 'node_modules/dumber-module-loader/dist/index.js' : 'dumber-module-loader' ,
764765 'node_modules/dumber/package.json' : JSON . stringify ( { name : 'dumber' , main : './dist/index' } ) ,
765766 'node_modules/dumber/dist/inject-css.js' : '' ,
766767 } ;
767768 const bundler = createBundler ( fakeFs , {
768- injectCss : true
769769 } ) ;
770770
771771 Promise . resolve ( )
772- . then ( ( ) => bundler . capture ( { path : 'src/app.js' , contents : '' , moduleId : 'app' } ) )
772+ . then ( ( ) => bundler . capture ( { path : 'src/app.js' , contents : 'c.css' , moduleId : 'app' } ) )
773+ . then ( ( ) => bundler . capture ( { path : 'src/c.css' , contents : 'lorem' , moduleId : 'c.css' } ) )
773774 . then ( ( ) => bundler . resolve ( ) )
774775 . then ( ( ) => bundler . bundle ( ) )
775776 . then (
@@ -779,7 +780,8 @@ test('Bundler supports inject css', t => {
779780 files : [
780781 { contents : 'dumber-module-loader;' } ,
781782 { contents : 'define.switchToUserSpace();' } ,
782- { path : 'src/app.js' , contents : "define('app',[],1);" , sourceMap : undefined } ,
783+ { path : 'src/app.js' , contents : "define('app',[\"c.css\"],1);" , sourceMap : undefined } ,
784+ { path : 'src/c.css' , contents : "define('text!c.css',function(){return \"lorem\";});" , sourceMap : undefined } ,
783785 { path : '__stub__/ext-css.js' , contents : "define('ext:css',['dumber/dist/inject-css'],function(m){return m;});" , sourceMap : undefined } ,
784786 { contents : 'define.switchToPackageSpace();' } ,
785787 { path : 'node_modules/dumber/dist/inject-css.js' , contents : "define('dumber/dist/inject-css',[],1);" , sourceMap : undefined } ,
@@ -798,6 +800,44 @@ test('Bundler supports inject css', t => {
798800 . then ( t . end ) ;
799801} ) ;
800802
803+ test ( 'Bundler can optionally turn off inject css' , t => {
804+ const fakeFs = {
805+ 'node_modules/dumber-module-loader/dist/index.js' : 'dumber-module-loader' ,
806+ 'node_modules/dumber/package.json' : JSON . stringify ( { name : 'dumber' , main : './dist/index' } ) ,
807+ 'node_modules/dumber/dist/inject-css.js' : '' ,
808+ } ;
809+ const bundler = createBundler ( fakeFs , {
810+ injectCss : false
811+ } ) ;
812+
813+ Promise . resolve ( )
814+ . then ( ( ) => bundler . capture ( { path : 'src/app.js' , contents : 'c.css' , moduleId : 'app' } ) )
815+ . then ( ( ) => bundler . capture ( { path : 'src/c.css' , contents : 'lorem' , moduleId : 'c.css' } ) )
816+ . then ( ( ) => bundler . resolve ( ) )
817+ . then ( ( ) => bundler . bundle ( ) )
818+ . then (
819+ bundleMap => {
820+ t . deepEqual ( bundleMap , {
821+ 'entry-bundle' : {
822+ files : [
823+ { contents : 'dumber-module-loader;' } ,
824+ { contents : 'define.switchToUserSpace();' } ,
825+ { path : 'src/app.js' , contents : "define('app',[\"c.css\"],1);" , sourceMap : undefined } ,
826+ { path : 'src/c.css' , contents : "define('text!c.css',function(){return \"lorem\";});" , sourceMap : undefined }
827+ ] ,
828+ config : {
829+ baseUrl : '/dist' ,
830+ bundles : { } ,
831+ paths : { }
832+ }
833+ }
834+ } )
835+ } ,
836+ err => t . fail ( err . stack )
837+ )
838+ . then ( t . end ) ;
839+ } ) ;
840+
801841test ( 'Bundler traces files with paths mapping' , t => {
802842 const fakeFs = {
803843 'node_modules/dumber-module-loader/dist/index.js' : 'dumber-module-loader' ,
0 commit comments