@@ -6,48 +6,58 @@ var loader = require("../");
66function execLoader ( filename , callback ) {
77 var async = false ;
88 var deps = [ ] ;
9+ var warns = [ ] ;
910 var context = {
1011 context : path . dirname ( filename ) ,
1112 resolve : function ( context , request , callback ) {
1213 process . nextTick ( function ( ) {
13- callback ( null , path . join ( context , request ) ) ;
14+ var p = path . join ( context , request ) ;
15+ if ( fs . existsSync ( p ) )
16+ callback ( null , p ) ;
17+ else
18+ callback ( new Error ( "File not found" ) ) ;
1419 } ) ;
1520 } ,
1621 addDependency : function ( dep ) {
1722 deps . push ( dep ) ;
1823 } ,
24+ emitWarning : function ( warn ) {
25+ warns . push ( warn ) ;
26+ } ,
1927 callback : function ( err , res , map ) {
2028 async = true ;
21- callback ( err , res , map , deps ) ;
29+ callback ( err , res , map , deps , warns ) ;
2230 } ,
2331 async : function ( ) {
2432 async = true ;
2533 return this . callback ;
2634 }
2735 } ;
2836 var res = loader . call ( context , fs . readFileSync ( filename , "utf-8" ) ) ;
29- if ( ! async ) return callback ( null , res , null , deps ) ;
37+ if ( ! async ) return callback ( null , res , null , deps , warns ) ;
3038}
3139
3240describe ( "source-map-loader" , function ( ) {
3341 it ( "should leave normal files untouched" , function ( done ) {
34- execLoader ( path . join ( __dirname , "fixtures" , "normal-file.js" ) , function ( err , res , map , deps ) {
42+ execLoader ( path . join ( __dirname , "fixtures" , "normal-file.js" ) , function ( err , res , map , deps , warns ) {
3543 should . equal ( err , null ) ;
44+ warns . should . be . eql ( [ ] ) ;
3645 should . equal ( res , "without SourceMap" ) ,
3746 should . equal ( map , null ) ;
3847 deps . should . be . eql ( [ ] ) ;
3948 done ( ) ;
4049 } ) ;
4150 } ) ;
4251 it ( "should process inlined SourceMaps" , function ( done ) {
43- execLoader ( path . join ( __dirname , "fixtures" , "inline-source-map.js" ) , function ( err , res , map , deps ) {
52+ execLoader ( path . join ( __dirname , "fixtures" , "inline-source-map.js" ) , function ( err , res , map , deps , warns ) {
4453 should . equal ( err , null ) ;
54+ warns . should . be . eql ( [ ] ) ;
4555 should . equal ( res , "with SourceMap\n\n// comment" ) ,
4656 map . should . be . eql ( {
4757 "version" :3 ,
4858 "file" :"inline-source-map.js" ,
4959 "sources" :[
50- path . join ( __dirname , "fixtures" , " inline-source-map.txt")
60+ " inline-source-map.txt"
5161 ] ,
5262 "sourcesContent" :[ "with SourceMap" ] ,
5363 "mappings" :"AAAA"
@@ -57,14 +67,15 @@ describe("source-map-loader", function() {
5767 } ) ;
5868 } ) ;
5969 it ( "should process external SourceMaps" , function ( done ) {
60- execLoader ( path . join ( __dirname , "fixtures" , "external-source-map.js" ) , function ( err , res , map , deps ) {
70+ execLoader ( path . join ( __dirname , "fixtures" , "external-source-map.js" ) , function ( err , res , map , deps , warns ) {
6171 should . equal ( err , null ) ;
72+ warns . should . be . eql ( [ ] ) ;
6273 should . equal ( res , "with SourceMap\n\n// comment" ) ,
6374 map . should . be . eql ( {
6475 "version" :3 ,
6576 "file" :"external-source-map.js" ,
6677 "sources" :[
67- path . join ( __dirname , "fixtures" , " external-source-map.txt")
78+ " external-source-map.txt"
6879 ] ,
6980 "sourcesContent" :[ "with SourceMap" ] ,
7081 "mappings" :"AAAA"
@@ -76,8 +87,9 @@ describe("source-map-loader", function() {
7687 } ) ;
7788 } ) ;
7889 it ( "should process external SourceMaps (external sources)" , function ( done ) {
79- execLoader ( path . join ( __dirname , "fixtures" , "external-source-map2.js" ) , function ( err , res , map , deps ) {
90+ execLoader ( path . join ( __dirname , "fixtures" , "external-source-map2.js" ) , function ( err , res , map , deps , warns ) {
8091 should . equal ( err , null ) ;
92+ warns . should . be . eql ( [ ] ) ;
8193 should . equal ( res , "with SourceMap\n\n// comment" ) ,
8294 map . should . be . eql ( {
8395 "version" :3 ,
@@ -95,4 +107,38 @@ describe("source-map-loader", function() {
95107 done ( ) ;
96108 } ) ;
97109 } ) ;
110+ it ( "should warn on missing SourceMap" , function ( done ) {
111+ execLoader ( path . join ( __dirname , "fixtures" , "missing-source-map.js" ) , function ( err , res , map , deps , warns ) {
112+ should . equal ( err , null ) ;
113+ warns . should . be . eql ( [
114+ "Cannot find SourceMap 'missing-source-map.map': Error: File not found"
115+ ] ) ;
116+ should . equal ( res , "with SourceMap\n//#sourceMappingURL=missing-source-map.map\n// comment" ) ,
117+ should . equal ( map , null ) ;
118+ deps . should . be . eql ( [ ] ) ;
119+ done ( ) ;
120+ } ) ;
121+ } ) ;
122+ it ( "should warn on missing source file" , function ( done ) {
123+ execLoader ( path . join ( __dirname , "fixtures" , "missing-source-map2.js" ) , function ( err , res , map , deps , warns ) {
124+ should . equal ( err , null ) ;
125+ warns . should . be . eql ( [
126+ "Cannot find source file 'missing-source-map2.txt': Error: File not found"
127+ ] ) ;
128+ should . equal ( res , "with SourceMap\n\n// comment" ) ,
129+ map . should . be . eql ( {
130+ "version" :3 ,
131+ "file" :"missing-source-map2.js" ,
132+ "sources" :[
133+ "missing-source-map2.txt"
134+ ] ,
135+ "sourcesContent" :[ null ] ,
136+ "mappings" :"AAAA"
137+ } ) ;
138+ deps . should . be . eql ( [
139+ path . join ( __dirname , "fixtures" , "missing-source-map2.map" )
140+ ] ) ;
141+ done ( ) ;
142+ } ) ;
143+ } ) ;
98144} ) ;
0 commit comments