Skip to content

Commit 59f49fd

Browse files
committed
Added unit tests for source comments
1 parent d8015f8 commit 59f49fd

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* line 4, /test/path/_cats.scss */
2+
body {
3+
background: pink; }
4+
5+
/* line 4, /test/path/_dogs.sass */
6+
footer {
7+
background: red; }
8+
9+
/* line 4, /test/path/inheritance.scss */
10+
.error, .badError {
11+
border: #f00;
12+
background: #fdd; }
13+
14+
/* line 9, /test/path/inheritance.scss */
15+
.error.intrusion, .intrusion.badError {
16+
font-size: 1.3em;
17+
font-weight: bold; }
18+
19+
/* line 14, /test/path/inheritance.scss */
20+
.badError {
21+
border-width: 3px; }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* line 4, /test/path/variables.scss */
2+
.content-navigation {
3+
border-color: #3bbfce;
4+
color: #2ca2af; }
5+
6+
/* line 10, /test/path/variables.scss */
7+
.border {
8+
padding: 8px;
9+
margin: 8px;
10+
border-color: #3bbfce; }

test/main.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,42 @@ describe('gulp-sass -- sync compile', function() {
422422
.on('end', done);
423423
});
424424
});
425+
426+
describe('gulp-sass -- source comments', function() {
427+
var testPath = '/test/path/';
428+
429+
// Replace comment path from current users filesystem to something we can test consistently
430+
var swapPathForTesting = function (contents) {
431+
return contents.replace(/(.*)(, )(.*?)(\w+\.(?:scss|sass))( \*\/)/g, '$1$2' + testPath + '$4$5');
432+
};
433+
434+
it('should properly add file path comment', function(done) {
435+
var sassFile = createVinyl('variables.scss');
436+
var stream = sass({ 'sourceComments': true });
437+
stream.on('data', function(cssFile) {
438+
var contents;
439+
should.exist(cssFile.contents);
440+
contents = swapPathForTesting(cssFile.contents.toString());
441+
contents.should.equal(
442+
fs.readFileSync(path.join(__dirname, 'expected/source-comments/variables.css'), 'utf8')
443+
);
444+
done();
445+
});
446+
stream.write(sassFile);
447+
});
448+
449+
it('should properly add file path comment with includes', function(done) {
450+
var sassFile = createVinyl('inheritance.scss');
451+
var stream = sass({ 'sourceComments': true });
452+
stream.on('data', function(cssFile) {
453+
var contents;
454+
should.exist(cssFile.contents);
455+
contents = swapPathForTesting(cssFile.contents.toString());
456+
contents.should.equal(
457+
fs.readFileSync(path.join(__dirname, 'expected/source-comments/inheritance.css'), 'utf8')
458+
);
459+
done();
460+
});
461+
stream.write(sassFile);
462+
});
463+
});

0 commit comments

Comments
 (0)