@@ -6,48 +6,58 @@ var loader = require("../");
6
6
function execLoader ( filename , callback ) {
7
7
var async = false ;
8
8
var deps = [ ] ;
9
+ var warns = [ ] ;
9
10
var context = {
10
11
context : path . dirname ( filename ) ,
11
12
resolve : function ( context , request , callback ) {
12
13
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" ) ) ;
14
19
} ) ;
15
20
} ,
16
21
addDependency : function ( dep ) {
17
22
deps . push ( dep ) ;
18
23
} ,
24
+ emitWarning : function ( warn ) {
25
+ warns . push ( warn ) ;
26
+ } ,
19
27
callback : function ( err , res , map ) {
20
28
async = true ;
21
- callback ( err , res , map , deps ) ;
29
+ callback ( err , res , map , deps , warns ) ;
22
30
} ,
23
31
async : function ( ) {
24
32
async = true ;
25
33
return this . callback ;
26
34
}
27
35
} ;
28
36
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 ) ;
30
38
}
31
39
32
40
describe ( "source-map-loader" , function ( ) {
33
41
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 ) {
35
43
should . equal ( err , null ) ;
44
+ warns . should . be . eql ( [ ] ) ;
36
45
should . equal ( res , "without SourceMap" ) ,
37
46
should . equal ( map , null ) ;
38
47
deps . should . be . eql ( [ ] ) ;
39
48
done ( ) ;
40
49
} ) ;
41
50
} ) ;
42
51
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 ) {
44
53
should . equal ( err , null ) ;
54
+ warns . should . be . eql ( [ ] ) ;
45
55
should . equal ( res , "with SourceMap\n\n// comment" ) ,
46
56
map . should . be . eql ( {
47
57
"version" :3 ,
48
58
"file" :"inline-source-map.js" ,
49
59
"sources" :[
50
- path . join ( __dirname , "fixtures" , " inline-source-map.txt")
60
+ " inline-source-map.txt"
51
61
] ,
52
62
"sourcesContent" :[ "with SourceMap" ] ,
53
63
"mappings" :"AAAA"
@@ -57,14 +67,15 @@ describe("source-map-loader", function() {
57
67
} ) ;
58
68
} ) ;
59
69
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 ) {
61
71
should . equal ( err , null ) ;
72
+ warns . should . be . eql ( [ ] ) ;
62
73
should . equal ( res , "with SourceMap\n\n// comment" ) ,
63
74
map . should . be . eql ( {
64
75
"version" :3 ,
65
76
"file" :"external-source-map.js" ,
66
77
"sources" :[
67
- path . join ( __dirname , "fixtures" , " external-source-map.txt")
78
+ " external-source-map.txt"
68
79
] ,
69
80
"sourcesContent" :[ "with SourceMap" ] ,
70
81
"mappings" :"AAAA"
@@ -76,8 +87,9 @@ describe("source-map-loader", function() {
76
87
} ) ;
77
88
} ) ;
78
89
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 ) {
80
91
should . equal ( err , null ) ;
92
+ warns . should . be . eql ( [ ] ) ;
81
93
should . equal ( res , "with SourceMap\n\n// comment" ) ,
82
94
map . should . be . eql ( {
83
95
"version" :3 ,
@@ -95,4 +107,38 @@ describe("source-map-loader", function() {
95
107
done ( ) ;
96
108
} ) ;
97
109
} ) ;
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
+ } ) ;
98
144
} ) ;
0 commit comments