Skip to content

Commit aa33b90

Browse files
committed
Merge branch '1.X'
2 parents e207533 + 43b20fb commit aa33b90

File tree

5 files changed

+159
-6
lines changed

5 files changed

+159
-6
lines changed

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"test": "jshint *.js test/*.js && faucet test/*.js",
1010
"tap": "tape test/*.js",
1111
"cover": "istanbul cover --dir reports/coverage tape \"test/*.js\"",
12-
"coveralls": "istanbul cover tape \"test/*.js\" --report lcovonly && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
12+
"coveralls": "istanbul cover tape \"test/*.js\" --report lcovonly && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
13+
"serve": "http-server",
14+
"test:int":"rm -rf ./tmp && tape ./test/integration.js"
1315
},
1416
"keywords": [
1517
"gulpplugin",
@@ -35,7 +37,11 @@
3537
"coveralls": "2.X",
3638
"faucet": "0.0.X",
3739
"gulp": "3.X",
40+
"gulp-concat": "2.X",
41+
"gulp-if": "2.0.2",
42+
"gulp-load-plugins": "1.X",
3843
"hook-std": "0.2.X",
44+
"http-server": "0.9.0",
3945
"istanbul": "0.X",
4046
"jshint": "2.X",
4147
"object-assign": "^4.1.0",

test/assets/helloworld2.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
function helloWorld2() {
4+
console.log('Hello world 2!');
5+
}

test/assets/helloworld7.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
function helloWorld2() {
4+
console.log('Hello world 7!');
5+
}

test/assets/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Open Browser</title>
5+
<script type="text/javascript" src="./index.js"></script>
6+
<script type="text/javascript">
7+
helloWorld();
8+
helloWorld2();
9+
</script>
10+
</head>
11+
<body>
12+
</body>
13+
</html>

test/integration.js

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
'use strict';
22
var gulp = require('gulp');
3+
var $ = require('gulp-load-plugins')();
34
var test = require('tape');
4-
var $ = require('..');
5+
var sourcemaps = require('..');
56
var PLUGIN_NAME = require('../src/utils').PLUGIN_NAME;
67
var debug = require('debug-fabulous')()(PLUGIN_NAME + ':test:integration');
78
var join = require('path').join;
89
var fs = require('fs');
910
var 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+
1119
debug('running');
1220

1321
test('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

3745
test('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(/index\.js$/.test(data.path)){
87+
t.ok(/\/\/# sourceMappingURL=index.js.map/.test(data.contents.toString()),
88+
'concatenated file is mapped');
89+
t.equal(data.contents.toString().match(/\/\/# sourceMappingURL/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(/index\.js$/.test(data.path)){
115+
t.ok(/\/\/# sourceMappingURL=data:application.*/.test(data.contents.toString()),
116+
'concatenated file is mapped');
117+
t.equal(data.contents.toString().match(/\/\/# sourceMappingURL/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(/index\.js$/.test(data.path)){
144+
t.ok(/\/\/# sourceMappingURL=index.js.map/.test(data.contents.toString()),
145+
'concatenated file is mapped');
146+
t.equal(data.contents.toString().match(/\/\/# sourceMappingURL/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(/index\.js$/.test(data.path)){
174+
t.ok(/\/\/# sourceMappingURL=data:application.*/.test(data.contents.toString()),
175+
'concatenated file is mapped');
176+
t.equal(data.contents.toString().match(/\/\/# sourceMappingURL/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

Comments
 (0)