@@ -5,9 +5,12 @@ var File = require('vinyl');
55var path = require ( 'path' ) ;
66var expect = require ( 'expect' ) ;
77var convert = require ( 'convert-source-map' ) ;
8+ var miss = require ( 'mississippi' ) ;
89
910var sourcemaps = require ( '..' ) ;
1011
12+ var from = miss . from ;
13+
1114var sourceContent = fs . readFileSync ( path . join ( __dirname , 'assets/helloworld.js' ) ) ;
1215
1316function makeFile ( ) {
@@ -64,14 +67,54 @@ describe('add', function() {
6467 } ) ;
6568 } ) ;
6669
67- it ( 'does not error if file argument is a vinyl object' , function ( done ) {
70+ it ( 'does not error if file argument is a Vinyl object with Buffer contents ' , function ( done ) {
6871 var file = makeFile ( ) ;
6972 sourcemaps . add ( file , function ( err ) {
7073 expect ( err ) . toNotExist ( ) ;
7174 done ( ) ;
7275 } ) ;
7376 } ) ;
7477
78+ it ( 'errors if file argument is a Vinyl object with Stream contents' , function ( done ) {
79+ var file = makeFile ( ) ;
80+ file . contents = from ( [ ] ) ;
81+ sourcemaps . add ( file , function ( err ) {
82+ expect ( err instanceof Error && err . message === 'vinyl-sourcemap-add: Streaming not supported' ) . toExist ( ) ;
83+ done ( ) ;
84+ } ) ;
85+ } ) ;
86+
87+ it ( 'calls back with the untouched file if file already has a sourcemap' , function ( done ) {
88+ var sourceMap = {
89+ version : 3 ,
90+ names : [ ] ,
91+ mappings : '' ,
92+ sources : [ 'test.js' ] ,
93+ sourcesContent : [ 'testContent' ] ,
94+ } ;
95+
96+ var file = makeFile ( ) ;
97+ file . sourceMap = sourceMap ;
98+ sourcemaps . add ( file , function ( err , data ) {
99+ expect ( data ) . toExist ( ) ;
100+ expect ( File . isVinyl ( data ) ) . toEqual ( true ) ;
101+ expect ( data . sourceMap ) . toBe ( sourceMap ) ;
102+ expect ( data ) . toBe ( file ) ;
103+ done ( err ) ;
104+ } ) ;
105+ } ) ;
106+
107+ it ( 'calls back with the untouched file if file contents are null' , function ( done ) {
108+ var file = makeFile ( ) ;
109+ file . contents = null ;
110+ sourcemaps . add ( file , function ( err , outFile ) {
111+ expect ( err ) . toNotExist ( ) ;
112+ expect ( file ) . toExist ( ) ;
113+ expect ( outFile ) . toEqual ( file ) ;
114+ done ( err ) ;
115+ } ) ;
116+ } ) ;
117+
75118 it ( 'adds an empty sourceMap if none are found' , function ( done ) {
76119 sourcemaps . add ( makeFile ( ) , function ( err , data ) {
77120 expect ( data . sourceMap ) . toExist ( ) ;
@@ -301,24 +344,4 @@ describe('add', function() {
301344 done ( err ) ;
302345 } ) ;
303346 } ) ;
304-
305- it ( 'passes file through when it already has a sourcemap' , function ( done ) {
306- var sourceMap = {
307- version : 3 ,
308- names : [ ] ,
309- mappings : '' ,
310- sources : [ 'test.js' ] ,
311- sourcesContent : [ 'testContent' ] ,
312- } ;
313-
314- var file = makeFile ( ) ;
315- file . sourceMap = sourceMap ;
316- sourcemaps . add ( file , function ( err , data ) {
317- expect ( data ) . toExist ( ) ;
318- expect ( File . isVinyl ( data ) ) . toEqual ( true ) ;
319- expect ( data . sourceMap ) . toBe ( sourceMap ) ;
320- expect ( data ) . toBe ( file ) ;
321- done ( err ) ;
322- } ) ;
323- } ) ;
324347} ) ;
0 commit comments