11'use strict' ;
22var gulp = require ( 'gulp' ) ;
3+ var $ = require ( 'gulp-load-plugins' ) ( ) ;
34var test = require ( 'tape' ) ;
4- var $ = require ( '..' ) ;
5+ var sourcemaps = require ( '..' ) ;
56var PLUGIN_NAME = require ( '../src/utils' ) . PLUGIN_NAME ;
67var debug = require ( 'debug-fabulous' ) ( ) ( PLUGIN_NAME + ':test:integration' ) ;
78var join = require ( 'path' ) . join ;
89var fs = require ( 'fs' ) ;
910var sourceContent = fs . readFileSync ( join ( __dirname , 'assets/helloworld.js' ) ) . toString ( ) ;
1011
12+
13+ function moveHtml ( dest , t ) {
14+ return gulp . src ( join ( __dirname , './assets/*.html' ) )
15+ . pipe ( gulp . dest ( 'tmp/' + dest ) )
16+ . on ( 'finish' , t . end ) ;
17+ }
18+
1119debug ( 'running' ) ;
1220
1321test ( 'creates inline mapping' , function ( t ) {
1422
1523 gulp . src ( join ( __dirname , './assets/helloworld.js' ) )
16- . pipe ( $ . init ( ) )
17- . pipe ( $ . write ( ) )
24+ . pipe ( sourcemaps . init ( ) )
25+ . pipe ( sourcemaps . write ( ) )
1826 // .pipe(gulp.dest('tmp'))
1927 . on ( 'data' , function ( data ) {
2028 t . ok ( data . sourceMap , 'should add a source map object' ) ;
@@ -36,8 +44,8 @@ test('creates inline mapping', function(t) {
3644
3745test ( 'creates re-uses existing mapping' , function ( t ) {
3846 gulp . src ( join ( __dirname , './assets/helloworld.map.js' ) )
39- . pipe ( $ . init ( { loadMaps :true } ) )
40- . pipe ( $ . write ( ) )
47+ . pipe ( sourcemaps . init ( { loadMaps :true } ) )
48+ . pipe ( sourcemaps . write ( ) )
4149 // .pipe(gulp.dest('tmp'))
4250 . on ( 'data' , function ( data ) {
4351 t . ok ( data . sourceMap , 'should add a source map object' ) ;
@@ -57,3 +65,119 @@ test('creates re-uses existing mapping', function(t) {
5765 t . end ( ) ;
5866 } ) ;
5967} ) ;
68+
69+
70+ test ( 'combined mapped: concat files with final combined sourcemap file' , function ( t ) {
71+
72+ gulp . src ( [
73+ join ( __dirname , './assets/*.js' ) ,
74+ '!' + join ( __dirname , './assets/test*.js' ) ,
75+ '!' + join ( __dirname , './assets/*map.js' ) ]
76+ )
77+ . pipe ( sourcemaps . init ( ) )
78+ . pipe ( $ . if ( "*.js" , $ . concat ( "index.js" ) ) )
79+ . pipe ( sourcemaps . write ( '.' , { sourceRoot :'../../test/assets' } ) )
80+ . pipe ( gulp . dest ( 'tmp/combined_map' ) )
81+ . on ( 'error' , function ( ) {
82+ t . fail ( 'emitted error' ) ;
83+ t . end ( ) ;
84+ } )
85+ . on ( 'data' , function ( data ) {
86+ if ( / i n d e x \. j s $ / . test ( data . path ) ) {
87+ t . ok ( / \/ \/ # s o u r c e M a p p i n g U R L = i n d e x .j s .m a p / . test ( data . contents . toString ( ) ) ,
88+ 'concatenated file is mapped' ) ;
89+ t . equal ( data . contents . toString ( ) . match ( / \/ \/ # s o u r c e M a p p i n g U R L / g) . length , 1 ,
90+ 'concatenated file is mapped once' ) ;
91+ }
92+ } )
93+ . on ( 'finish' , function ( ) {
94+ moveHtml ( 'combined_map' , t ) ;
95+ } ) ;
96+ } ) ;
97+
98+ test ( 'combined: inline concatenated file' , function ( t ) {
99+
100+ gulp . src ( [
101+ join ( __dirname , './assets/*.js' ) ,
102+ '!' + join ( __dirname , './assets/test*.js' ) ,
103+ '!' + join ( __dirname , './assets/*map.js' ) ]
104+ )
105+ . pipe ( sourcemaps . init ( ) )
106+ . pipe ( $ . if ( "*.js" , $ . concat ( "index.js" ) ) )
107+ . pipe ( sourcemaps . write ( { sourceRoot :'../../test/assets' } ) )
108+ . pipe ( gulp . dest ( 'tmp/combined_inline' ) )
109+ . on ( 'error' , function ( ) {
110+ t . fail ( 'emitted error' ) ;
111+ t . end ( ) ;
112+ } )
113+ . on ( 'data' , function ( data ) {
114+ if ( / i n d e x \. j s $ / . test ( data . path ) ) {
115+ t . ok ( / \/ \/ # s o u r c e M a p p i n g U R L = d a t a : a p p l i c a t i o n .* / . test ( data . contents . toString ( ) ) ,
116+ 'concatenated file is mapped' ) ;
117+ t . equal ( data . contents . toString ( ) . match ( / \/ \/ # s o u r c e M a p p i n g U R L / g) . length , 1 ,
118+ 'concatenated file is mapped once' ) ;
119+ }
120+ } )
121+ . on ( 'finish' , function ( ) {
122+ moveHtml ( 'combined_inline' , t ) ;
123+ } ) ;
124+ } ) ;
125+
126+ test ( 'combined: mapped preExisting' , function ( t ) {
127+
128+ gulp . src ( [
129+ //picking a file with no existing sourcemap, if we use helloworld2 it will attempt to use helloworld2.js.map
130+ join ( __dirname , './assets/helloworld7.js' ) , //NO PRE-MAP at all
131+ join ( __dirname , './assets/helloworld.map.js' ) //INLINE PRE-MAp
132+ ]
133+ )
134+ . pipe ( sourcemaps . init ( { loadMaps :true } ) )
135+ . pipe ( $ . if ( "*.js" , $ . concat ( "index.js" ) ) )
136+ . pipe ( sourcemaps . write ( '.' , { sourceRoot :'../../test/assets' } ) )
137+ . pipe ( gulp . dest ( 'tmp/combined_map_preExisting' ) )
138+ . on ( 'error' , function ( ) {
139+ t . fail ( 'emitted error' ) ;
140+ t . end ( ) ;
141+ } )
142+ . on ( 'data' , function ( data ) {
143+ if ( / i n d e x \. j s $ / . test ( data . path ) ) {
144+ t . ok ( / \/ \/ # s o u r c e M a p p i n g U R L = i n d e x .j s .m a p / . test ( data . contents . toString ( ) ) ,
145+ 'concatenated file is mapped' ) ;
146+ t . equal ( data . contents . toString ( ) . match ( / \/ \/ # s o u r c e M a p p i n g U R L / g) . length , 1 ,
147+ 'concatenated file is mapped once' ) ;
148+ }
149+ } )
150+ . on ( 'finish' , function ( ) {
151+ moveHtml ( 'combined_map_preExisting' , t ) ;
152+ } ) ;
153+ } ) ;
154+
155+
156+ test ( 'combined: inlined preExisting' , function ( t ) {
157+
158+ gulp . src ( [
159+ //picking a file with no existing sourcemap, if we use helloworld2 it will attempt to use helloworld2.js.map
160+ join ( __dirname , './assets/helloworld7.js' ) , //NO PRE-MAP at all
161+ join ( __dirname , './assets/helloworld.map.js' ) //INLINE PRE-MAp
162+ ]
163+ )
164+ . pipe ( sourcemaps . init ( { loadMaps :true } ) )
165+ . pipe ( $ . if ( "*.js" , $ . concat ( "index.js" ) ) )
166+ . pipe ( sourcemaps . write ( { sourceRoot :'../../test/assets' } ) )
167+ . pipe ( gulp . dest ( 'tmp/combined_inline_preExisting' ) )
168+ . on ( 'error' , function ( ) {
169+ t . fail ( 'emitted error' ) ;
170+ t . end ( ) ;
171+ } )
172+ . on ( 'data' , function ( data ) {
173+ if ( / i n d e x \. j s $ / . test ( data . path ) ) {
174+ t . ok ( / \/ \/ # s o u r c e M a p p i n g U R L = d a t a : a p p l i c a t i o n .* / . test ( data . contents . toString ( ) ) ,
175+ 'concatenated file is mapped' ) ;
176+ t . equal ( data . contents . toString ( ) . match ( / \/ \/ # s o u r c e M a p p i n g U R L / g) . length , 1 ,
177+ 'concatenated file is mapped once' ) ;
178+ }
179+ } )
180+ . on ( 'finish' , function ( ) {
181+ moveHtml ( 'combined_inline_preExisting' , t ) ;
182+ } ) ;
183+ } ) ;
0 commit comments