@@ -881,5 +881,100 @@ module.exports = require('./bar.js');
881881 expect ( Utils . getCache ) . toHaveBeenCalled ( ) ;
882882 expect ( Utils . setCache ) . not . toHaveBeenCalled ( ) ;
883883 } ) ;
884+
885+ it ( 'transform saves transformed source map to cache' , ( ) => {
886+ let file = {
887+ path : path . resolve ( cwd , 'node_modules/foo/bar/lo.js' ) ,
888+ contents : "export {default as t} from './t.js';" ,
889+ sourceMap : { "version" :3 , "file" :"lo.js" , "sourceRoot" :"" , "sources" :[ "lo.ts" ] , "names" :[ ] , "mappings" :"AAAA,OAAO,EAAC,OAAO,IAAI,CAAC,EAAC,MAAM,QAAQ,CAAA" }
890+ } ;
891+
892+ Utils . getCache = jasmine . createSpy ( 'getCache' ) . and . returnValue ( undefined ) ;
893+ Utils . setCache = jasmine . createSpy ( 'setCache' ) ;
894+
895+ let bs = new BundledSource ( bundler , file ) ;
896+ bs . _getProjectRoot = ( ) => 'src' ;
897+ bs . includedBy = {
898+ includedBy : {
899+ description : {
900+ name : 'foo' ,
901+ mainId : 'foo/index' ,
902+ loaderConfig : {
903+ name : 'foo' ,
904+ path : '../node_modules/foo' ,
905+ main : 'index'
906+ } ,
907+ browserReplacement : ( ) => undefined
908+ }
909+ }
910+ } ;
911+ bs . _getLoaderPlugins = ( ) => [ ] ;
912+ bs . _getLoaderConfig = ( ) => ( { paths : { } } ) ;
913+ bs . _getUseCache = ( ) => true ;
914+
915+ let deps = bs . transform ( ) ;
916+ let contents = "define('foo/bar/lo',[\"exports\", './t'], function (_exports, _t) { \"use strict\"; _exports.__esModule = true; _exports.t = void 0; _t = _interopRequireDefault(_t); _exports.t = _t.default; function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }});" ;
917+ let transformedSourceMap = { version :3 , file :undefined , names :[ '_t' , '_interopRequireDefault' , '_exports' , 't' , 'default' , 'e' , '__esModule' ] , sourceRoot :undefined , sources :[ 'lo.ts' ] , sourcesContent :[ undefined ] , mappings :";;;;;EAAAA,EAAA,GAAAC,sBAAA,CAAAD,EAAA;EAA2BE,QAAA,CAAAC,CAAA,GAAAH,EAAA,CAAAI,OAAA;EAAA,SAAAH,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAD,OAAA,EAAAC,CAAA;AAAA" , ignoreList :[ ] } ;
918+
919+ expect ( deps ) . toEqual ( [ 'foo/bar/t' ] ) ;
920+ expect ( bs . requiresTransform ) . toBe ( false ) ;
921+ expect ( bs . contents . replace ( / \r | \n / g, '' ) )
922+ . toBe ( contents ) ;
923+ expect ( bs . sourceMap ) . toEqual ( transformedSourceMap )
924+
925+ expect ( Utils . getCache ) . toHaveBeenCalled ( ) ;
926+ expect ( Utils . setCache ) . toHaveBeenCalled ( ) ;
927+ expect ( Utils . setCache . calls . argsFor ( 0 ) [ 1 ] . deps ) . toEqual ( [ './t' ] ) ;
928+ expect ( Utils . setCache . calls . argsFor ( 0 ) [ 1 ] . contents . replace ( / \r | \n / g, '' ) ) . toBe ( contents ) ;
929+ expect ( Utils . setCache . calls . argsFor ( 0 ) [ 1 ] . transformedSourceMap ) . toEqual ( transformedSourceMap ) ;
930+ } ) ;
931+
932+ it ( 'transform uses cache for transformed source map' , ( ) => {
933+ let file = {
934+ path : path . resolve ( cwd , 'node_modules/foo/bar/lo.js' ) ,
935+ contents : "export {default as t} from './t.js';" ,
936+ sourceMap : { "version" :3 , "file" :"lo.js" , "sourceRoot" :"" , "sources" :[ "lo.ts" ] , "names" :[ ] , "mappings" :"AAAA,OAAO,EAAC,OAAO,IAAI,CAAC,EAAC,MAAM,QAAQ,CAAA" }
937+ } ;
938+
939+ let contents = "define('foo/bar/lo',[\"exports\", './t'], function (_exports, _t) { \"use strict\"; _exports.__esModule = true; _exports.t = void 0; _t = _interopRequireDefault(_t); _exports.t = _t.default; function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }});" ;
940+ let transformedSourceMap = { version :3 , file :undefined , names :[ '_t' , '_interopRequireDefault' , '_exports' , 't' , 'default' , 'e' , '__esModule' ] , sourceRoot :undefined , sources :[ 'lo.ts' ] , sourcesContent :[ undefined ] , mappings :";;;;;EAAAA,EAAA,GAAAC,sBAAA,CAAAD,EAAA;EAA2BE,QAAA,CAAAC,CAAA,GAAAH,EAAA,CAAAI,OAAA;EAAA,SAAAH,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAD,OAAA,EAAAC,CAAA;AAAA" , ignoreList :[ ] } ;
941+
942+ Utils . getCache = jasmine . createSpy ( 'getCache' ) . and . returnValue ( {
943+ deps : [ './t' ] ,
944+ contents,
945+ transformedSourceMap
946+ } ) ;
947+ Utils . setCache = jasmine . createSpy ( 'setCache' ) ;
948+
949+ let bs = new BundledSource ( bundler , file ) ;
950+ bs . _getProjectRoot = ( ) => 'src' ;
951+ bs . includedBy = {
952+ includedBy : {
953+ description : {
954+ name : 'foo' ,
955+ mainId : 'foo/index' ,
956+ loaderConfig : {
957+ name : 'foo' ,
958+ path : '../node_modules/foo' ,
959+ main : 'index'
960+ } ,
961+ browserReplacement : ( ) => undefined
962+ }
963+ }
964+ } ;
965+ bs . _getLoaderPlugins = ( ) => [ ] ;
966+ bs . _getLoaderConfig = ( ) => ( { paths : { } } ) ;
967+ bs . _getUseCache = ( ) => true ;
968+
969+ let deps = bs . transform ( ) ;
970+ expect ( deps ) . toEqual ( [ 'foo/bar/t' ] ) ;
971+ expect ( bs . requiresTransform ) . toBe ( false ) ;
972+ expect ( bs . contents . replace ( / \r | \n / g, '' ) )
973+ . toBe ( contents ) ;
974+ expect ( bs . sourceMap ) . toEqual ( transformedSourceMap ) ;
975+
976+ expect ( Utils . getCache ) . toHaveBeenCalled ( ) ;
977+ expect ( Utils . setCache ) . not . toHaveBeenCalled ( ) ;
978+ } ) ;
884979 } ) ;
885980} ) ;
0 commit comments